Skip to content

Commit d17ca69

Browse files
committed
Nanostack EMAC implementation
Make Nanostack an OnboardNetworkInterface, implementing add_ethernet_interface so it can use EMAC drivers. Can now be used via EthernetInterface, and be the system's default network stack. Legacy support for NanostackEthernetInterface retained. Some restructuring of mesh interface code to fit into the OnboardNetworkStack:::Interface system.
1 parent df138ad commit d17ca69

26 files changed

+1233
-537
lines changed

features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/mbed-mesh-api/LoWPANNDInterface.h

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,22 +26,16 @@ class LoWPANNDInterface : public MeshInterfaceNanostack {
2626
*
2727
* Must initialize to initialize the mesh on a phy.
2828
*/
29-
LoWPANNDInterface() : MeshInterfaceNanostack() { }
29+
LoWPANNDInterface() { }
3030

31-
/** Create an initialized MeshInterface
31+
/** Create an initialized LoWPANNDInterface
3232
*
3333
*/
3434
LoWPANNDInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
3535

36-
nsapi_error_t initialize(NanostackRfPhy *phy);
3736
virtual int connect();
3837
virtual int disconnect();
39-
virtual bool getOwnIpAddress(char *address, int8_t len);
4038
bool getRouterIpAddress(char *address, int8_t len);
41-
private:
42-
mesh_error_t init();
43-
mesh_error_t mesh_connect();
44-
mesh_error_t mesh_disconnect();
4539
};
4640

4741
#endif

features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/mbed-mesh-api/MeshInterfaceNanostack.h

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,42 @@
2020

2121
#include "MeshInterface.h"
2222
#include "NanostackRfPhy.h"
23+
#include "Nanostack.h"
2324
#include "mesh_interface_types.h"
2425

