Skip to content

Commit 8848550

Browse files
authored
Merge pull request #5944 from kjbracey-arm/emac_ns
Nanostack EMAC implementation
2 parents ed4bf78 + e8f38ce commit 8848550

33 files changed

+1349
-556
lines changed

features/FEATURE_LWIP/lwip-interface/LWIPStack.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ class LWIP : public OnboardNetworkStack, private mbed::NonCopyable<LWIP> {
159159
* @param[out] interface_out pointer to stack interface object controlling the EMAC
160160
* @return NSAPI_ERROR_OK on success, or error code
161161
*/
162-
nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out);
162+
virtual nsapi_error_t add_ethernet_interface(EMAC &emac, bool default_if, OnboardNetworkStack::Interface **interface_out);
163163

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

199199
/** Add a domain name server to list of servers to query

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: 57 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -20,32 +20,47 @@
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+
void get_mac_address(uint8_t *buf) const { interface_phy.get_mac_address(buf); }
3634

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

43-
/** Stop the interface
44-
*
45-
* @return 0 on success, negative on failure
46-
*/
47-
virtual nsapi_error_t disconnect() = 0;
41+
int8_t get_interface_id() const { return interface_id; }
42+
int8_t get_driver_id() const { return _device_id; }
43+
44+
private:
45+
NanostackPhy &interface_phy;
46+
protected:
47+
Interface(NanostackPhy &phy);
48+
virtual nsapi_error_t register_phy();
49+
NanostackPhy &get_phy() const { return interface_phy; }
50+
int8_t interface_id;
51+
int8_t _device_id;
52+
Semaphore connect_semaphore;
53+
};
54+
55+
class Nanostack::MeshInterface : public Nanostack::Interface {
56+
protected:
57+
MeshInterface(NanostackRfPhy &phy) : Interface(phy) { }
58+
NanostackRfPhy &get_phy() const { return static_cast<NanostackRfPhy &>(Interface::get_phy()); }
59+
};
4860

61+
62+
class InterfaceNanostack : public virtual NetworkInterface {
63+
public:
4964
/** Get the internally stored IP address
5065
/return IP address of the interface or null if not yet connected
5166
*/
@@ -56,36 +71,34 @@ class MeshInterfaceNanostack : public MeshInterface {
5671
*/
5772
virtual const char *get_mac_address();
5873

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-
6574
protected:
66-
MeshInterfaceNanostack();
67-
MeshInterfaceNanostack(NanostackPhy *phy);
68-
nsapi_error_t register_phy();
69-
virtual NetworkStack * get_stack(void);
75+
InterfaceNanostack();
76+
virtual Nanostack *get_stack(void);
77+
Nanostack::Interface *get_interface() const { return _interface; }
7078

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;
79+
Nanostack::Interface *_interface;
7980

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];
8681
char ip_addr_str[40];
8782
char mac_addr_str[24];
88-
Semaphore connect_semaphore;
83+
};
84+
85+
class MeshInterfaceNanostack : public InterfaceNanostack, public MeshInterface, private mbed::NonCopyable<MeshInterfaceNanostack> {
86+
public:
87+
88+
/** Attach phy and initialize the mesh
89+
*
90+
* Initializes a mesh interface on the given phy. Not needed if
91+
* the phy is passed to the mesh's constructor.
92+
*
93+
* @return 0 on success, negative on failure
94+
*/
95+
nsapi_error_t initialize(NanostackRfPhy *phy);
96+
97+
protected:
98+
MeshInterfaceNanostack() : _phy(NULL) { }
99+
MeshInterfaceNanostack(NanostackRfPhy *phy) : _phy(phy) { }
100+
Nanostack::MeshInterface *get_interface() const { return static_cast<Nanostack::MeshInterface *>(_interface); }
101+
NanostackRfPhy *_phy;
89102
};
90103

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