wifi: add interface query functions

Various libraries, like libnl and wpa_driver_nl80211, used hardcoded
values for the interface index (ifindex) and name (ifname).
To accomdate the legacy as well as the upcoming new driver we add
functions to query these information where at least the index differs.

Issue #4455.
This commit is contained in:
Josef Söntgen 2022-02-28 10:56:31 +01:00 committed by Christian Helmuth
parent c1fea8c002
commit 56427da393
4 changed files with 24 additions and 6 deletions

View File

@ -3,20 +3,21 @@
#include <util/string.h>
#define WLAN_DEV "wlan0"
extern "C" {
unsigned int wifi_ifindex(void);
char const * wifi_ifname(void);
unsigned int if_nametoindex(const char *ifname)
{
/* we make sure the index is always 1 in the wifi driver */
return 1;
return wifi_ifindex();
}
char *if_indextoname(unsigned int ifindex, char *ifname)
{
Genode::memcpy(ifname, WLAN_DEV, Genode::strlen(WLAN_DEV));
char const *p = wifi_ifname();
Genode::memcpy(ifname, p, Genode::strlen(p));
return ifname;
}

View File

@ -67,6 +67,18 @@ void wifi_set_rfkill(bool blocked)
}
extern "C" unsigned int wifi_ifindex(void)
{
return 1;
}
extern "C" char const wifi_ifname(void)
{
return "wlan0";
}
/**************************
** socketcall poll hack **
**************************/

View File

@ -14,6 +14,9 @@
_*wifi_*_rfkill*;
_*wifi_kick_*;
/* interface libnl/wpa_driver_nl80211*/
wifi_if*;
/* used by libnl's time() */
jiffies;

View File

@ -31,6 +31,8 @@ extern Wifi::Socket_call socket_call;
extern "C" {
unsigned int wifi_ifindex(void);
int ioctl(int fd, unsigned long request, ...)
{
long arg;
@ -46,7 +48,7 @@ int ioctl(int fd, unsigned long request, ...)
Genode::error("ioctl: request SIOCGIFADDR not implemented.");
return -1;
case SIOCGIFINDEX:
ifr->ifr_ifindex = 1;
ifr->ifr_ifindex = wifi_ifindex();
return 0;
case SIOCGIFHWADDR:
socket_call.get_mac_address((unsigned char*)ifr->ifr_hwaddr.sa_data);