25-
class MeshInterfaceNanostack : public MeshInterface {
26+
class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed::NonCopyable<Nanostack::Interface> {
2627
public:
28+
virtual char *get_ip_address(char *buf, nsapi_size_t buflen);
29+
virtual char *get_mac_address(char *buf, nsapi_size_t buflen);
30+
virtual char *get_netmask(char *buf, nsapi_size_t buflen);
31+
virtual char *get_gateway(char *buf, nsapi_size_t buflen);
2732

28-
/** Attach phy and initialize the mesh
29-
*
30-
* Initializes a mesh interface on the given phy. Not needed if
31-
* the phy is passed to the mesh's constructor.
32-
*
33-
* @return 0 on success, negative on failure
34-
*/
35-
nsapi_error_t initialize(NanostackPhy *phy);
33+
/**
34+
* \brief Callback from C-layer
35+
* \param state state of the network
36+
* */
37+
void network_handler(mesh_connection_status_t status);
3638

37-
/** Start the interface
38-
*
39-
* @return 0 on success, negative on failure
40-
*/
41-
virtual nsapi_error_t connect() = 0;
39+
private:
40+
NanostackPhy &interface_phy;
41+
protected:
42+
Interface(NanostackPhy &phy);
43+
virtual nsapi_error_t register_phy();
44+
NanostackPhy &get_phy() const { return interface_phy; }
45+
int8_t interface_id;
46+
int8_t _device_id;
47+
Semaphore connect_semaphore;
48+
};
49+
50+
class Nanostack::MeshInterface : public Nanostack::Interface {
51+
protected:
52+
MeshInterface(NanostackRfPhy &phy) : Interface(phy) { }
53+
NanostackRfPhy &get_phy() const { return static_cast<NanostackRfPhy &>(Interface::get_phy()); }
54+
};
4255

43-
/** Stop the interface
44-
*
45-
* @return 0 on success, negative on failure
46-
*/
47-
virtual nsapi_error_t disconnect() = 0;
4856

57+
class InterfaceNanostack : public virtual NetworkInterface {
58+
public:
4959
/** Get the internally stored IP address
5060
/return IP address of the interface or null if not yet connected
5161
*/
@@ -56,36 +66,34 @@ class MeshInterfaceNanostack : public MeshInterface {
5666
*/
5767
virtual const char *get_mac_address();
5868

59-
/**
60-
* \brief Callback from C-layer
61-
* \param state state of the network
62-
* */
63-
void mesh_network_handler(mesh_connection_status_t status);
64-
6569
protected:
66-
MeshInterfaceNanostack();
67-
MeshInterfaceNanostack(NanostackPhy *phy);
68-
nsapi_error_t register_phy();
69-
virtual NetworkStack * get_stack(void);
70+
InterfaceNanostack();
71+
virtual Nanostack *get_stack(void);
72+
Nanostack::Interface *get_interface() const { return _interface; }
7073

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

80-
NanostackPhy *phy;
81-
/** Network interface ID */
82-
int8_t _network_interface_id;
83-
/** Registered device ID */
84-
int8_t _device_id;
85-
uint8_t _eui64[8];
8676
char ip_addr_str[40];
8777
char mac_addr_str[24];
88-
Semaphore connect_semaphore;
78+
};
79+
80+
class MeshInterfaceNanostack : public InterfaceNanostack, public MeshInterface, private mbed::NonCopyable<MeshInterfaceNanostack> {
81+
public:
82+
83+
/** Attach phy and initialize the mesh
84+
*
85+
* Initializes a mesh interface on the given phy. Not needed if
86+
* the phy is passed to the mesh's constructor.
87+
*
88+
* @return 0 on success, negative on failure
89+
*/
90+
nsapi_error_t initialize(NanostackRfPhy *phy);
91+
92+
protected:
93+
MeshInterfaceNanostack() : _phy(NULL) { }
94+
MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { }
95+
Nanostack::MeshInterface *get_interface() const { return static_cast<Nanostack::MeshInterface *>(_interface); }
96+
NanostackRfPhy *_phy;
8997
};
9098

9199
#endif /* MESHINTERFACENANOSTACK_H */
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2016 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef NANOSTACKETHERNETINTERFACE_H
18+
#define NANOSTACKETHERNETINTERFACE_H
19+
20+
#include "MeshInterfaceNanostack.h"
21+
#include "NanostackEthernetPhy.h"
22+
23+
class NanostackEMACInterface : public Nanostack::Interface {
24+
public:
25+
26+
NanostackEMACInterface(EMAC &emac);
27+
};
28+
29+
#endif // NANOSTACKETHERNETINTERFACE_H

features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/mbed-mesh-api/NanostackEthernetInterface.h

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,48 @@
1717
#ifndef NANOSTACKETHERNETINTERFACE_H
1818
#define NANOSTACKETHERNETINTERFACE_H
1919

20+
#include "EthInterface.h"
2021
#include "MeshInterfaceNanostack.h"
2122
#include "NanostackEthernetPhy.h"
2223

23-
class NanostackEthernetInterface : public MeshInterfaceNanostack {
24+
class Nanostack::EthernetInterface : public Nanostack::Interface {
2425
public:
26+
virtual nsapi_error_t bringup(bool dhcp, const char *ip,
27+
const char *netmask, const char *gw,
28+
nsapi_ip_stack_t stack = DEFAULT_STACK);
29+
virtual nsapi_error_t bringdown();
2530

26-
NanostackEthernetInterface() : MeshInterfaceNanostack() { }
27-
NanostackEthernetInterface(NanostackEthernetPhy *phy) : MeshInterfaceNanostack(phy) { }
31+
private:
32+
friend Nanostack;
33+
friend class NanostackEthernetInterface;
34+
EthernetInterface(NanostackEthernetPhy &phy) : Interface(phy) {}
35+
nsapi_error_t initialize();
36+
protected:
37+
NanostackEthernetPhy &get_phy() const { return static_cast<NanostackEthernetPhy &>(Interface::get_phy()); }
38+
};
39+
40+
class NanostackEthernetInterface : public InterfaceNanostack, public EthInterface, private mbed::NonCopyable<NanostackEthernetInterface> {
41+
public:
42+
NanostackEthernetInterface() { }
43+
//NanostackEthernetInterface(NanostackEthernetPhy *phy);
2844

2945
nsapi_error_t initialize(NanostackEthernetPhy *phy);
30-
virtual int connect();
31-
virtual int disconnect();
32-
virtual bool getOwnIpAddress(char *address, int8_t len);
33-
bool getRouterIpAddress(char *address, int8_t len);
46+
47+
/** Start the interface
48+
*
49+
* @return 0 on success, negative on failure
50+
*/
51+
virtual nsapi_error_t connect();
52+
53+
/** Stop the interface
54+
*
55+
* @return 0 on success, negative on failure
56+
*/
57+
virtual nsapi_error_t disconnect();
58+
59+
protected:
60+
Nanostack::EthernetInterface *get_interface() const { return static_cast<Nanostack::EthernetInterface *>(_interface); }
61+
3462
};
3563

3664
#endif // NANOSTACKETHERNETINTERFACE_H
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/*
2+
* Copyright (c) 2016 ARM Limited. All rights reserved.
3+
* SPDX-License-Identifier: Apache-2.0
4+
* Licensed under the Apache License, Version 2.0 (the License); you may
5+
* not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an AS IS BASIS, WITHOUT
12+
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
#ifndef NANOSTACKRFINTERFACE_H
18+
#define NANOSTACKRFINTERFACE_H
19+
20+
#include "MeshInterfaceNanostack.h"
21+
#include "NanostackRfPhy.h"
22+
23+
class NanostackRfInterface : public Nanostack::Interface {
24+
public:
25+
26+
NanostackRfInterface(NanostackRfPhy &phy);
27+
};
28+
29+
#endif // NANOSTACKRFINTERFACE_H

features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/mbed-mesh-api/ThreadInterface.h

Lines changed: 8 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,16 @@
2222
class ThreadInterface : public MeshInterfaceNanostack {
2323
public:
2424

25-
/** Create an uninitialized LoWPANNDInterface
25+
/** Create an uninitialized ThreadInterface
2626
*
2727
* Must initialize to initialize the mesh on a phy.
2828
*/
29-
ThreadInterface() : MeshInterfaceNanostack() { }
29+
ThreadInterface() : user_set_eui64(false) { }
3030

31-
/** Create an initialized MeshInterface
31+
/** Create an initialized ThreadInterface
3232
*
3333
*/
34-
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
35-
36-
nsapi_error_t initialize(NanostackRfPhy *phy);
34+
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy), user_set_eui64(false) { }
3735

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

5654
virtual int connect();
5755
virtual int disconnect();
58-
private:
59-
/*
60-
* \brief Initialization of the interface.
61-
* \return MESH_ERROR_NONE on success.
62-
* \return MESH_ERROR_PARAM when input parameters are illegal (also in case when RF device is already associated to other interface)
63-
* \return MESH_ERROR_MEMORY in case of memory error
64-
* \return MESH_ERROR_UNKNOWN in other error cases
65-
*/
66-
mesh_error_t init();
67-
/**
68-
* \brief Connect interface to the mesh network
69-
* \return MESH_ERROR_NONE on success.
70-
* \return MESH_ERROR_PARAM in case of illegal parameters.
71-
* \return MESH_ERROR_MEMORY in case of memory error.
72-
* \return MESH_ERROR_STATE if interface is already connected to network.
73-
* \return MESH_ERROR_UNKNOWN in case of unspecified error.
74-
* */
75-
mesh_error_t mesh_connect();
56+
protected:
57+
Nanostack::ThreadInterface *get_interface() const;
7658

77-
/**
78-
* \brief Disconnect interface from the mesh network
79-
* \return MESH_ERROR_NONE on success.
80-
* \return MESH_ERROR_UNKNOWN in case of error.
81-
* */
82-
mesh_error_t mesh_disconnect();
83-
84-
/**
85-
* \brief Read own global IP address
86-
*
87-
* \param address is where the IP address will be copied
88-
* \param len is the length of the address buffer, must be at least 40 bytes
89-
* \return true if address is read successfully, false otherwise
90-
*/
91-
virtual bool getOwnIpAddress(char *address, int8_t len);
59+
private:
60+
bool user_set_eui64;
9261
};
9362

9463
#endif // THREADINTERFACE_H

features/nanostack/FEATURE_NANOSTACK/mbed-mesh-api/source/CallbackHandler.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,21 @@
1414
* limitations under the License.
1515
*/
1616

17-
#include "include/callback_handler.h"
17+
#include "MeshInterfaceNanostack.h"
1818

19+
#include "include/callback_handler.h"
1920

20-
static MeshInterfaceNanostack *_handler = NULL;
21+
static Nanostack::Interface *_handler = NULL;
2122

2223
void __mesh_handler_c_callback(mesh_connection_status_t state)
2324
{
2425

2526
if (_handler) {
26-
_handler->mesh_network_handler(state);
27+
_handler->network_handler(state);
2728
}
2829
}
2930

30-
void __mesh_handler_set_callback(MeshInterfaceNanostack *handler)
31+
void __mesh_handler_set_callback(Nanostack::Interface *handler)
3132
{
3233
_handler = handler;
3334
}

0 commit comments

Comments
 (0)