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 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 &&
27 (ssid->ssid_len == nr->ssid.ssid_len &&
28 os_memcmp(ssid->ssid, nr->ssid.ssid,
29 ssid->ssid_len) == 0)))
36 static void hostapd_neighbor_clear_entry(struct hostapd_neighbor_entry *nr)
42 wpabuf_free(nr->civic);
44 os_memset(nr->bssid, 0, sizeof(nr->bssid));
45 os_memset(&nr->ssid, 0, sizeof(nr->ssid));
49 static struct hostapd_neighbor_entry *
50 hostapd_neighbor_add(struct hostapd_data *hapd)
52 struct hostapd_neighbor_entry *nr;
54 nr = os_zalloc(sizeof(struct hostapd_neighbor_entry));
58 dl_list_add(&hapd->nr_db, &nr->list);
64 int hostapd_neighbor_set(struct hostapd_data *hapd, const u8 *bssid,
65 const struct wpa_ssid_value *ssid,
66 const struct wpabuf *nr, const struct wpabuf *lci,
67 const struct wpabuf *civic)
69 struct hostapd_neighbor_entry *entry;
71 entry = hostapd_neighbor_get(hapd, bssid, ssid);
73 entry = hostapd_neighbor_add(hapd);
77 hostapd_neighbor_clear_entry(entry);
79 os_memcpy(entry->bssid, bssid, ETH_ALEN);
80 os_memcpy(&entry->ssid, ssid, sizeof(entry->ssid));
82 entry->nr = wpabuf_dup(nr);
87 entry->lci = wpabuf_dup(lci);
88 if (!entry->lci || os_get_time(&entry->lci_date))
93 entry->civic = wpabuf_dup(civic);
101 hostapd_neighbor_remove(hapd, bssid, ssid);
106 int hostapd_neighbor_remove(struct hostapd_data *hapd, const u8 *bssid,
107 const struct wpa_ssid_value *ssid)
109 struct hostapd_neighbor_entry *nr;
111 nr = hostapd_neighbor_get(hapd, bssid, ssid);
115 hostapd_neighbor_clear_entry(nr);
116 dl_list_del(&nr->list);
123 void hostpad_free_neighbor_db(struct hostapd_data *hapd)
125 struct hostapd_neighbor_entry *nr, *prev;
127 dl_list_for_each_safe(nr, prev, &hapd->nr_db,
128 struct hostapd_neighbor_entry, list) {
129 hostapd_neighbor_clear_entry(nr);
130 dl_list_del(&nr->list);