Skip to content

Nanostack EMAC implementation #5944

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

Merged
merged 6 commits into from
Feb 14, 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
4 changes: 2 additions & 2 deletions features/FEATURE_LWIP/lwip-interface/LWIPStack.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
* @param[out] interface_out pointer to stack interface object controlling the EMAC
* @return NSAPI_ERROR_OK on success, or error code
*/
nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out);
virtual nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out);

/** Register a PPP interface with the IP stack
*
Expand Down Expand Up @@ -193,7 +193,7 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
* version is chosen by the stack (defaults to NSAPI_UNSPEC)
* @return 0 on success, negative error code on failure
*/
nsapi_error_t gethostbyname(const char *host,
virtual nsapi_error_t gethostbyname(const char *host,
SocketAddress *address, nsapi_version_t version = NSAPI_UNSPEC);

/** Add a domain name server to list of servers to query
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,22 +26,16 @@ class LoWPANNDInterface : public MeshInterfaceNanostack {
*
* Must initialize to initialize the mesh on a phy.
*/
LoWPANNDInterface() : MeshInterfaceNanostack() { }
LoWPANNDInterface() { }

/** Create an initialized MeshInterface
/** Create an initialized LoWPANNDInterface
*
*/
LoWPANNDInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }

nsapi_error_t initialize(NanostackRfPhy *phy);
virtual int connect();
virtual int disconnect();
virtual bool getOwnIpAddress(char *address, int8_t len);
bool getRouterIpAddress(char *address, int8_t len);
private:
mesh_error_t init();
mesh_error_t mesh_connect();
mesh_error_t mesh_disconnect();
};

#endif
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,47 @@

#include "MeshInterface.h"
#include "NanostackRfPhy.h"
#include "Nanostack.h"
#include "mesh_interface_types.h"

