2 * hostapd / Neighboring APs DB
3 * Copyright(c) 2013 - 2016 Intel Mobile Communications GmbH.
4 * Copyright(c) 2011 - 2016 Intel Corporation. All rights reserved.
6 * This software may be distributed under the terms of the BSD license.
7 * See README for more details.
10 #include "utils/includes.h"
12 #include "utils/common.h"
14 #include "neighbor_db.h"
17 static struct hostapd_neighbor_entry *
18 hostapd_neighbor_get(struct hostapd_data *hapd, const u8 *bssid,
19 const struct wpa_ssid_value *ssid)
21 struct hostapd_neighbor_entry *nr;
23 dl_list_for_each(nr, &hapd->nr_db, struct hostapd_neighbor_entry,
25 if (os_memcmp(bssid, nr->bssid, ETH_ALEN) == 0 &&
26 ssid->ssid_len == nr->ssid.ssid_len &&
27 os_memcmp(ssid->ssid, nr->ssid.ssid, ssid->ssid_len) == 0)
34 static void hostapd_neighbor_clear_entry(struct hostapd_neighbor_entry *nr)
40 wpabuf_free(nr->civic);
42 os_memset(nr->bssid, 0, sizeof(nr->bssid));
43 os_memset(&nr->ssid, 0, sizeof(nr->ssid));
47 static struct hostapd_neighbor_entry *
48 hostapd_neighbor_add(struct hostapd_data *hapd)
50 struct hostapd_neighbor_entry *nr;
52 nr = os_zalloc(sizeof(struct hostapd_neighbor_entry));
56 dl_list_add(&hapd->nr_db, &nr->list);
62 int hostapd_neighbor_set(struct hostapd_data *hapd, const u8 *bssid,
63 const struct wpa_ssid_value *ssid,
64 const struct wpabuf *nr, const struct wpabuf *lci,
65 const struct wpabuf *civic)
67 struct hostapd_neighbor_entry *entry;
69 entry = hostapd_neighbor_get(hapd, bssid, ssid);
71 entry = hostapd_neighbor_add(hapd);
75 hostapd_neighbor_clear_entry(entry);
77 os_memcpy(entry->bssid, bssid, ETH_ALEN);
78 os_memcpy(&entry->ssid, ssid, sizeof(entry->ssid));
80 entry->nr = wpabuf_dup(nr);
85 entry->lci = wpabuf_dup(lci);
86 if (!entry->lci || os_get_time(&entry->lci_date))
91 entry->civic = wpabuf_dup(civic);
99 hostapd_neighbor_remove(hapd, bssid, ssid);
104 int hostapd_neighbor_remove(struct hostapd_data *hapd, const u8 *bssid,
105 const struct wpa_ssid_value *ssid)
107 struct hostapd_neighbor_entry *nr;
109 nr = hostapd_neighbor_get(hapd, bssid, ssid);
113 hostapd_neighbor_clear_entry(nr);
114 dl_list_del(&nr->list);
121 void hostpad_free_neighbor_db(struct hostapd_data *hapd)
123 struct hostapd_neighbor_entry *nr, *prev;
125 dl_list_for_each_safe(nr, prev, &hapd->nr_db,
126 struct hostapd_neighbor_entry, list) {
127 hostapd_neighbor_clear_entry(nr);
128 dl_list_del(&nr->list);