blob: 76706ab7e4bfb95fb60d72bc9c1ed7a8238ae4e5 [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.
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010015 */
16#pragma once
17
18#include <stdint.h>
19#include <inttypes.h>
20
21#include <osmocom/core/linuxlist.h>
22#include <osmocom/core/timer.h>
23
24#include <osmocom/gsm/gsm23003.h>
25#include <osmocom/gprs/gprs_bssgp_rim.h>
26
27////////////////////
28// NEIGH CACHE
29///////////////////
30
31/* ARFC+BSIC -> CGI PS cache */
32struct neigh_cache {
33 struct llist_head list; /* list of neigh_cache_entry items */
34 struct osmo_timer_list cleanup_timer; /* Timer removing too-old entries */
35 struct timespec keep_time_intval;
36};
37
38struct neigh_cache_entry_key {
39 uint16_t local_lac;
40 uint16_t local_ci;
41 uint16_t tgt_arfcn;
42 uint8_t tgt_bsic;
43};
44#define NEIGH_CACHE_ENTRY_KEY_FMT "%" PRIu16 "-%" PRIu16 "-%" PRIu16 "-%" PRIu8
45#define NEIGH_CACHE_ENTRY_KEY_ARGS(key) (key)->local_lac, (key)->local_ci, (key)->tgt_arfcn, (key)->tgt_bsic
46
Pau Espin Pedrol069a6372021-02-10 17:33:13 +010047static inline bool neigh_cache_entry_key_eq(const struct neigh_cache_entry_key *a,
48 const struct neigh_cache_entry_key *b)
49{
50 return a->local_lac == b->local_lac &&
51 a->local_ci == b->local_ci &&
52 a->tgt_arfcn == b->tgt_arfcn &&
53 a->tgt_bsic == b->tgt_bsic;
54}
55
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010056struct neigh_cache_entry {
57 struct llist_head list; /* to be included in neigh_cache->list */
58 struct timespec update_ts;
59 struct neigh_cache_entry_key key;
60 struct osmo_cell_global_id_ps value;
61};
62
Pau Espin Pedrolab7159f2021-01-26 17:51:44 +010063struct neigh_cache *neigh_cache_alloc(void *ctx, unsigned int keep_time_sec);
64void neigh_cache_set_keep_time_interval(struct neigh_cache *cache, unsigned int keep_time_sec);
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +010065struct neigh_cache_entry *neigh_cache_add(struct neigh_cache *cache,
66 const struct neigh_cache_entry_key *key,
67 const struct osmo_cell_global_id_ps *value);
68struct neigh_cache_entry *neigh_cache_lookup_entry(struct neigh_cache *cache,
69 const struct neigh_cache_entry_key *key);
70const struct osmo_cell_global_id_ps *neigh_cache_lookup_value(struct neigh_cache *cache,
71 const struct neigh_cache_entry_key *key);
72void neigh_cache_free(struct neigh_cache *cache);
73
74
75////////////////////
76// SI CACHE
77///////////////////
78
79/* CGI-PS-> SI cache */
80struct si_cache {
81 struct llist_head list; /* list of si_cache_entry items */
82 struct osmo_timer_list cleanup_timer; /* Timer removing too-old entries */
83 struct timespec keep_time_intval;
84};
85
86struct si_cache_value {
87 uint8_t si_buf[BSSGP_RIM_PSI_LEN * 127]; /* 3GPP TS 48.018 11.3.63.2.1 */
88 size_t si_len;
89 bool type_psi;
90};
91
92struct si_cache_entry {
93 struct llist_head list; /* to be included in si_cache->list */
94 struct timespec update_ts;
95 struct osmo_cell_global_id_ps key;
96 struct si_cache_value value;
97};
98
Pau Espin Pedrolab7159f2021-01-26 17:51:44 +010099struct si_cache *si_cache_alloc(void *ctx, unsigned int keep_time_sec);
100void si_cache_set_keep_time_interval(struct si_cache *cache, unsigned int keep_time_sec);
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +0100101struct si_cache_entry *si_cache_add(struct si_cache *cache,
102 const struct osmo_cell_global_id_ps *key,
103 const struct si_cache_value *value);
104struct si_cache_entry *si_cache_lookup_entry(struct si_cache *cache,
105 const struct osmo_cell_global_id_ps *key);
106const struct si_cache_value *si_cache_lookup_value(struct si_cache *cache,
107 const struct osmo_cell_global_id_ps *key);
108void si_cache_free(struct si_cache *cache);