Skip to content

Commit 81ce5b6

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 b2ca976 commit 81ce5b6

26 files changed

+1309
-567
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: 72 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,54 @@
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;
34+
virtual void set_blocking(bool blocking);
3135

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);
36+
void get_mac_address(uint8_t *buf) const { interface_phy.get_mac_address(buf); }
4037

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

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

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

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-
7481
/** Register callback for status reporting
82+
*
83+
* The specified status callback function will be called on status changes
84+
* on the network. The parameters on the callback are the event type and
85+
* event-type dependent reason parameter.
7586
*
7687
* @param status_cb The callback for status changes
7788
*/
@@ -90,34 +101,39 @@ class MeshInterfaceNanostack : public MeshInterface {
90101
*/
91102
virtual nsapi_error_t set_blocking(bool blocking);
92103

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

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;
114+
Nanostack::Interface *_interface;
107115

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];
114116
char ip_addr_str[40];
115117
char mac_addr_str[24];
116-
Semaphore connect_semaphore;
118+
};
117119

118-
Callback<void(nsapi_event_t, intptr_t)> _connection_status_cb;
119-
nsapi_connection_status_t _connect_status;
120-
bool _blocking;
120+
class MeshInterfaceNanostack : public InterfaceNanostack, public MeshInterface, private mbed::NonCopyable<MeshInterfaceNanostack> {
121+
public:
122+
123+
/** Attach phy and initialize the mesh
124+
*
125+
* Initializes a mesh interface on the given phy. Not needed if
126+
* the phy is passed to the mesh's constructor.
127+
*
128+
* @return 0 on success, negative on failure
129+
*/
130+
nsapi_error_t initialize(NanostackRfPhy *phy);
131+
132+
protected:
133+
MeshInterfaceNanostack() : _phy(NULL) { }
134+
MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { }
135+
Nanostack::MeshInterface *get_interface() const { return static_cast<Nanostack::MeshInterface *>(_interface); }
136+
NanostackRfPhy *_phy;
121137
};
122138

123139
#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: 36 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,24 +17,52 @@
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+
virtual nsapi_error_t bringdown();
30+
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+
2340
/** Ethernet interface for Nanostack.
2441
*
2542
* Configure Nanostack to use Ethernet connectivity.
2643
*/
27-
class NanostackEthernetInterface : public MeshInterfaceNanostack {
44+
class NanostackEthernetInterface : public InterfaceNanostack, public EthInterface, private mbed::NonCopyable<NanostackEthernetInterface> {
2845
public:
29-
30-
NanostackEthernetInterface() : MeshInterfaceNanostack() { }
31-
NanostackEthernetInterface(NanostackEthernetPhy *phy) : MeshInterfaceNanostack(phy) { }
46+
NanostackEthernetInterface() { }
47+
//NanostackEthernetInterface(NanostackEthernetPhy *phy);
3248

3349
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);
50+
51+
/** Start the interface
52+
*
53+
* @return 0 on success, negative on failure
54+
*/
55+
virtual nsapi_error_t connect();
56+
57+
/** Stop the interface
58+
*
59+
* @return 0 on success, negative on failure
60+
*/
61+
virtual nsapi_error_t disconnect();
62+
63+
protected:
64+
Nanostack::EthernetInterface *get_interface() const { return static_cast<Nanostack::EthernetInterface *>(_interface); }
65+
3866
};
3967

4068
#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)