driver_nl80211/wext: Share netlink operstate send function
As an initial step in sharing netlink helper functions among driver wrappers, create a new file for netlink code and move operstate send function there.
This commit is contained in:
parent
3b31db5199
commit
e2d02c29b5
5 changed files with 129 additions and 137 deletions
|
@ -28,10 +28,11 @@
|
|||
#include "nl80211_copy.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "radiotap.h"
|
||||
#include "radiotap_iter.h"
|
||||
#include "eloop.h"
|
||||
#include "common/ieee802_11_defs.h"
|
||||
#include "netlink.h"
|
||||
#include "radiotap.h"
|
||||
#include "radiotap_iter.h"
|
||||
#include "driver.h"
|
||||
|
||||
#ifdef CONFIG_LIBNL20
|
||||
|
@ -303,68 +304,6 @@ static int set_ifhwaddr(struct wpa_driver_nl80211_data *drv,
|
|||
#endif /* HOSTAPD */
|
||||
|
||||
|
||||
static int wpa_driver_nl80211_send_oper_ifla(
|
||||
struct wpa_driver_nl80211_data *drv,
|
||||
int linkmode, int operstate)
|
||||
{
|
||||
struct {
|
||||
struct nlmsghdr hdr;
|
||||
struct ifinfomsg ifinfo;
|
||||
char opts[16];
|
||||
} req;
|
||||
struct rtattr *rta;
|
||||
static int nl_seq;
|
||||
ssize_t ret;
|
||||
|
||||
os_memset(&req, 0, sizeof(req));
|
||||
|
||||
req.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
||||
req.hdr.nlmsg_type = RTM_SETLINK;
|
||||
req.hdr.nlmsg_flags = NLM_F_REQUEST;
|
||||
req.hdr.nlmsg_seq = ++nl_seq;
|
||||
req.hdr.nlmsg_pid = 0;
|
||||
|
||||
req.ifinfo.ifi_family = AF_UNSPEC;
|
||||
req.ifinfo.ifi_type = 0;
|
||||
req.ifinfo.ifi_index = drv->ifindex;
|
||||
req.ifinfo.ifi_flags = 0;
|
||||
req.ifinfo.ifi_change = 0;
|
||||
|
||||
if (linkmode != -1) {
|
||||
rta = aliasing_hide_typecast(
|
||||
((char *) &req + NLMSG_ALIGN(req.hdr.nlmsg_len)),
|
||||
struct rtattr);
|
||||
rta->rta_type = IFLA_LINKMODE;
|
||||
rta->rta_len = RTA_LENGTH(sizeof(char));
|
||||
*((char *) RTA_DATA(rta)) = linkmode;
|
||||
req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) +
|
||||
RTA_LENGTH(sizeof(char));
|
||||
}
|
||||
if (operstate != -1) {
|
||||
rta = aliasing_hide_typecast(
|
||||
((char *) &req + NLMSG_ALIGN(req.hdr.nlmsg_len)),
|
||||
struct rtattr);
|
||||
rta->rta_type = IFLA_OPERSTATE;
|
||||
rta->rta_len = RTA_LENGTH(sizeof(char));
|
||||
*((char *) RTA_DATA(rta)) = operstate;
|
||||
req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) +
|
||||
RTA_LENGTH(sizeof(char));
|
||||
}
|
||||
|
||||
wpa_printf(MSG_DEBUG, "nl80211: Operstate: linkmode=%d, operstate=%d",
|
||||
linkmode, operstate);
|
||||
|
||||
ret = send(drv->link_event_sock, &req, req.hdr.nlmsg_len, 0);
|
||||
if (ret < 0) {
|
||||
wpa_printf(MSG_DEBUG, "nl80211: Sending operstate IFLA failed:"
|
||||
" %s (assume operstate is not supported)",
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
return ret < 0 ? -1 : 0;
|
||||
}
|
||||
|
||||
|
||||
static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid)
|
||||
{
|
||||
struct wpa_driver_nl80211_data *drv = priv;
|
||||
|
@ -500,7 +439,8 @@ static void wpa_driver_nl80211_event_rtm_newlink(struct wpa_driver_nl80211_data
|
|||
if (drv->operstate == 1 &&
|
||||
(ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP &&
|
||||
!(ifi->ifi_flags & IFF_RUNNING))
|
||||
wpa_driver_nl80211_send_oper_ifla(drv, -1, IF_OPER_UP);
|
||||
netlink_send_oper_ifla(drv->link_event_sock, drv->ifindex,
|
||||
-1, IF_OPER_UP);
|
||||
|
||||
_nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
|
||||
|
||||
|
@ -1369,7 +1309,8 @@ wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv)
|
|||
if (wpa_driver_nl80211_capa(drv))
|
||||
return -1;
|
||||
|
||||
wpa_driver_nl80211_send_oper_ifla(drv, 1, IF_OPER_DORMANT);
|
||||
netlink_send_oper_ifla(drv->link_event_sock, drv->ifindex,
|
||||
1, IF_OPER_DORMANT);
|
||||
#endif /* HOSTAPD */
|
||||
|
||||
return 0;
|
||||
|
@ -1448,7 +1389,8 @@ static void wpa_driver_nl80211_deinit(void *priv)
|
|||
wpa_driver_nl80211_free_bss(drv);
|
||||
#endif /* HOSTAPD */
|
||||
|
||||
wpa_driver_nl80211_send_oper_ifla(priv, 0, IF_OPER_UP);
|
||||
netlink_send_oper_ifla(drv->link_event_sock, drv->ifindex,
|
||||
0, IF_OPER_UP);
|
||||
|
||||
if (drv->link_event_sock >= 0) {
|
||||
eloop_unregister_read_sock(drv->link_event_sock);
|
||||
|
@ -3767,8 +3709,9 @@ static int wpa_driver_nl80211_set_operstate(void *priv, int state)
|
|||
wpa_printf(MSG_DEBUG, "%s: operstate %d->%d (%s)",
|
||||
__func__, drv->operstate, state, state ? "UP" : "DORMANT");
|
||||
drv->operstate = state;
|
||||
return wpa_driver_nl80211_send_oper_ifla(
|
||||
drv, -1, state ? IF_OPER_UP : IF_OPER_DORMANT);
|
||||
return netlink_send_oper_ifla(drv->link_event_sock, drv->ifindex,
|
||||
-1,
|
||||
state ? IF_OPER_UP : IF_OPER_DORMANT);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -24,12 +24,13 @@
|
|||
|
||||
#include "wireless_copy.h"
|
||||
#include "common.h"
|
||||
#include "driver.h"
|
||||
#include "eloop.h"
|
||||
#include "priv_netlink.h"
|
||||
#include "driver_wext.h"
|
||||
#include "common/ieee802_11_defs.h"
|
||||
#include "common/wpa_common.h"
|
||||
#include "priv_netlink.h"
|
||||
#include "netlink.h"
|
||||
#include "driver.h"
|
||||
#include "driver_wext.h"
|
||||
|
||||
|
||||
static int wpa_driver_wext_flush_pmkid(void *priv);
|
||||
|
@ -39,66 +40,6 @@ static void wpa_driver_wext_disconnect(struct wpa_driver_wext_data *drv);
|
|||
static int wpa_driver_wext_set_auth_alg(void *priv, int auth_alg);
|
||||
|
||||
|
||||
static int wpa_driver_wext_send_oper_ifla(struct wpa_driver_wext_data *drv,
|
||||
int linkmode, int operstate)
|
||||
{
|
||||
struct {
|
||||
struct nlmsghdr hdr;
|
||||
struct ifinfomsg ifinfo;
|
||||
char opts[16];
|
||||
} req;
|
||||
struct rtattr *rta;
|
||||
static int nl_seq;
|
||||
ssize_t ret;
|
||||
|
||||
os_memset(&req, 0, sizeof(req));
|
||||
|
||||
req.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
||||
req.hdr.nlmsg_type = RTM_SETLINK;
|
||||
req.hdr.nlmsg_flags = NLM_F_REQUEST;
|
||||
req.hdr.nlmsg_seq = ++nl_seq;
|
||||
req.hdr.nlmsg_pid = 0;
|
||||
|
||||
req.ifinfo.ifi_family = AF_UNSPEC;
|
||||
req.ifinfo.ifi_type = 0;
|
||||
req.ifinfo.ifi_index = drv->ifindex;
|
||||
req.ifinfo.ifi_flags = 0;
|
||||
req.ifinfo.ifi_change = 0;
|
||||
|
||||
if (linkmode != -1) {
|
||||
rta = aliasing_hide_typecast(
|
||||
((char *) &req + NLMSG_ALIGN(req.hdr.nlmsg_len)),
|
||||
struct rtattr);
|
||||
rta->rta_type = IFLA_LINKMODE;
|
||||
rta->rta_len = RTA_LENGTH(sizeof(char));
|
||||
*((char *) RTA_DATA(rta)) = linkmode;
|
||||
req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) +
|
||||
RTA_LENGTH(sizeof(char));
|
||||
}
|
||||
if (operstate != -1) {
|
||||
rta = (struct rtattr *)
|
||||
((char *) &req + NLMSG_ALIGN(req.hdr.nlmsg_len));
|
||||
rta->rta_type = IFLA_OPERSTATE;
|
||||
rta->rta_len = RTA_LENGTH(sizeof(char));
|
||||
*((char *) RTA_DATA(rta)) = operstate;
|
||||
req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) +
|
||||
RTA_LENGTH(sizeof(char));
|
||||
}
|
||||
|
||||
wpa_printf(MSG_DEBUG, "WEXT: Operstate: linkmode=%d, operstate=%d",
|
||||
linkmode, operstate);
|
||||
|
||||
ret = send(drv->event_sock, &req, req.hdr.nlmsg_len, 0);
|
||||
if (ret < 0) {
|
||||
wpa_printf(MSG_DEBUG, "WEXT: Sending operstate IFLA failed: "
|
||||
"%s (assume operstate is not supported)",
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
return ret < 0 ? -1 : 0;
|
||||
}
|
||||
|
||||
|
||||
int wpa_driver_wext_set_auth_param(struct wpa_driver_wext_data *drv,
|
||||
int idx, u32 value)
|
||||
{
|
||||
|
@ -712,7 +653,8 @@ static void wpa_driver_wext_event_rtm_newlink(struct wpa_driver_wext_data *drv,
|
|||
if (drv->operstate == 1 &&
|
||||
(ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP &&
|
||||
!(ifi->ifi_flags & IFF_RUNNING))
|
||||
wpa_driver_wext_send_oper_ifla(drv, -1, IF_OPER_UP);
|
||||
netlink_send_oper_ifla(drv->event_sock, drv->ifindex,
|
||||
-1, IF_OPER_UP);
|
||||
|
||||
nlmsg_len = NLMSG_ALIGN(sizeof(struct ifinfomsg));
|
||||
|
||||
|
@ -1023,7 +965,8 @@ static int wpa_driver_wext_finish_drv_init(struct wpa_driver_wext_data *drv)
|
|||
wpa_driver_wext_alternative_ifindex(drv, ifname2);
|
||||
}
|
||||
|
||||
wpa_driver_wext_send_oper_ifla(drv, 1, IF_OPER_DORMANT);
|
||||
netlink_send_oper_ifla(drv->event_sock, drv->ifindex,
|
||||
1, IF_OPER_DORMANT);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -1051,7 +994,7 @@ void wpa_driver_wext_deinit(void *priv)
|
|||
*/
|
||||
wpa_driver_wext_disconnect(drv);
|
||||
|
||||
wpa_driver_wext_send_oper_ifla(priv, 0, IF_OPER_UP);
|
||||
netlink_send_oper_ifla(drv->event_sock, drv->ifindex, 0, IF_OPER_UP);
|
||||
|
||||
eloop_unregister_read_sock(drv->event_sock);
|
||||
if (drv->mlme_sock >= 0)
|
||||
|
@ -2360,8 +2303,9 @@ int wpa_driver_wext_set_operstate(void *priv, int state)
|
|||
wpa_printf(MSG_DEBUG, "%s: operstate %d->%d (%s)",
|
||||
__func__, drv->operstate, state, state ? "UP" : "DORMANT");
|
||||
drv->operstate = state;
|
||||
return wpa_driver_wext_send_oper_ifla(
|
||||
drv, -1, state ? IF_OPER_UP : IF_OPER_DORMANT);
|
||||
return netlink_send_oper_ifla(drv->event_sock, drv->ifindex,
|
||||
-1,
|
||||
state ? IF_OPER_UP : IF_OPER_DORMANT);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -25,6 +25,7 @@ DRV_OBJS += ../src/drivers/driver_nl80211.o
|
|||
DRV_OBJS += ../src/utils/radiotap.o
|
||||
NEED_SME=y
|
||||
NEED_AP_MLME=y
|
||||
NEED_NETLINK=y
|
||||
DRV_LIBS += -lnl
|
||||
|
||||
ifdef CONFIG_LIBNL20
|
||||
|
@ -67,6 +68,7 @@ endif
|
|||
ifdef CONFIG_DRIVER_WEXT
|
||||
DRV_WPA_CFLAGS += -DCONFIG_DRIVER_WEXT
|
||||
CONFIG_WIRELESS_EXTENSION=y
|
||||
NEED_NETLINK=y
|
||||
endif
|
||||
|
||||
ifdef CONFIG_DRIVER_HERMES
|
||||
|
@ -148,6 +150,10 @@ DRV_WPA_CFLAGS += -DCONFIG_WIRELESS_EXTENSION
|
|||
DRV_WPA_OBJS += ../src/drivers/driver_wext.o
|
||||
endif
|
||||
|
||||
ifdef NEED_NETLINK
|
||||
DRV_OBJS += ../src/drivers/netlink.o
|
||||
endif
|
||||
|
||||
##### COMMON VARS
|
||||
DRV_BOTH_CFLAGS := $(DRV_CFLAGS) $(DRV_WPA_CFLAGS) $(DRV_AP_CFLAGS)
|
||||
DRV_WPA_CFLAGS += $(DRV_CFLAGS)
|
||||
|
|
79
src/drivers/netlink.c
Normal file
79
src/drivers/netlink.c
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*
|
||||
* Netlink helper functions for driver wrappers
|
||||
* Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#include "includes.h"
|
||||
|
||||
#include "common.h"
|
||||
#include "priv_netlink.h"
|
||||
#include "netlink.h"
|
||||
|
||||
|
||||
int netlink_send_oper_ifla(int sock, int ifindex, int linkmode, int operstate)
|
||||
{
|
||||
struct {
|
||||
struct nlmsghdr hdr;
|
||||
struct ifinfomsg ifinfo;
|
||||
char opts[16];
|
||||
} req;
|
||||
struct rtattr *rta;
|
||||
static int nl_seq;
|
||||
ssize_t ret;
|
||||
|
||||
os_memset(&req, 0, sizeof(req));
|
||||
|
||||
req.hdr.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
|
||||
req.hdr.nlmsg_type = RTM_SETLINK;
|
||||
req.hdr.nlmsg_flags = NLM_F_REQUEST;
|
||||
req.hdr.nlmsg_seq = ++nl_seq;
|
||||
req.hdr.nlmsg_pid = 0;
|
||||
|
||||
req.ifinfo.ifi_family = AF_UNSPEC;
|
||||
req.ifinfo.ifi_type = 0;
|
||||
req.ifinfo.ifi_index = ifindex;
|
||||
req.ifinfo.ifi_flags = 0;
|
||||
req.ifinfo.ifi_change = 0;
|
||||
|
||||
if (linkmode != -1) {
|
||||
rta = aliasing_hide_typecast(
|
||||
((char *) &req + NLMSG_ALIGN(req.hdr.nlmsg_len)),
|
||||
struct rtattr);
|
||||
rta->rta_type = IFLA_LINKMODE;
|
||||
rta->rta_len = RTA_LENGTH(sizeof(char));
|
||||
*((char *) RTA_DATA(rta)) = linkmode;
|
||||
req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) +
|
||||
RTA_LENGTH(sizeof(char));
|
||||
}
|
||||
if (operstate != -1) {
|
||||
rta = aliasing_hide_typecast(
|
||||
((char *) &req + NLMSG_ALIGN(req.hdr.nlmsg_len)),
|
||||
struct rtattr);
|
||||
rta->rta_type = IFLA_OPERSTATE;
|
||||
rta->rta_len = RTA_LENGTH(sizeof(char));
|
||||
*((char *) RTA_DATA(rta)) = operstate;
|
||||
req.hdr.nlmsg_len = NLMSG_ALIGN(req.hdr.nlmsg_len) +
|
||||
RTA_LENGTH(sizeof(char));
|
||||
}
|
||||
|
||||
wpa_printf(MSG_DEBUG, "netlink: Operstate: linkmode=%d, operstate=%d",
|
||||
linkmode, operstate);
|
||||
|
||||
ret = send(sock, &req, req.hdr.nlmsg_len, 0);
|
||||
if (ret < 0) {
|
||||
wpa_printf(MSG_DEBUG, "netlink: Sending operstate IFLA "
|
||||
"failed: %s (assume operstate is not supported)",
|
||||
strerror(errno));
|
||||
}
|
||||
|
||||
return ret < 0 ? -1 : 0;
|
||||
}
|
20
src/drivers/netlink.h
Normal file
20
src/drivers/netlink.h
Normal file
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* Netlink helper functions for driver wrappers
|
||||
* Copyright (c) 2002-2009, Jouni Malinen <j@w1.fi>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Alternatively, this software may be distributed under the terms of BSD
|
||||
* license.
|
||||
*
|
||||
* See README and COPYING for more details.
|
||||
*/
|
||||
|
||||
#ifndef NETLINK_H
|
||||
#define NETLINK_H
|
||||
|
||||
int netlink_send_oper_ifla(int sock, int ifindex, int linkmode, int operstate);
|
||||
|
||||
#endif /* NETLINK_H */
|
Loading…
Reference in a new issue