Skip to content

Commit 4385361

Browse files
author
Mika Leppänen
committed
Changed Realtek RTL8195A wifi interface to inherit EMAC interface
This allows connection status callback build into EMAC interface class to work with Realtek RTL8195A wifi.
1 parent 54f40a0 commit 4385361

File tree

2 files changed

+14
-135
lines changed

2 files changed

+14
-135
lines changed

targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.cpp

Lines changed: 9 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,6 @@ typedef struct _wifi_scan_hdl {
3838

3939
#define MAX_SCAN_TIMEOUT (15000)
4040

41-
static bool _inited = false;
42-
4341
static rtw_result_t scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result )
4442
{
4543
wifi_scan_hdl *scan_handler = (wifi_scan_hdl *)malloced_scan_result->user_data;
@@ -88,37 +86,17 @@ static rtw_result_t scan_result_handler( rtw_scan_handler_result_t* malloced_sca
8886
}
8987

9088
RTWInterface::RTWInterface(RTW_EMAC &get_rtw_emac, OnboardNetworkStack &get_rtw_obn_stack) :
89+
EMACInterface(get_rtw_emac, get_rtw_obn_stack),
9190
rtw_emac(get_rtw_emac),
92-
rtw_obn_stack(get_rtw_obn_stack),
93-
rtw_interface(NULL),
94-
_dhcp(true),
95-
_ip_address(),
96-
_netmask(),
97-
_gateway(),
98-
_mac_address()
91+
rtw_obn_stack(get_rtw_obn_stack)
9992
{
10093
rtw_emac.power_up();
10194
}
10295

10396
RTWInterface::~RTWInterface()
10497
{
10598
rtw_emac.wlan_emac_link_change(false);
106-
rtw_interface->bringdown();
107-
}
108-
109-
nsapi_error_t RTWInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
110-
{
111-
_dhcp = false;
112-
strncpy(_ip_address, ip_address ? ip_address : "", sizeof(_ip_address));
113-
strncpy(_netmask, netmask ? netmask : "", sizeof(_netmask));
114-
strncpy(_gateway, gateway ? gateway : "", sizeof(_gateway));
115-
return NSAPI_ERROR_OK;
116-
}
117-
118-
nsapi_error_t RTWInterface::set_dhcp(bool dhcp)
119-
{
120-
_dhcp = dhcp;
121-
return NSAPI_ERROR_OK;
99+
EMACInterface::disconnect();
122100
}
123101

124102
/*
@@ -190,20 +168,10 @@ nsapi_error_t RTWInterface::connect()
190168
}
191169

192170
rtw_emac.wlan_emac_link_change(true);
193-
if (!rtw_interface) {
194-
nsapi_error_t err = rtw_obn_stack.add_ethernet_interface(rtw_emac, true, &rtw_interface);
195-
if (err != NSAPI_ERROR_OK) {
196-
rtw_interface = NULL;
197-
return err;
198-
}
199-
}
200171

201-
int rtw_if_bringup = rtw_interface->bringup(_dhcp,
202-
_ip_address[0] ? _ip_address : 0,
203-
_netmask[0] ? _netmask : 0,
204-
_gateway[0] ? _gateway : 0,
205-
DEFAULT_STACK);
206-
return rtw_if_bringup;
172+
ret = EMACInterface::connect();
173+
174+
return ret;
207175
}
208176

209177
nsapi_error_t RTWInterface::scan(WiFiAccessPoint *res, unsigned count)
@@ -257,7 +225,9 @@ nsapi_error_t RTWInterface::disconnect()
257225
char essid[33];
258226

259227
rtw_emac.wlan_emac_link_change(false);
260-
rtw_interface->bringdown();
228+
229+
EMACInterface::disconnect();
230+
261231
if (wifi_is_connected_to_ap() != RTW_SUCCESS) {
262232
return NSAPI_ERROR_NO_CONNECTION;
263233
}
@@ -277,38 +247,6 @@ int RTWInterface::is_connected()
277247
return !wifi_is_connected_to_ap();
278248
}
279249

280-
const char *RTWInterface::get_mac_address()
281-
{
282-
if (rtw_interface->get_mac_address(_mac_address, sizeof _mac_address)) {
283-
return _mac_address;
284-
}
285-
return 0;
286-
}
287-
288-
const char *RTWInterface::get_ip_address()
289-
{
290-
if (rtw_interface->get_ip_address(_ip_address, sizeof _ip_address)) {
291-
return _ip_address;
292-
}
293-
return 0;
294-
}
295-
296-
const char *RTWInterface::get_netmask()
297-
{
298-
if (rtw_interface->get_netmask(_netmask, sizeof _netmask)) {
299-
return _netmask;
300-
}
301-
return 0;
302-
}
303-
304-
const char *RTWInterface::get_gateway()
305-
{
306-
if (rtw_interface->get_gateway(_gateway, sizeof _gateway)) {
307-
return _gateway;
308-
}
309-
return 0;
310-
}
311-
312250
NetworkStack *RTWInterface::get_stack()
313251
{
314252
return &rtw_obn_stack;

targets/TARGET_Realtek/TARGET_AMEBA/RTWInterface.h

Lines changed: 5 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "netif.h"
2525
#include "rtw_emac.h"
2626
#include "OnboardNetworkStack.h"
27+
#include "EMACInterface.h"
2728
#include "LWIPStack.h"
2829

2930
// Forward declaration
@@ -32,7 +33,7 @@ class NetworkStack;
3233
/** Realtek Wlan (RTW) interface class
3334
* Implementation of the NetworkStack for Ameba
3435
*/
35-
class RTWInterface: public WiFiInterface
36+
class RTWInterface: public WiFiInterface, public EMACInterface
3637
{
3738
public:
3839
/** RTWWlanInterface lifetime
@@ -43,28 +44,6 @@ class RTWInterface: public WiFiInterface
4344

4445
~RTWInterface();
4546

46-
/** Set a static IP address
47-
*
48-
* Configures this network interface to use a static IP address.
49-
* Implicitly disables DHCP, which can be enabled in set_dhcp.
50-
* Requires that the network is disconnected.
51-
*
52-
* @param address Null-terminated representation of the local IP address
53-
* @param netmask Null-terminated representation of the local network mask
54-
* @param gateway Null-terminated representation of the local gateway
55-
* @return 0 on success, negative error code on failure
56-
*/
57-
virtual nsapi_error_t set_network(const char *ip_address, const char *netmask, const char *gateway);
58-
59-
/** Enable or disable DHCP on the network
60-
*
61-
* Requires that the network is disconnected
62-
*
63-
* @param dhcp False to disable dhcp (defaults to enabled)
64-
* @return 0 on success, negative error code on failure
65-
*/
66-
virtual nsapi_error_t set_dhcp(bool dhcp);
67-
6847
/** Set the WiFi network credentials
6948
*
7049
* @param ssid Name of the network to connect to
@@ -112,42 +91,10 @@ class RTWInterface: public WiFiInterface
11291
* @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
11392
* see @a nsapi_error
11493
*/
115-
virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, unsigned count);
116-
117-
virtual nsapi_error_t set_channel(uint8_t channel);
118-
virtual int8_t get_rssi();
119-
120-
/** Get the local MAC address
121-
*
122-
* Provided MAC address is intended for info or debug purposes and
123-
* may not be provided if the underlying network interface does not
124-
* provide a MAC address
125-
*
126-
* @return Null-terminated representation of the local MAC address
127-
* or null if no MAC address is available
128-
*/
129-
virtual const char *get_mac_address();
130-
131-
/** Get the local IP address
132-
*
133-
* @return Null-terminated representation of the local IP address
134-
* or null if no IP address has been recieved
135-
*/
136-
virtual const char *get_ip_address();
94+
virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, unsigned count);
13795

