mirror of https://github.com/ARMmbed/mbed-os.git
Merge pull request #7751 from mikaleppanen/realtek_emac_interf
Realtek RTL8195A wifi interface to inherit EMAC interfacepull/7635/merge
commit
7531b31c01
|
@ -38,8 +38,6 @@ typedef struct _wifi_scan_hdl {
|
|||
|
||||
#define MAX_SCAN_TIMEOUT (15000)
|
||||
|
||||
static bool _inited = false;
|
||||
|
||||
static rtw_result_t scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result )
|
||||
{
|
||||
wifi_scan_hdl *scan_handler = (wifi_scan_hdl *)malloced_scan_result->user_data;
|
||||
|
@ -88,14 +86,9 @@ static rtw_result_t scan_result_handler( rtw_scan_handler_result_t* malloced_sca
|
|||
}
|
||||
|
||||
RTWInterface::RTWInterface(RTW_EMAC &get_rtw_emac, OnboardNetworkStack &get_rtw_obn_stack) :
|
||||
EMACInterface(get_rtw_emac, get_rtw_obn_stack),
|
||||
rtw_emac(get_rtw_emac),
|
||||
rtw_obn_stack(get_rtw_obn_stack),
|
||||
rtw_interface(NULL),
|
||||
_dhcp(true),
|
||||
_ip_address(),
|
||||
_netmask(),
|
||||
_gateway(),
|
||||
_mac_address()
|
||||
rtw_obn_stack(get_rtw_obn_stack)
|
||||
{
|
||||
rtw_emac.power_up();
|
||||
}
|
||||
|
@ -103,22 +96,7 @@ RTWInterface::RTWInterface(RTW_EMAC &get_rtw_emac, OnboardNetworkStack &get_rtw_
|
|||
RTWInterface::~RTWInterface()
|
||||
{
|
||||
rtw_emac.wlan_emac_link_change(false);
|
||||
rtw_interface->bringdown();
|
||||
}
|
||||
|
||||
nsapi_error_t RTWInterface::set_network(const char *ip_address, const char *netmask, const char *gateway)
|
||||
{
|
||||
_dhcp = false;
|
||||
strncpy(_ip_address, ip_address ? ip_address : "", sizeof(_ip_address));
|
||||
strncpy(_netmask, netmask ? netmask : "", sizeof(_netmask));
|
||||
strncpy(_gateway, gateway ? gateway : "", sizeof(_gateway));
|
||||
return NSAPI_ERROR_OK;
|
||||
}
|
||||
|
||||
nsapi_error_t RTWInterface::set_dhcp(bool dhcp)
|
||||
{
|
||||
_dhcp = dhcp;
|
||||
return NSAPI_ERROR_OK;
|
||||
EMACInterface::disconnect();
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -190,20 +168,10 @@ nsapi_error_t RTWInterface::connect()
|
|||
}
|
||||
|
||||
rtw_emac.wlan_emac_link_change(true);
|
||||
if (!rtw_interface) {
|
||||
nsapi_error_t err = rtw_obn_stack.add_ethernet_interface(rtw_emac, true, &rtw_interface);
|
||||
if (err != NSAPI_ERROR_OK) {
|
||||
rtw_interface = NULL;
|
||||
return err;
|
||||
}
|
||||
}
|
||||
|
||||
int rtw_if_bringup = rtw_interface->bringup(_dhcp,
|
||||
_ip_address[0] ? _ip_address : 0,
|
||||
_netmask[0] ? _netmask : 0,
|
||||
_gateway[0] ? _gateway : 0,
|
||||
DEFAULT_STACK);
|
||||
return rtw_if_bringup;
|
||||
ret = EMACInterface::connect();
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
nsapi_error_t RTWInterface::scan(WiFiAccessPoint *res, unsigned count)
|
||||
|
@ -257,7 +225,9 @@ nsapi_error_t RTWInterface::disconnect()
|
|||
char essid[33];
|
||||
|
||||
rtw_emac.wlan_emac_link_change(false);
|
||||
rtw_interface->bringdown();
|
||||
|
||||
EMACInterface::disconnect();
|
||||
|
||||
if (wifi_is_connected_to_ap() != RTW_SUCCESS) {
|
||||
return NSAPI_ERROR_NO_CONNECTION;
|
||||
}
|
||||
|
@ -277,38 +247,6 @@ int RTWInterface::is_connected()
|
|||
return !wifi_is_connected_to_ap();
|
||||
}
|
||||
|
||||
const char *RTWInterface::get_mac_address()
|
||||
{
|
||||
if (rtw_interface->get_mac_address(_mac_address, sizeof _mac_address)) {
|
||||
return _mac_address;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *RTWInterface::get_ip_address()
|
||||
{
|
||||
if (rtw_interface->get_ip_address(_ip_address, sizeof _ip_address)) {
|
||||
return _ip_address;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *RTWInterface::get_netmask()
|
||||
{
|
||||
if (rtw_interface->get_netmask(_netmask, sizeof _netmask)) {
|
||||
return _netmask;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
const char *RTWInterface::get_gateway()
|
||||
{
|
||||
if (rtw_interface->get_gateway(_gateway, sizeof _gateway)) {
|
||||
return _gateway;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
NetworkStack *RTWInterface::get_stack()
|
||||
{
|
||||
return &rtw_obn_stack;
|
||||
|
|
|
@ -24,6 +24,7 @@
|
|||
#include "netif.h"
|
||||
#include "rtw_emac.h"
|
||||
#include "OnboardNetworkStack.h"
|
||||
#include "EMACInterface.h"
|
||||
#include "LWIPStack.h"
|
||||
|
||||
// Forward declaration
|
||||
|
@ -32,7 +33,7 @@ class NetworkStack;
|
|||
/** Realtek Wlan (RTW) interface class
|
||||
* Implementation of the NetworkStack for Ameba
|
||||
*/
|
||||
class RTWInterface: public WiFiInterface
|
||||
class RTWInterface: public WiFiInterface, public EMACInterface
|
||||
{
|
||||
public:
|
||||
/** RTWWlanInterface lifetime
|
||||
|
@ -43,28 +44,6 @@ public:
|
|||
|
||||
~RTWInterface();
|
||||
|
||||
/** Set a static IP address
|
||||
*
|
||||
* Configures this network interface to use a static IP address.
|
||||
* Implicitly disables DHCP, which can be enabled in set_dhcp.
|
||||
* Requires that the network is disconnected.
|
||||
*
|
||||
* @param address Null-terminated representation of the local IP address
|
||||
* @param netmask Null-terminated representation of the local network mask
|
||||
* @param gateway Null-terminated representation of the local gateway
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual nsapi_error_t set_network(const char *ip_address, const char *netmask, const char *gateway);
|
||||
|
||||
/** Enable or disable DHCP on the network
|
||||
*
|
||||
* Requires that the network is disconnected
|
||||
*
|
||||
* @param dhcp False to disable dhcp (defaults to enabled)
|
||||
* @return 0 on success, negative error code on failure
|
||||
*/
|
||||
virtual nsapi_error_t set_dhcp(bool dhcp);
|
||||
|
||||
/** Set the WiFi network credentials
|
||||
*
|
||||
* @param ssid Name of the network to connect to
|
||||
|
@ -112,42 +91,10 @@ public:
|
|||
* @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
|
||||
* see @a nsapi_error
|
||||
*/
|
||||
virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, unsigned count);
|
||||
virtual nsapi_size_or_error_t scan(WiFiAccessPoint *res, unsigned count);
|
||||
|
||||
virtual nsapi_error_t set_channel(uint8_t channel);
|
||||
virtual int8_t get_rssi();
|
||||
|
||||
/** Get the local MAC address
|
||||
*
|
||||
* Provided MAC address is intended for info or debug purposes and
|
||||
* may not be provided if the underlying network interface does not
|
||||
* provide a MAC address
|
||||
*
|
||||
* @return Null-terminated representation of the local MAC address
|
||||
* or null if no MAC address is available
|
||||
*/
|
||||
virtual const char *get_mac_address();
|
||||
|
||||
/** Get the local IP address
|
||||
*
|
||||
* @return Null-terminated representation of the local IP address
|
||||
* or null if no IP address has been recieved
|
||||
*/
|
||||
virtual const char *get_ip_address();
|
||||
|
||||
/** Get the local network mask
|
||||
*
|
||||
* @return Null-terminated representation of the local network mask
|
||||
* or null if no network mask has been recieved
|
||||
*/
|
||||
virtual const char *get_netmask();
|
||||
|
||||
/** Get the local gateways
|
||||
*
|
||||
* @return Null-terminated representation of the local gateway
|
||||
* or null if no network mask has been recieved
|
||||
*/
|
||||
virtual const char *get_gateway();
|
||||
virtual nsapi_error_t set_channel(uint8_t channel);
|
||||
virtual int8_t get_rssi();
|
||||
|
||||
RTW_EMAC &get_emac() const { return rtw_emac; }
|
||||
|
||||
|
@ -161,15 +108,9 @@ protected:
|
|||
virtual NetworkStack *get_stack();
|
||||
RTW_EMAC &rtw_emac;
|
||||
OnboardNetworkStack &rtw_obn_stack;
|
||||
OnboardNetworkStack::Interface *rtw_interface;
|
||||
bool _dhcp;
|
||||
char _ssid[256];
|
||||
char _pass[256];
|
||||
nsapi_security_t _security;
|
||||
uint8_t _channel;
|
||||
char _ip_address[IPADDR_STRLEN_MAX];
|
||||
char _netmask[NSAPI_IPv4_SIZE];
|
||||
char _gateway[NSAPI_IPv4_SIZE];
|
||||
char _mac_address[NSAPI_MAC_SIZE];
|
||||
};
|
||||
#endif
|
||||
|
|
Loading…
Reference in New Issue