Skip to content

Commit

Permalink
WiFi: Add IPStackInterface abstraction for IP stacks
Browse files Browse the repository at this point in the history
  • Loading branch information
bulislaw committed Sep 23, 2016
1 parent 4a6728c commit ddd65b4
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
/* Interface implementation */
int EthernetInterface::connect()
{
return lwip_bringup();
return lwip_bringup(NULL);
}

int EthernetInterface::disconnect()
Expand Down
40 changes: 40 additions & 0 deletions features/net/FEATURE_IPV4/lwip-interface/LWIPIPStack.cpp
Original file line number Diff line number Diff line change
@@ -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();
}
5 changes: 3 additions & 2 deletions features/net/FEATURE_IPV4/lwip-interface/lwip_stack.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "lwip/tcp.h"
#include "lwip/ip.h"

#include "emac_api.h"

/* Static arena of sockets */
static struct lwip_socket {
Expand Down Expand Up @@ -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()) {
Expand All @@ -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 */
Expand Down
3 changes: 2 additions & 1 deletion features/net/FEATURE_IPV4/lwip-interface/lwip_stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@
#define LWIP_STACK_H

#include "nsapi.h"
#include "emac_api.h"

#ifdef __cplusplus
extern "C" {
#endif


// 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;
Expand Down
57 changes: 57 additions & 0 deletions features/net/network-socket/IPStackInterface.h
Original file line number Diff line number Diff line change
@@ -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 */

0 comments on commit ddd65b4

Please sign in to comment.