]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/network/networkd-wifi.c
network: bridgeFDB: rename FdbEntry -> BridgeFDB
[thirdparty/systemd.git] / src / network / networkd-wifi.c
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2
3 #include <net/ethernet.h>
4 #include <linux/nl80211.h>
5
6 #include "sd-bus.h"
7
8 #include "bus-util.h"
9 #include "ether-addr-util.h"
10 #include "netlink-internal.h"
11 #include "netlink-util.h"
12 #include "networkd-link.h"
13 #include "networkd-manager.h"
14 #include "networkd-wifi.h"
15 #include "string-util.h"
16 #include "wifi-util.h"
17
18 int wifi_get_info(Link *link) {
19 _cleanup_free_ char *ssid = NULL;
20 enum nl80211_iftype iftype;
21 const char *type;
22 int r, s = 0;
23
24 assert(link);
25
26 if (!link->sd_device)
27 return 0;
28
29 r = sd_device_get_devtype(link->sd_device, &type);
30 if (r == -ENOENT)
31 return 0;
32 else if (r < 0)
33 return r;
34
35 if (!streq(type, "wlan"))
36 return 0;
37
38 r = wifi_get_interface(link->manager->genl, link->ifindex, &iftype, &ssid);
39 if (r < 0)
40 return r;
41 if (r > 0 && link->wlan_iftype == iftype && streq_ptr(link->ssid, ssid))
42 r = 0;
43
44 link->wlan_iftype = iftype;
45 free_and_replace(link->ssid, ssid);
46
47 if (link->wlan_iftype == NL80211_IFTYPE_STATION) {
48 struct ether_addr old_bssid = link->bssid;
49
50 s = wifi_get_station(link->manager->genl, link->ifindex, &link->bssid);
51 if (s < 0)
52 return s;
53 if (s > 0 && memcmp(&old_bssid, &link->bssid, sizeof old_bssid) == 0)
54 s = 0;
55 }
56
57 if (r > 0 || s > 0) {
58 char buf[ETHER_ADDR_TO_STRING_MAX];
59
60 if (link->wlan_iftype == NL80211_IFTYPE_STATION && link->ssid)
61 log_link_info(link, "Connected WiFi access point: %s (%s)",
62 link->ssid, ether_addr_to_string(&link->bssid, buf));
63
64 return 1; /* Some information is updated. */
65 }
66
67 return 0; /* No new information. */
68 }