blob: 4fed0faf9c796e128bf17f588221555962fb5fc2 [file] [log] [blame]
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +01001/* neigh_cache.h
2 *
3 * Copyright (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
4 * Author: Pau Espin Pedrol <pespin@sysmocom.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20#pragma once
21
22#include <stdint.h>
23#include <inttypes.h>
24
25#include <osmocom/core/linuxlist.h>
26#include <osmocom/core/timer.h>
27
28#include <osmocom/gsm/gsm23003.h>
29#include <osmocom/gprs/gprs_bssgp_rim.h>
30
31////////////////////
32// NEIGH CACHE
33///////////////////
34
35/* ARFC+BSIC -> CGI PS cache */
36struct neigh_cache {
37 struct llist_head list; /* list of neigh_cache_entry items */
38 struct osmo_timer_list cleanup_timer; /* Timer removing too-old entries */
39 struct timespec keep_time_intval;
40};
41
42struct neigh_cache_entry_key {
43 uint16_t local_lac;
44 uint16_t local_ci;
45 uint16_t tgt_arfcn;
46 uint8_t tgt_bsic;
47};
48#define NEIGH_CACHE_ENTRY_KEY_FMT "%" PRIu16 "-%" PRIu16 "-%" PRIu16 "-%" PRIu8
49#define NEIGH_CACHE_ENTRY_KEY_ARGS(key) (key)->local_lac, (key)->local_ci, (key)->tgt_arfcn, (key)->tgt_bsic
50
51struct neigh_cache_entry {
52 struct llist_head list; /* to be included in neigh_cache->list */
53 struct timespec update_ts;
54 struct neigh_cache_entry_key key;
55 struct osmo_cell_global_id_ps value;
56};
57
Pau Espin Pedrolab7159f2021-01-26 17:51:44 +010058struct neigh_cache *neigh_cache_alloc(void *ctx, unsigned int keep_time_sec);
59void neigh_cache_set_keep_time_interval(struct neigh_cache *cache, unsigned int keep_time_sec);
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010060struct neigh_cache_entry *neigh_cache_add(struct neigh_cache *cache,
61 const struct neigh_cache_entry_key *key,
62 const struct osmo_cell_global_id_ps *value);
63struct neigh_cache_entry *neigh_cache_lookup_entry(struct neigh_cache *cache,
64 const struct neigh_cache_entry_key *key);
65const struct osmo_cell_global_id_ps *neigh_cache_lookup_value(struct neigh_cache *cache,
66 const struct neigh_cache_entry_key *key);
67void neigh_cache_free(struct neigh_cache *cache);
68
69
70////////////////////
71// SI CACHE
72///////////////////
73
74/* CGI-PS-> SI cache */
75struct si_cache {
76 struct llist_head list; /* list of si_cache_entry items */
77 struct osmo_timer_list cleanup_timer; /* Timer removing too-old entries */
78 struct timespec keep_time_intval;
79};
80
81struct si_cache_value {
82 uint8_t si_buf[BSSGP_RIM_PSI_LEN * 127]; /* 3GPP TS 48.018 11.3.63.2.1 */
83 size_t si_len;
84 bool type_psi;
85};
86
87struct si_cache_entry {
88 struct llist_head list; /* to be included in si_cache->list */
89 struct timespec update_ts;
90 struct osmo_cell_global_id_ps key;
91 struct si_cache_value value;
92};
93
Pau Espin Pedrolab7159f2021-01-26 17:51:44 +010094struct si_cache *si_cache_alloc(void *ctx, unsigned int keep_time_sec);
95void si_cache_set_keep_time_interval(struct si_cache *cache, unsigned int keep_time_sec);
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010096struct si_cache_entry *si_cache_add(struct si_cache *cache,
97 const struct osmo_cell_global_id_ps *key,
98 const struct si_cache_value *value);
99struct si_cache_entry *si_cache_lookup_entry(struct si_cache *cache,
100 const struct osmo_cell_global_id_ps *key);
101const struct si_cache_value *si_cache_lookup_value(struct si_cache *cache,
102 const struct osmo_cell_global_id_ps *key);
103void si_cache_free(struct si_cache *cache);