WiFi: Add IPStackInterface abstraction for IP stacks

pull/2729/head
Bartek Szatkowski 2016-09-22 11:32:53 +01:00
parent 4a6728cb2a
commit ddd65b4089
5 changed files with 103 additions and 4 deletions

View File

@ -21,7 +21,7 @@
/* Interface implementation */
int EthernetInterface::connect()
{
return lwip_bringup();
return lwip_bringup(NULL);
}
int EthernetInterface::disconnect()

View File

@ -0,0 +1,40 @@
/* LWIPIPStackInterface
* Copyright (c) 2015 - 2016 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "IPStackInterface.h"
#include "lwip_stack.h"
/** LWIP specific implementation of IPStackInterface */
void IPStackInterface::bringup(emac_interface_t *emac)
{
lwip_bringup(emac);
}
void IPStackInterface::bringdown()
{
lwip_bringdown();
}
const char * IPStackInterface::get_mac_address()
{
return lwip_get_mac_address();
}
const char * IPStackInterface::get_ip_address()
{
return lwip_get_ip_address();
}

View File

@ -30,6 +30,7 @@
#include "lwip/tcp.h"
#include "lwip/ip.h"
#include "emac_api.h"
/* Static arena of sockets */
static struct lwip_socket {
@ -142,7 +143,7 @@ const char *lwip_get_ip_address(void)
return lwip_ip_addr[0] ? lwip_ip_addr : 0;
}
int lwip_bringup(void)
int lwip_bringup(emac_interface_t *emac)
{
// Check if we've already connected
if (!lwip_get_mac_address()) {
@ -158,7 +159,7 @@ int lwip_bringup(void)
memset(&lwip_netif, 0, sizeof lwip_netif);
#if DEVICE_EMAC
netif_add(&lwip_netif, 0, 0, 0, &emac_if, emac_lwip_if_init, tcpip_input);
netif_add(&lwip_netif, 0, 0, 0, emac, emac_lwip_if_init, tcpip_input);
#else /* DEVICE_EMAC */
netif_add(&lwip_netif, 0, 0, 0, NULL, eth_arch_enetif_init, tcpip_input);
#endif /* DEVICE_EMAC */

View File

@ -18,6 +18,7 @@
#define LWIP_STACK_H
#include "nsapi.h"
#include "emac_api.h"
#ifdef __cplusplus
extern "C" {
@ -25,7 +26,7 @@ extern "C" {
// Access to lwip through the nsapi
int lwip_bringup(void);
int lwip_bringup(emac_interface_t *emac);
void lwip_bringdown(void);
extern nsapi_stack_t lwip_stack;

View File

@ -0,0 +1,57 @@
/* IPStackInterface
* Copyright (c) 2015 - 2016 ARM Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#ifndef IP_STACK_INTERFACE_H
#define IP_STACK_INTERFACE_H
#include "emac_api.h"
/**
* IPStackInterface
*
* Abstraction class on top of IP stack, enables WiFiInterface implementation to setup IP stack
*/
class IPStackInterface
{
public:
/**
* Brings up the IP stack using provided @a emac interface
*
* @param emac Emack backend to use
*/
virtual void bringup(emac_interface_t *emac);
/**
* Brings down the IP stack
*/
virtual void bringdown();
/**
* Returns MAC address
*
* @return MAC address in "00:11:22:33:44:55" form
*/
virtual const char *get_mac_address();
/**
* Returns interfaces IP address
*
* @return IP address in "10.11.12.13" form
*/
virtual const char *get_ip_address();
};
#endif /* IP_STACK_INTERFACE_H */