class MeshInterfaceNanostack : public MeshInterface {
class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed::NonCopyable<Nanostack::Interface> {
public:
virtual char *get_ip_address(char *buf, nsapi_size_t buflen);
virtual char *get_mac_address(char *buf, nsapi_size_t buflen);
virtual char *get_netmask(char *buf, nsapi_size_t buflen);
virtual char *get_gateway(char *buf, nsapi_size_t buflen);

/** Attach phy and initialize the mesh
*
* Initializes a mesh interface on the given phy. Not needed if
* the phy is passed to the mesh's constructor.
*
* @return 0 on success, negative on failure
*/
nsapi_error_t initialize(NanostackPhy *phy);
void get_mac_address(uint8_t *buf) const { interface_phy.get_mac_address(buf); }

/** Start the interface
*
* @return 0 on success, negative on failure
*/
virtual nsapi_error_t connect() = 0;
/**
* \brief Callback from C-layer
* \param state state of the network
* */
void network_handler(mesh_connection_status_t status);

/** Stop the interface
*
* @return 0 on success, negative on failure
*/
virtual nsapi_error_t disconnect() = 0;
int8_t get_interface_id() const { return interface_id; }
int8_t get_driver_id() const { return _device_id; }

private:
NanostackPhy &interface_phy;
protected:
Interface(NanostackPhy &phy);
virtual nsapi_error_t register_phy();
NanostackPhy &get_phy() const { return interface_phy; }
int8_t interface_id;
int8_t _device_id;
Semaphore connect_semaphore;
};

class Nanostack::MeshInterface : public Nanostack::Interface {
protected:
MeshInterface(NanostackRfPhy &phy) : Interface(phy) { }
NanostackRfPhy &get_phy() const { return static_cast<NanostackRfPhy &>(Interface::get_phy()); }
};


class InterfaceNanostack : public virtual NetworkInterface {
public:
/** Get the internally stored IP address
/return IP address of the interface or null if not yet connected
*/
Expand All @@ -56,36 +71,34 @@ class MeshInterfaceNanostack : public MeshInterface {
*/
virtual const char *get_mac_address();

/**
* \brief Callback from C-layer
* \param state state of the network
* */
void mesh_network_handler(mesh_connection_status_t status);

protected:
MeshInterfaceNanostack();
MeshInterfaceNanostack(NanostackPhy *phy);
nsapi_error_t register_phy();
virtual NetworkStack * get_stack(void);
InterfaceNanostack();
virtual Nanostack *get_stack(void);
Nanostack::Interface *get_interface() const { return _interface; }

/**
* \brief Read own global IP address
*
* \param address is where the IP address will be copied
* \param len is the length of the address buffer, must be at least 40 bytes
* \return true if address is read successfully, false otherwise
*/
virtual bool getOwnIpAddress(char *address, int8_t len) = 0;
Nanostack::Interface *_interface;

NanostackPhy *phy;
/** Network interface ID */
int8_t _network_interface_id;
/** Registered device ID */
int8_t _device_id;
uint8_t _eui64[8];
char ip_addr_str[40];
char mac_addr_str[24];
Semaphore connect_semaphore;
};

class MeshInterfaceNanostack : public InterfaceNanostack, public MeshInterface, private mbed::NonCopyable<MeshInterfaceNanostack> {
public:

/** Attach phy and initialize the mesh
*
* Initializes a mesh interface on the given phy. Not needed if
* the phy is passed to the mesh's constructor.
*
* @return 0 on success, negative on failure
*/
nsapi_error_t initialize(NanostackRfPhy *phy);

protected:
MeshInterfaceNanostack() : _phy(NULL) { }
MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { }
Nanostack::MeshInterface *get_interface() const { return static_cast<Nanostack::MeshInterface *>(_interface); }
NanostackRfPhy *_phy;
};

#endif /* MESHINTERFACENANOSTACK_H */
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2016 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* 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 NANOSTACKETHERNETINTERFACE_H
#define NANOSTACKETHERNETINTERFACE_H

#include "MeshInterfaceNanostack.h"
#include "NanostackEthernetPhy.h"

class NanostackEMACInterface : public Nanostack::Interface {
public:

NanostackEMACInterface(EMAC &emac);
};

#endif // NANOSTACKETHERNETINTERFACE_H
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,48 @@
#ifndef NANOSTACKETHERNETINTERFACE_H
#define NANOSTACKETHERNETINTERFACE_H

#include "EthInterface.h"
#include "MeshInterfaceNanostack.h"
#include "NanostackEthernetPhy.h"

class NanostackEthernetInterface : public MeshInterfaceNanostack {
class Nanostack::EthernetInterface : public Nanostack::Interface {
public:
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
const char *netmask, const char *gw,
nsapi_ip_stack_t stack = DEFAULT_STACK);
virtual nsapi_error_t bringdown();

NanostackEthernetInterface() : MeshInterfaceNanostack() { }
NanostackEthernetInterface(NanostackEthernetPhy *phy) : MeshInterfaceNanostack(phy) { }
private:
friend Nanostack;
friend class NanostackEthernetInterface;
EthernetInterface(NanostackEthernetPhy &phy) : Interface(phy) {}
nsapi_error_t initialize();
protected:
NanostackEthernetPhy &get_phy() const { return static_cast<NanostackEthernetPhy &>(Interface::get_phy()); }
};

class NanostackEthernetInterface : public InterfaceNanostack, public EthInterface, private mbed::NonCopyable<NanostackEthernetInterface> {
public:
NanostackEthernetInterface() { }
//NanostackEthernetInterface(NanostackEthernetPhy *phy);

nsapi_error_t initialize(NanostackEthernetPhy *phy);
virtual int connect();
virtual int disconnect();
virtual bool getOwnIpAddress(char *address, int8_t len);
bool getRouterIpAddress(char *address, int8_t len);

/** Start the interface
*
* @return 0 on success, negative on failure
*/
virtual nsapi_error_t connect();

/** Stop the interface
*
* @return 0 on success, negative on failure
*/
virtual nsapi_error_t disconnect();

protected:
Nanostack::EthernetInterface *get_interface() const { return static_cast<Nanostack::EthernetInterface *>(_interface); }

};

#endif // NANOSTACKETHERNETINTERFACE_H
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Copyright (c) 2016 ARM Limited. All rights reserved.
* SPDX-License-Identifier: Apache-2.0
* 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 NANOSTACKRFINTERFACE_H
#define NANOSTACKRFINTERFACE_H

#include "MeshInterfaceNanostack.h"
#include "NanostackRfPhy.h"

class NanostackRfInterface : public Nanostack::Interface {
public:

NanostackRfInterface(NanostackRfPhy &phy);
};

#endif // NANOSTACKRFINTERFACE_H
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,16 @@
class ThreadInterface : public MeshInterfaceNanostack {
public:

/** Create an uninitialized LoWPANNDInterface
/** Create an uninitialized ThreadInterface
*
* Must initialize to initialize the mesh on a phy.
*/
ThreadInterface() : MeshInterfaceNanostack() { }
ThreadInterface() : user_set_eui64(false) { }

/** Create an initialized MeshInterface
/** Create an initialized ThreadInterface
*
*/
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }

nsapi_error_t initialize(NanostackRfPhy *phy);
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy), user_set_eui64(false) { }

/**
* \brief Sets the eui64 for the device configuration.
Expand All @@ -55,40 +53,11 @@ class ThreadInterface : public MeshInterfaceNanostack {

virtual int connect();
virtual int disconnect();
private:
/*
* \brief Initialization of the interface.
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_PARAM when input parameters are illegal (also in case when RF device is already associated to other interface)
* \return MESH_ERROR_MEMORY in case of memory error
* \return MESH_ERROR_UNKNOWN in other error cases
*/
mesh_error_t init();
/**
* \brief Connect interface to the mesh network
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_PARAM in case of illegal parameters.
* \return MESH_ERROR_MEMORY in case of memory error.
* \return MESH_ERROR_STATE if interface is already connected to network.
* \return MESH_ERROR_UNKNOWN in case of unspecified error.
* */
mesh_error_t mesh_connect();
protected:
Nanostack::ThreadInterface *get_interface() const;

/**
* \brief Disconnect interface from the mesh network
* \return MESH_ERROR_NONE on success.
* \return MESH_ERROR_UNKNOWN in case of error.
* */
mesh_error_t mesh_disconnect();

/**
* \brief Read own global IP address
*
* \param address is where the IP address will be copied
* \param len is the length of the address buffer, must be at least 40 bytes
* \return true if address is read successfully, false otherwise
*/
virtual bool getOwnIpAddress(char *address, int8_t len);
private:
bool user_set_eui64;
};

#endif // THREADINTERFACE_H
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@
* limitations under the License.
*/

#include "include/callback_handler.h"
#include "MeshInterfaceNanostack.h"

#include "include/callback_handler.h"

static MeshInterfaceNanostack *_handler = NULL;
static Nanostack::Interface *_handler = NULL;

void __mesh_handler_c_callback(mesh_connection_status_t state)
{

if (_handler) {
_handler->mesh_network_handler(state);
_handler->network_handler(state);
}
}

void __mesh_handler_set_callback(MeshInterfaceNanostack *handler)
void __mesh_handler_set_callback(Nanostack::Interface *handler)
{
_handler = handler;
}
Loading