Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 1 | /* 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 */ |
| 36 | struct 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 | |
| 42 | struct 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 | |
| 51 | struct 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 Pedrol | ab7159f | 2021-01-26 17:51:44 +0100 | [diff] [blame] | 58 | struct neigh_cache *neigh_cache_alloc(void *ctx, unsigned int keep_time_sec); |
| 59 | void neigh_cache_set_keep_time_interval(struct neigh_cache *cache, unsigned int keep_time_sec); |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 60 | struct 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); |
| 63 | struct neigh_cache_entry *neigh_cache_lookup_entry(struct neigh_cache *cache, |
| 64 | const struct neigh_cache_entry_key *key); |
| 65 | const struct osmo_cell_global_id_ps *neigh_cache_lookup_value(struct neigh_cache *cache, |
| 66 | const struct neigh_cache_entry_key *key); |
| 67 | void neigh_cache_free(struct neigh_cache *cache); |
| 68 | |
| 69 | |
| 70 | //////////////////// |
| 71 | // SI CACHE |
| 72 | /////////////////// |
| 73 | |
| 74 | /* CGI-PS-> SI cache */ |
| 75 | struct 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 | |
| 81 | struct 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 | |
| 87 | struct 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 Pedrol | ab7159f | 2021-01-26 17:51:44 +0100 | [diff] [blame] | 94 | struct si_cache *si_cache_alloc(void *ctx, unsigned int keep_time_sec); |
| 95 | void si_cache_set_keep_time_interval(struct si_cache *cache, unsigned int keep_time_sec); |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 96 | struct 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); |
| 99 | struct si_cache_entry *si_cache_lookup_entry(struct si_cache *cache, |
| 100 | const struct osmo_cell_global_id_ps *key); |
| 101 | const struct si_cache_value *si_cache_lookup_value(struct si_cache *cache, |
| 102 | const struct osmo_cell_global_id_ps *key); |
| 103 | void si_cache_free(struct si_cache *cache); |