eiwd

no dbus iwd with iwctl functionality
git clone https://git.daat.foo/repos/eiwd.git
Log | Files | Refs | Submodules | README | LICENSE

commit a3c1fa28dae273a189e6e753a92bfe69917bc0af
parent 60a74c46a0aa5955c0ff3eed9ff32657391d9fe4
Author: Marcel Holtmann <marcel@holtmann.org>
Date:   Sun, 14 Oct 2018 05:41:06 +0200

build: Rename nl80211_util.[ch] into nl80211util.[ch]

Diffstat:
MMakefile.am | 3+--
Msrc/adhoc.c | 2+-
Msrc/ap.c | 2+-
Msrc/netdev.c | 2+-
Dsrc/nl80211_util.c | 192-------------------------------------------------------------------------------
Asrc/nl80211util.c | 192+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Rsrc/nl80211_util.h -> src/nl80211util.h | 0
7 files changed, 196 insertions(+), 197 deletions(-)

diff --git a/Makefile.am b/Makefile.am @@ -130,8 +130,7 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h \ src/ap.h src/ap.c \ src/adhoc.h src/adhoc.c \ src/sae.h src/sae.c \ - src/nl80211_util.h \ - src/nl80211_util.c \ + src/nl80211util.h src/nl80211util.c \ $(eap_sources) \ $(builtin_sources) src_iwd_LDADD = ell/libell-internal.la -ldl diff --git a/src/adhoc.c b/src/adhoc.c @@ -40,7 +40,7 @@ #include "src/mpdu.h" #include "src/adhoc.h" #include "src/dbus.h" -#include "src/nl80211_util.h" +#include "src/nl80211util.h" struct adhoc_state { struct netdev *netdev; diff --git a/src/ap.c b/src/ap.c @@ -44,7 +44,7 @@ #include "src/handshake.h" #include "src/ap.h" #include "src/dbus.h" -#include "src/nl80211_util.h" +#include "src/nl80211util.h" struct ap_state { struct netdev *netdev; diff --git a/src/netdev.c b/src/netdev.c @@ -56,7 +56,7 @@ #include "src/util.h" #include "src/watchlist.h" #include "src/sae.h" -#include "src/nl80211_util.h" +#include "src/nl80211util.h" #ifndef ENOTSUPP #define ENOTSUPP 524 diff --git a/src/nl80211_util.c b/src/nl80211_util.c @@ -1,192 +0,0 @@ -/* - * - * Wireless daemon for Linux - * - * Copyright (C) 2018 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 <linux/if_ether.h> -#include <ell/ell.h> - -#include "linux/nl80211.h" - -#include "nl80211_util.h" - -struct l_genl_msg *nl80211_build_new_key_group(uint32_t ifindex, uint32_t cipher, - uint8_t key_id, const uint8_t *key, - size_t key_len, const uint8_t *ctr, - size_t ctr_len, const uint8_t *addr) -{ - struct l_genl_msg *msg; - - msg = l_genl_msg_new_sized(NL80211_CMD_NEW_KEY, 512); - - l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex); - - if (addr) - l_genl_msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); - - l_genl_msg_enter_nested(msg, NL80211_ATTR_KEY); - l_genl_msg_append_attr(msg, NL80211_KEY_DATA, key_len, key); - l_genl_msg_append_attr(msg, NL80211_KEY_CIPHER, 4, &cipher); - l_genl_msg_append_attr(msg, NL80211_KEY_IDX, 1, &key_id); - - if (ctr) - l_genl_msg_append_attr(msg, NL80211_KEY_SEQ, ctr_len, ctr); - - if (addr) { - uint32_t type = NL80211_KEYTYPE_GROUP; - - l_genl_msg_append_attr(msg, NL80211_KEY_TYPE, 4, &type); - l_genl_msg_enter_nested(msg, NL80211_KEY_DEFAULT_TYPES); - l_genl_msg_append_attr(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST, - 0, NULL); - l_genl_msg_leave_nested(msg); - } - - l_genl_msg_leave_nested(msg); - - return msg; -} - -static struct l_genl_msg *nl80211_build_set_station(uint32_t ifindex, - const uint8_t *addr, - struct nl80211_sta_flag_update *flags) -{ - struct l_genl_msg *msg; - - msg = l_genl_msg_new_sized(NL80211_CMD_SET_STATION, 512); - - l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex); - l_genl_msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); - l_genl_msg_append_attr(msg, NL80211_ATTR_STA_FLAGS2, - sizeof(struct nl80211_sta_flag_update), flags); - - return msg; -} - -struct l_genl_msg *nl80211_build_set_station_authorized(uint32_t ifindex, - const uint8_t *addr) -{ - struct nl80211_sta_flag_update flags = { - .mask = (1 << NL80211_STA_FLAG_AUTHORIZED), - .set = (1 << NL80211_STA_FLAG_AUTHORIZED), - }; - - return nl80211_build_set_station(ifindex, addr, &flags); -} - -struct l_genl_msg *nl80211_build_set_station_associated(uint32_t ifindex, - const uint8_t *addr) -{ - struct nl80211_sta_flag_update flags = { - .mask = (1 << NL80211_STA_FLAG_AUTHENTICATED) | - (1 << NL80211_STA_FLAG_ASSOCIATED), - .set = (1 << NL80211_STA_FLAG_AUTHENTICATED) | - (1 << NL80211_STA_FLAG_ASSOCIATED), - }; - - return nl80211_build_set_station(ifindex, addr, &flags); -} - -struct l_genl_msg *nl80211_build_set_station_unauthorized(uint32_t ifindex, - const uint8_t *addr) -{ - struct nl80211_sta_flag_update flags = { - .mask = (1 << NL80211_STA_FLAG_AUTHORIZED), - .set = 0, - }; - - return nl80211_build_set_station(ifindex, addr, &flags); -} - -struct l_genl_msg *nl80211_build_set_key(uint32_t ifindex, uint8_t key_index) -{ - struct l_genl_msg *msg; - - msg = l_genl_msg_new_sized(NL80211_CMD_SET_KEY, 128); - - l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex); - - l_genl_msg_enter_nested(msg, NL80211_ATTR_KEY); - l_genl_msg_append_attr(msg, NL80211_KEY_IDX, 1, &key_index); - l_genl_msg_append_attr(msg, NL80211_KEY_DEFAULT, 0, NULL); - l_genl_msg_enter_nested(msg, NL80211_KEY_DEFAULT_TYPES); - l_genl_msg_append_attr(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST, - 0, NULL); - l_genl_msg_leave_nested(msg); - l_genl_msg_leave_nested(msg); - - return msg; -} - -struct l_genl_msg *nl80211_build_get_key(uint32_t ifindex, uint8_t key_index) -{ - struct l_genl_msg *msg; - - msg = l_genl_msg_new_sized(NL80211_CMD_GET_KEY, 128); - - l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex); - l_genl_msg_append_attr(msg, NL80211_ATTR_KEY_IDX, 1, &key_index); - - return msg; -} - -const void *nl80211_parse_get_key_seq(struct l_genl_msg *msg) -{ - struct l_genl_attr attr, nested; - uint16_t type, len; - const void *data; - - if (l_genl_msg_get_error(msg) < 0 || !l_genl_attr_init(&attr, msg)) { - l_error("GET_KEY failed for the GTK: %i", - l_genl_msg_get_error(msg)); - return NULL; - } - - while (l_genl_attr_next(&attr, &type, &len, &data)) { - if (type != NL80211_ATTR_KEY) - continue; - - break; - } - - if (type != NL80211_ATTR_KEY || !l_genl_attr_recurse(&attr, &nested)) { - l_error("Can't recurse into ATTR_KEY in GET_KEY reply"); - return NULL; - } - - while (l_genl_attr_next(&nested, &type, &len, &data)) { - if (type != NL80211_KEY_SEQ) - continue; - - break; - } - - if (type != NL80211_KEY_SEQ) { - l_error("KEY_SEQ not returned in GET_KEY reply"); - return NULL; - } - - if (len != 6) { - l_error("KEY_SEQ length != 6 in GET_KEY reply"); - return NULL; - } - - return data; -} diff --git a/src/nl80211util.c b/src/nl80211util.c @@ -0,0 +1,192 @@ +/* + * + * Wireless daemon for Linux + * + * Copyright (C) 2018 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 <linux/if_ether.h> +#include <ell/ell.h> + +#include "linux/nl80211.h" + +#include "src/nl80211util.h" + +struct l_genl_msg *nl80211_build_new_key_group(uint32_t ifindex, uint32_t cipher, + uint8_t key_id, const uint8_t *key, + size_t key_len, const uint8_t *ctr, + size_t ctr_len, const uint8_t *addr) +{ + struct l_genl_msg *msg; + + msg = l_genl_msg_new_sized(NL80211_CMD_NEW_KEY, 512); + + l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex); + + if (addr) + l_genl_msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); + + l_genl_msg_enter_nested(msg, NL80211_ATTR_KEY); + l_genl_msg_append_attr(msg, NL80211_KEY_DATA, key_len, key); + l_genl_msg_append_attr(msg, NL80211_KEY_CIPHER, 4, &cipher); + l_genl_msg_append_attr(msg, NL80211_KEY_IDX, 1, &key_id); + + if (ctr) + l_genl_msg_append_attr(msg, NL80211_KEY_SEQ, ctr_len, ctr); + + if (addr) { + uint32_t type = NL80211_KEYTYPE_GROUP; + + l_genl_msg_append_attr(msg, NL80211_KEY_TYPE, 4, &type); + l_genl_msg_enter_nested(msg, NL80211_KEY_DEFAULT_TYPES); + l_genl_msg_append_attr(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST, + 0, NULL); + l_genl_msg_leave_nested(msg); + } + + l_genl_msg_leave_nested(msg); + + return msg; +} + +static struct l_genl_msg *nl80211_build_set_station(uint32_t ifindex, + const uint8_t *addr, + struct nl80211_sta_flag_update *flags) +{ + struct l_genl_msg *msg; + + msg = l_genl_msg_new_sized(NL80211_CMD_SET_STATION, 512); + + l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex); + l_genl_msg_append_attr(msg, NL80211_ATTR_MAC, ETH_ALEN, addr); + l_genl_msg_append_attr(msg, NL80211_ATTR_STA_FLAGS2, + sizeof(struct nl80211_sta_flag_update), flags); + + return msg; +} + +struct l_genl_msg *nl80211_build_set_station_authorized(uint32_t ifindex, + const uint8_t *addr) +{ + struct nl80211_sta_flag_update flags = { + .mask = (1 << NL80211_STA_FLAG_AUTHORIZED), + .set = (1 << NL80211_STA_FLAG_AUTHORIZED), + }; + + return nl80211_build_set_station(ifindex, addr, &flags); +} + +struct l_genl_msg *nl80211_build_set_station_associated(uint32_t ifindex, + const uint8_t *addr) +{ + struct nl80211_sta_flag_update flags = { + .mask = (1 << NL80211_STA_FLAG_AUTHENTICATED) | + (1 << NL80211_STA_FLAG_ASSOCIATED), + .set = (1 << NL80211_STA_FLAG_AUTHENTICATED) | + (1 << NL80211_STA_FLAG_ASSOCIATED), + }; + + return nl80211_build_set_station(ifindex, addr, &flags); +} + +struct l_genl_msg *nl80211_build_set_station_unauthorized(uint32_t ifindex, + const uint8_t *addr) +{ + struct nl80211_sta_flag_update flags = { + .mask = (1 << NL80211_STA_FLAG_AUTHORIZED), + .set = 0, + }; + + return nl80211_build_set_station(ifindex, addr, &flags); +} + +struct l_genl_msg *nl80211_build_set_key(uint32_t ifindex, uint8_t key_index) +{ + struct l_genl_msg *msg; + + msg = l_genl_msg_new_sized(NL80211_CMD_SET_KEY, 128); + + l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex); + + l_genl_msg_enter_nested(msg, NL80211_ATTR_KEY); + l_genl_msg_append_attr(msg, NL80211_KEY_IDX, 1, &key_index); + l_genl_msg_append_attr(msg, NL80211_KEY_DEFAULT, 0, NULL); + l_genl_msg_enter_nested(msg, NL80211_KEY_DEFAULT_TYPES); + l_genl_msg_append_attr(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST, + 0, NULL); + l_genl_msg_leave_nested(msg); + l_genl_msg_leave_nested(msg); + + return msg; +} + +struct l_genl_msg *nl80211_build_get_key(uint32_t ifindex, uint8_t key_index) +{ + struct l_genl_msg *msg; + + msg = l_genl_msg_new_sized(NL80211_CMD_GET_KEY, 128); + + l_genl_msg_append_attr(msg, NL80211_ATTR_IFINDEX, 4, &ifindex); + l_genl_msg_append_attr(msg, NL80211_ATTR_KEY_IDX, 1, &key_index); + + return msg; +} + +const void *nl80211_parse_get_key_seq(struct l_genl_msg *msg) +{ + struct l_genl_attr attr, nested; + uint16_t type, len; + const void *data; + + if (l_genl_msg_get_error(msg) < 0 || !l_genl_attr_init(&attr, msg)) { + l_error("GET_KEY failed for the GTK: %i", + l_genl_msg_get_error(msg)); + return NULL; + } + + while (l_genl_attr_next(&attr, &type, &len, &data)) { + if (type != NL80211_ATTR_KEY) + continue; + + break; + } + + if (type != NL80211_ATTR_KEY || !l_genl_attr_recurse(&attr, &nested)) { + l_error("Can't recurse into ATTR_KEY in GET_KEY reply"); + return NULL; + } + + while (l_genl_attr_next(&nested, &type, &len, &data)) { + if (type != NL80211_KEY_SEQ) + continue; + + break; + } + + if (type != NL80211_KEY_SEQ) { + l_error("KEY_SEQ not returned in GET_KEY reply"); + return NULL; + } + + if (len != 6) { + l_error("KEY_SEQ length != 6 in GET_KEY reply"); + return NULL; + } + + return data; +} diff --git a/src/nl80211_util.h b/src/nl80211util.h