3
0
mirror of https://git.kernel.org/pub/scm/network/wireless/iwd.git synced 2024-12-26 01:02:35 +01:00

core: Add skeleton for nl80211 setup

This commit is contained in:
Marcel Holtmann 2014-07-29 21:25:01 +02:00
parent 3cb432a81c
commit 999ba12f31
4 changed files with 141 additions and 0 deletions

View File

@ -39,6 +39,7 @@ bin_PROGRAMS = src/iwd client/iwctl
src_iwd_SOURCES = src/main.c linux/nl80211.h linux/kdbus.h \
src/kdbus.h src/kdbus.c \
src/netdev.h src/netdev.c \
src/wiphy.h src/wiphy.c \
src/sha1.h src/sha1.c \
src/ie.h src/ie.c
src_iwd_LDADD = ell/libell-internal.la

View File

@ -28,6 +28,7 @@
#include <ell/ell.h>
#include "src/netdev.h"
#include "src/wiphy.h"
#include "src/kdbus.h"
static void signal_handler(struct l_signal *signal, uint32_t signo,
@ -83,8 +84,15 @@ int main(int argc, char *argv[])
goto destroy;
}
if (!wiphy_init()) {
netdev_exit();
exit_status = EXIT_FAILURE;
goto destroy;
}
l_main_run();
wiphy_exit();
netdev_exit();
exit_status = EXIT_SUCCESS;

106
src/wiphy.c Normal file
View File

@ -0,0 +1,106 @@
/*
*
* 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 <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;
}
l_genl_set_debug(genl, do_debug, "[GENL] ", NULL);
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;
}

26
src/wiphy.h Normal file
View File

@ -0,0 +1,26 @@
/*
*
* 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
*
*/
#include <stdbool.h>
bool wiphy_init(void);
bool wiphy_exit(void);