Merge pull request #7751 from mikaleppanen/realtek_emac_interf

Realtek RTL8195A wifi interface to inherit EMAC interface
pull/7635/merge
Cruz Monrreal 2018-08-24 19:30:39 -05:00 committed by GitHub
commit 7531b31c01
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 135 deletions

View File

@ -38,8 +38,6 @@ typedef struct _wifi_scan_hdl {
#define MAX_SCAN_TIMEOUT (15000) #define MAX_SCAN_TIMEOUT (15000)
static bool _inited = false;
static rtw_result_t scan_result_handler( rtw_scan_handler_result_t* malloced_scan_result ) 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; 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) : 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_emac(get_rtw_emac),
rtw_obn_stack(get_rtw_obn_stack), rtw_obn_stack(get_rtw_obn_stack)
rtw_interface(NULL),
_dhcp(true),
_ip_address(),
_netmask(),
_gateway(),
_mac_address()
{ {
rtw_emac.power_up(); rtw_emac.power_up();
} }
@ -103,22 +96,7 @@ RTWInterface::RTWInterface(RTW_EMAC &get_rtw_emac, OnboardNetworkStack &get_rtw_
RTWInterface::~RTWInterface() RTWInterface::~RTWInterface()
{ {
rtw_emac.wlan_emac_link_change(false); rtw_emac.wlan_emac_link_change(false);
rtw_interface->bringdown(); EMACInterface::disconnect();
}
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;
} }
/* /*
@ -190,20 +168,10 @@ nsapi_error_t RTWInterface::connect()
} }
rtw_emac.wlan_emac_link_change(true); 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, ret = EMACInterface::connect();
_ip_address[0] ? _ip_address : 0,
_netmask[0] ? _netmask : 0, return ret;
_gateway[0] ? _gateway : 0,
DEFAULT_STACK);
return rtw_if_bringup;
} }
nsapi_error_t RTWInterface::scan(WiFiAccessPoint *res, unsigned count) nsapi_error_t RTWInterface::scan(WiFiAccessPoint *res, unsigned count)
@ -257,7 +225,9 @@ nsapi_error_t RTWInterface::disconnect()
char essid[33]; char essid[33];
rtw_emac.wlan_emac_link_change(false); rtw_emac.wlan_emac_link_change(false);
rtw_interface->bringdown();
EMACInterface::disconnect();
if (wifi_is_connected_to_ap() != RTW_SUCCESS) { if (wifi_is_connected_to_ap() != RTW_SUCCESS) {
return NSAPI_ERROR_NO_CONNECTION; return NSAPI_ERROR_NO_CONNECTION;
} }
@ -277,38 +247,6 @@ int RTWInterface::is_connected()
return !wifi_is_connected_to_ap(); 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() NetworkStack *RTWInterface::get_stack()
{ {
return &rtw_obn_stack; return &rtw_obn_stack;

View File

@ -24,6 +24,7 @@
#include "netif.h" #include "netif.h"
#include "rtw_emac.h" #include "rtw_emac.h"
#include "OnboardNetworkStack.h" #include "OnboardNetworkStack.h"
#include "EMACInterface.h"
#include "LWIPStack.h" #include "LWIPStack.h"
// Forward declaration // Forward declaration
@ -32,7 +33,7 @@ class NetworkStack;
/** Realtek Wlan (RTW) interface class /** Realtek Wlan (RTW) interface class
* Implementation of the NetworkStack for Ameba * Implementation of the NetworkStack for Ameba
*/ */
class RTWInterface: public WiFiInterface class RTWInterface: public WiFiInterface, public EMACInterface
{ {
public: public:
/** RTWWlanInterface lifetime /** RTWWlanInterface lifetime
@ -43,28 +44,6 @@ public:
~RTWInterface(); ~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 /** Set the WiFi network credentials
* *
* @param ssid Name of the network to connect to * @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 * @return Number of entries in @a, or if @a count was 0 number of available networks, negative on error
* see @a nsapi_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 nsapi_error_t set_channel(uint8_t channel);
virtual int8_t get_rssi(); 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();
RTW_EMAC &get_emac() const { return rtw_emac; } RTW_EMAC &get_emac() const { return rtw_emac; }
@ -161,15 +108,9 @@ protected:
virtual NetworkStack *get_stack(); virtual NetworkStack *get_stack();
RTW_EMAC &rtw_emac; RTW_EMAC &rtw_emac;
OnboardNetworkStack &rtw_obn_stack; OnboardNetworkStack &rtw_obn_stack;
OnboardNetworkStack::Interface *rtw_interface;
bool _dhcp;
char _ssid[256]; char _ssid[256];
char _pass[256]; char _pass[256];
nsapi_security_t _security; nsapi_security_t _security;
uint8_t _channel; 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 #endif