blob: 90260cd3aebf88f792af5244930747f157c2d540 [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
Pau Espin Pedrol069a6372021-02-10 17:33:13 +010051static inline bool neigh_cache_entry_key_eq(const struct neigh_cache_entry_key *a,
52 const struct neigh_cache_entry_key *b)
53{
54 return a->local_lac == b->local_lac &&
55 a->local_ci == b->local_ci &&
56 a->tgt_arfcn == b->tgt_arfcn &&
57 a->tgt_bsic == b->tgt_bsic;
58}
59
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010060struct neigh_cache_entry {
61 struct llist_head list; /* to be included in neigh_cache->list */
62 struct timespec update_ts;
63 struct neigh_cache_entry_key key;
64 struct osmo_cell_global_id_ps value;
65};
66
Pau Espin Pedrolab7159f2021-01-26 17:51:44 +010067struct neigh_cache *neigh_cache_alloc(void *ctx, unsigned int keep_time_sec);
68void neigh_cache_set_keep_time_interval(struct neigh_cache *cache, unsigned int keep_time_sec);
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010069struct neigh_cache_entry *neigh_cache_add(struct neigh_cache *cache,
70 const struct neigh_cache_entry_key *key,
71 const struct osmo_cell_global_id_ps *value);
72struct neigh_cache_entry *neigh_cache_lookup_entry(struct neigh_cache *cache,
73 const struct neigh_cache_entry_key *key);
74const struct osmo_cell_global_id_ps *neigh_cache_lookup_value(struct neigh_cache *cache,
75 const struct neigh_cache_entry_key *key);
76void neigh_cache_free(struct neigh_cache *cache);
77
78
79////////////////////
80// SI CACHE
81///////////////////
82
83/* CGI-PS-> SI cache */
84struct si_cache {
85 struct llist_head list; /* list of si_cache_entry items */
86 struct osmo_timer_list cleanup_timer; /* Timer removing too-old entries */
87 struct timespec keep_time_intval;
88};
89
90struct si_cache_value {
91 uint8_t si_buf[BSSGP_RIM_PSI_LEN * 127]; /* 3GPP TS 48.018 11.3.63.2.1 */
92 size_t si_len;
93 bool type_psi;
94};
95
96struct si_cache_entry {
97 struct llist_head list; /* to be included in si_cache->list */
98 struct timespec update_ts;
99 struct osmo_cell_global_id_ps key;
100 struct si_cache_value value;
101};
102
Pau Espin Pedrolab7159f2021-01-26 17:51:44 +0100103struct si_cache *si_cache_alloc(void *ctx, unsigned int keep_time_sec);
104void si_cache_set_keep_time_interval(struct si_cache *cache, unsigned int keep_time_sec);
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +0100105struct si_cache_entry *si_cache_add(struct si_cache *cache,
106 const struct osmo_cell_global_id_ps *key,
107 const struct si_cache_value *value);
108struct si_cache_entry *si_cache_lookup_entry(struct si_cache *cache,
109 const struct osmo_cell_global_id_ps *key);
110const struct si_cache_value *si_cache_lookup_value(struct si_cache *cache,
111 const struct osmo_cell_global_id_ps *key);
112void si_cache_free(struct si_cache *cache);