iwd/src/wiphy.c

109 lines
2.4 KiB
C
Raw Normal View History

2014-07-29 21:25:01 +02:00
/*
*
* Wireless daemon for Linux
*
* Copyright (C) 2013-2014 Intel Corporation. All rights reserved.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
#include <stdlib.h>
2014-07-29 21:25:01 +02:00
#include <ell/ell.h>
#include "linux/nl80211.h"
#include "src/wiphy.h"
static struct l_genl *genl = NULL;
static struct l_genl_family *nl80211 = NULL;
static void do_debug(const char *str, void *user_data)
{
const char *prefix = user_data;
l_info("%s%s", prefix, str);
}
static void nl80211_appeared(void *user_data)
{
struct l_genl_msg *msg;
l_debug("Found nl80211 interface");
msg = l_genl_msg_new(NL80211_CMD_GET_WIPHY);
l_genl_family_dump(nl80211, msg, NULL, NULL, NULL);
}
static void nl80211_vanished(void *user_data)
{
l_debug("Lost nl80211 interface");
}
bool wiphy_init(void)
{
if (genl)
return false;
genl = l_genl_new_default();
if (!genl) {
l_error("Failed to open generic netlink socket");
return false;
}
if (getenv("IWD_GENL_DEBUG"))
l_genl_set_debug(genl, do_debug, "[GENL] ", NULL);
2014-07-29 21:25:01 +02:00
l_debug("Opening nl80211 interface");
nl80211 = l_genl_family_new(genl, NL80211_GENL_NAME);
if (!nl80211) {
l_error("Failed to open nl80211 interface");
goto failed;
}
l_genl_family_set_watches(nl80211, nl80211_appeared, nl80211_vanished,
NULL, NULL);
return true;
failed:
l_genl_unref(genl);
genl = NULL;
return false;
}
bool wiphy_exit(void)
{
if (!genl)
return false;
l_debug("Closing nl80211 interface");
/*
* The generic netlink master object keeps track of all families
* and closing it will take care of freeing all associated resources.
*/
l_genl_unref(genl);
genl = NULL;
return true;
}