Skip to content

Commit c38e211

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 31d86d5 commit c38e211

26 files changed

+1331
-572
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
@@ -30,22 +30,16 @@ class LoWPANNDInterface : public MeshInterfaceNanostack {
3030
*
3131
* Must initialize to initialize the mesh on a phy.
3232
*/
33-
LoWPANNDInterface() : MeshInterfaceNanostack() { }
33+
LoWPANNDInterface() { }
3434

35-
/** Create an initialized MeshInterface
35+
/** Create an initialized LoWPANNDInterface
3636
*
3737
*/
3838
LoWPANNDInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
3939

40-
nsapi_error_t initialize(NanostackRfPhy *phy);
4140
virtual int connect();
4241
virtual int disconnect();
43-
virtual bool getOwnIpAddress(char *address, int8_t len);
4442
bool getRouterIpAddress(char *address, int8_t len);
45-
private:
46-
mesh_error_t init();
47-
mesh_error_t mesh_connect();
48-
mesh_error_t mesh_disconnect();
4943
};
5044

5145
#endif

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

Lines changed: 73 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,53 @@
2020

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

25-
/** Nanostack's network interface class.
26-
*
27-
* Common class that is shared between mesh interface classes
28-
*/
29-
class MeshInterfaceNanostack : public MeshInterface {
26+
class Nanostack::Interface : public OnboardNetworkStack::Interface, private mbed::NonCopyable<Nanostack::Interface> {
3027
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);
32+
virtual void attach(mbed::Callback<void(nsapi_event_t, intptr_t)> status_cb);
33+
virtual nsapi_connection_status_t get_connection_status() const;
3134

32-
/** Attach phy and initialize the mesh
33-
*
34-
* Initializes a mesh interface on the given phy. Not needed if
35-
* the phy is passed to the mesh's constructor.
36-
*
37-
* @return 0 on success, negative on failure
38-
*/
39-
nsapi_error_t initialize(NanostackPhy *phy);
35+
void get_mac_address(uint8_t *buf) const { interface_phy.get_mac_address(buf); }
4036

41-
/** Start the interface
42-
*
43-
* @return 0 on success, negative on failure
44-
*/
45-
virtual nsapi_error_t connect() = 0;
37+
/**
38+
* \brief Callback from C-layer
39+
* \param status state of the network
40+
* */
41+
void network_handler(mesh_connection_status_t status);
4642

47-
/** Stop the interface
48-
*
49-
* @return 0 on success, negative on failure
50-
*/
51-
virtual nsapi_error_t disconnect() = 0;
43+
int8_t get_interface_id() const { return interface_id; }
44+
int8_t get_driver_id() const { return _device_id; }
5245

46+
private:
47+
NanostackPhy &interface_phy;
48+
protected:
49+
Interface(NanostackPhy &phy);
50+
virtual nsapi_error_t register_phy();
51+
NanostackPhy &get_phy() const { return interface_phy; }
52+
int8_t interface_id;
53+
int8_t _device_id;
54+
Semaphore connect_semaphore;
55+
56+
Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
57+
nsapi_connection_status_t _connect_status;
58+
bool _blocking;
59+
};
60+
61+
class Nanostack::MeshInterface : public Nanostack::Interface {
62+
protected:
63+
MeshInterface(NanostackRfPhy &phy) : Interface(phy) { }
64+
NanostackRfPhy &get_phy() const { return static_cast<NanostackRfPhy &>(Interface::get_phy()); }
65+
};
66+
67+
68+
class InterfaceNanostack : public virtual NetworkInterface {
69+
public:
5370
/** Get the internally stored IP address
5471
/return IP address of the interface or null if not yet connected
5572
*/
@@ -60,18 +77,11 @@ class MeshInterfaceNanostack : public MeshInterface {
6077
*/
6178
virtual const char *get_mac_address();
6279

63-
/** Get the interface ID
64-
/return Interface identifier
65-
*/
66-
int8_t get_interface_id() const { return _network_interface_id; }
67-
68-
/**
69-
* \brief Callback from C-layer
70-
* \param status state of the network
71-
* */
72-
void mesh_network_handler(mesh_connection_status_t status);
73-
7480
/** Register callback for status reporting
81+
*
82+
* The specified status callback function will be called on status changes
83+
* on the network. The parameters on the callback are the event type and
84+
* event-type dependent reason parameter.
7585
*
7686
* @param status_cb The callback for status changes
7787
*/
@@ -90,34 +100,41 @@ class MeshInterfaceNanostack : public MeshInterface {
90100
*/
91101
virtual nsapi_error_t set_blocking(bool blocking);
92102

103+
/** Get the interface ID
104+
/return Interface identifier
105+
*/
106+
int8_t get_interface_id() const { return _interface->get_interface_id(); }
107+
93108
protected:
94-
MeshInterfaceNanostack();
95-
MeshInterfaceNanostack(NanostackPhy *phy);
96-
nsapi_error_t register_phy();
97-
virtual NetworkStack * get_stack(void);
109+
InterfaceNanostack();
110+
virtual Nanostack *get_stack(void);
111+
Nanostack::Interface *get_interface() const { return _interface; }
98112

99-
/**
100-
* \brief Read own global IP address
101-
*
102-
* \param address is where the IP address will be copied
103-
* \param len is the length of the address buffer, must be at least 40 bytes
104-
* \return true if address is read successfully, false otherwise
105-
*/
106-
virtual bool getOwnIpAddress(char *address, int8_t len) = 0;
113+
Nanostack::Interface *_interface;
107114

108-
NanostackPhy *phy;
109-
/** Network interface ID */
110-
int8_t _network_interface_id;
111-
/** Registered device ID */
112-
int8_t _device_id;
113-
uint8_t _eui64[8];
114115
char ip_addr_str[40];
115116
char mac_addr_str[24];
116-
Semaphore connect_semaphore;
117-
118-
Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
119-
nsapi_connection_status_t _connect_status;
117+
mbed::Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
120118
bool _blocking;
121119
};
122120

121+
class MeshInterfaceNanostack : public InterfaceNanostack, public MeshInterface, private mbed::NonCopyable<MeshInterfaceNanostack> {
122+
public:
123+
124+
/** Attach phy and initialize the mesh
125+
*
126+
* Initializes a mesh interface on the given phy. Not needed if
127+
* the phy is passed to the mesh's constructor.
128+
*
129+
* @return 0 on success, negative on failure
130+
*/
131+
nsapi_error_t initialize(NanostackRfPhy *phy);
132+
133+
protected:
134+
MeshInterfaceNanostack() : _phy(NULL) { }
135+
MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { }
136+
Nanostack::MeshInterface *get_interface() const { return static_cast<Nanostack::MeshInterface *>(_interface); }
137+
NanostackRfPhy *_phy;
138+
};
139+
123140
#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: 37 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,53 @@
1717
#ifndef NANOSTACKETHERNETINTERFACE_H
1818
#define NANOSTACKETHERNETINTERFACE_H
1919

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

24+
class Nanostack::EthernetInterface : public Nanostack::Interface {
25+
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+
bool blocking = true);
30+
virtual nsapi_error_t bringdown();
31+
32+
private:
33+
friend Nanostack;
34+
friend class NanostackEthernetInterface;
35+
EthernetInterface(NanostackEthernetPhy &phy) : Interface(phy) {}
36+
nsapi_error_t initialize();
37+
protected:
38+
NanostackEthernetPhy &get_phy() const { return static_cast<NanostackEthernetPhy &>(Interface::get_phy()); }
39+
};
40+
2341
/** Ethernet interface for Nanostack.
2442
*
2543
* Configure Nanostack to use Ethernet connectivity.
2644
*/
27-
class NanostackEthernetInterface : public MeshInterfaceNanostack {
45+
class NanostackEthernetInterface : public InterfaceNanostack, public EthInterface, private mbed::NonCopyable<NanostackEthernetInterface> {
2846
public:
29-
30-
NanostackEthernetInterface() : MeshInterfaceNanostack() { }
31-
NanostackEthernetInterface(NanostackEthernetPhy *phy) : MeshInterfaceNanostack(phy) { }
47+
NanostackEthernetInterface() { }
48+
//NanostackEthernetInterface(NanostackEthernetPhy *phy);
3249

3350
nsapi_error_t initialize(NanostackEthernetPhy *phy);
34-
virtual int connect();
35-
virtual int disconnect();
36-
virtual bool getOwnIpAddress(char *address, int8_t len);
37-
bool getRouterIpAddress(char *address, int8_t len);
51+
52+
/** Start the interface
53+
*
54+
* @return 0 on success, negative on failure
55+
*/
56+
virtual nsapi_error_t connect();
57+
58+
/** Stop the interface
59+
*
60+
* @return 0 on success, negative on failure
61+
*/
62+
virtual nsapi_error_t disconnect();
63+
64+
protected:
65+
Nanostack::EthernetInterface *get_interface() const { return static_cast<Nanostack::EthernetInterface *>(_interface); }
66+
3867
};
3968

4069
#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
@@ -26,18 +26,16 @@
2626
class ThreadInterface : public MeshInterfaceNanostack {
2727
public:
2828

29-
/** Create an uninitialized LoWPANNDInterface
29+
/** Create an uninitialized ThreadInterface
3030
*
3131
* Must initialize to initialize the mesh on a phy.
3232
*/
33-
ThreadInterface() : MeshInterfaceNanostack() { }
33+
ThreadInterface() : user_set_eui64(false) { }
3434

35-
/** Create an initialized MeshInterface
35+
/** Create an initialized ThreadInterface
3636
*
3737
*/
38-
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy) { }
39-
40-
nsapi_error_t initialize(NanostackRfPhy *phy);
38+
ThreadInterface(NanostackRfPhy *phy) : MeshInterfaceNanostack(phy), user_set_eui64(false) { }
4139

4240
/**
4341
* \brief Sets the eui64 for the device configuration.
@@ -59,40 +57,11 @@ class ThreadInterface : public MeshInterfaceNanostack {
5957

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

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

9867
#endif // THREADINTERFACE_H

0 commit comments

Comments
 (0)