138-
/** Get the local network mask
139-
*
140-
* @return Null-terminated representation of the local network mask
141-
* or null if no network mask has been recieved
142-
*/
143-
virtual const char *get_netmask();
144-
145-
/** Get the local gateways
146-
*
147-
* @return Null-terminated representation of the local gateway
148-
* or null if no network mask has been recieved
149-
*/
150-
virtual const char *get_gateway();
96+
virtual nsapi_error_t set_channel(uint8_t channel);
97+
virtual int8_t get_rssi();
15198

15299
RTW_EMAC &get_emac() const { return rtw_emac; }
153100

@@ -161,15 +108,9 @@ class RTWInterface: public WiFiInterface
161108
virtual NetworkStack *get_stack();
162109
RTW_EMAC &rtw_emac;
163110
OnboardNetworkStack &rtw_obn_stack;
164-
OnboardNetworkStack::Interface *rtw_interface;
165-
bool _dhcp;
166111
char _ssid[256];
167112
char _pass[256];
168113
nsapi_security_t _security;
169114
uint8_t _channel;
170-
char _ip_address[IPADDR_STRLEN_MAX];
171-
char _netmask[NSAPI_IPv4_SIZE];
172-
char _gateway[NSAPI_IPv4_SIZE];
173-
char _mac_address[NSAPI_MAC_SIZE];
174115
};
175116
#endif

0 commit comments

Comments
 (0)