blob: 907e6663f0b5ab6ace609c530424080aa27bf66e [file] [log] [blame]
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001/* gprs_bssgp_pcu.h
Ivan Kluchnikov5c2f9fb2012-02-05 02:27:17 +04002 *
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04003 * Copyright (C) 2012 Ivan Klyuchnikov
Holger Hans Peter Freytherc0f16442013-08-22 08:40:33 +02004 * Copyright (C) 2013 by Holger Hans Peter Freyther
Ivan Kluchnikov5c2f9fb2012-02-05 02:27:17 +04005 *
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 */
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040020
21#ifndef GPRS_BSSGP_PCU_H
22#define GPRS_BSSGP_PCU_H
23
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +010024#ifdef __cplusplus
Ivan Kluchnikov5c2f9fb2012-02-05 02:27:17 +040025extern "C" {
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +010026#endif
Ivan Kluchnikov5c2f9fb2012-02-05 02:27:17 +040027#include <osmocom/core/talloc.h>
28#include <osmocom/core/rate_ctr.h>
Ivan Kluchnikova9f1ff22012-05-24 22:25:06 +040029#include <osmocom/core/logging.h>
Harald Welted6790092012-06-18 12:21:03 +080030#include <osmocom/core/signal.h>
Ivan Kluchnikov5c2f9fb2012-02-05 02:27:17 +040031#include <osmocom/core/application.h>
Alexander Couzens290d9032020-09-16 21:52:02 +020032#include <osmocom/gprs/gprs_ns2.h>
Harald Welted6790092012-06-18 12:21:03 +080033#include <osmocom/gprs/gprs_bssgp.h>
Andreas Eversberg4b39dd12012-09-23 05:03:56 +020034#include <osmocom/gprs/gprs_bssgp_bss.h>
Harald Welted6790092012-06-18 12:21:03 +080035#include <osmocom/gprs/gprs_msgb.h>
Ivan Kluchnikov5c2f9fb2012-02-05 02:27:17 +040036
Ivan Kluchnikov5c2f9fb2012-02-05 02:27:17 +040037struct bssgp_bvc_ctx *btsctx_alloc(uint16_t bvci, uint16_t nsei);
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +010038
Ivan Kluchnikova9f1ff22012-05-24 22:25:06 +040039#include <gprs_debug.h>
Ivan Kluchnikov5c2f9fb2012-02-05 02:27:17 +040040
Pau Espin Pedrol1de68732020-03-11 14:04:52 +010041#include <time.h>
Pau Espin Pedrol8a35e642021-01-18 17:14:14 +010042#include <unistd.h>
Pau Espin Pedrol1de68732020-03-11 14:04:52 +010043
Andreas Eversberg4b39dd12012-09-23 05:03:56 +020044#define QOS_PROFILE 4
Ivan Kluchnikov3fa42b22012-06-04 19:07:25 +040045#define BSSGP_HDR_LEN 53
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +040046#define NS_HDR_LEN 4
Ivan Kluchnikovb172b1b2012-06-07 01:51:49 +040047#define IE_LLC_PDU 14
Ivan Kluchnikov5c2f9fb2012-02-05 02:27:17 +040048
Oliver Smith97839672021-07-05 11:11:42 +020049enum sgsn_counter_id {
50 SGSN_CTR_RX_PAGING_CS,
51 SGSN_CTR_RX_PAGING_PS,
52};
53
Holger Hans Peter Freythere8d9a5f2013-07-28 19:11:20 +020054struct gprs_bssgp_pcu {
Holger Hans Peter Freythere8d9a5f2013-07-28 19:11:20 +020055 struct bssgp_bvc_ctx *bctx;
56
57 struct gprs_rlcmac_bts *bts;
58
59 struct osmo_timer_list bvc_timer;
60
Oliver Smith97839672021-07-05 11:11:42 +020061 struct rate_ctr_group *ctrs;
62
Alexander Couzens5d376842021-02-22 01:45:17 +010063 /* state: is the NSVC unblocked? */
Holger Hans Peter Freythere8d9a5f2013-07-28 19:11:20 +020064 int nsvc_unblocked;
65
Alexander Couzens5d376842021-02-22 01:45:17 +010066 /* state: true if bvc signalling needs to be reseted or waiting for reset ack */
Holger Hans Peter Freythere8d9a5f2013-07-28 19:11:20 +020067 int bvc_sig_reset;
Alexander Couzens5d376842021-02-22 01:45:17 +010068 /* state: true if bvc ptp needs to be reseted or waiting for reset ack */
Holger Hans Peter Freythere8d9a5f2013-07-28 19:11:20 +020069 int bvc_reset;
Alexander Couzens5d376842021-02-22 01:45:17 +010070 /* state: true if bvc ptp is unblocked */
Holger Hans Peter Freythere8d9a5f2013-07-28 19:11:20 +020071 int bvc_unblocked;
Holger Hans Peter Freytherc0f16442013-08-22 08:40:33 +020072
Jacob Erlbeck6e4ccec2015-05-06 14:24:36 +020073 /* Flow control */
Pau Espin Pedrol1de68732020-03-11 14:04:52 +010074 struct timespec queue_delay_sum;
Jacob Erlbeck6e4ccec2015-05-06 14:24:36 +020075 unsigned queue_delay_count;
Jacob Erlbeck6eeb7c72015-05-06 15:26:08 +020076 uint8_t fc_tag;
Jacob Erlbeck2db0f082015-09-07 18:49:00 +020077 unsigned queue_frames_sent;
78 unsigned queue_bytes_recv;
79 unsigned queue_frames_recv;
Jacob Erlbeck6e4ccec2015-05-06 14:24:36 +020080
Holger Hans Peter Freytherc0f16442013-08-22 08:40:33 +020081 /** callbacks below */
82
83 /* The BSSGP has been unblocked */
84 void (*on_unblock_ack)(struct gprs_bssgp_pcu *pcu);
Holger Hans Peter Freyther416ce692013-08-22 08:44:04 +020085
86 /* When BSSGP data arrives. The msgb is not only for reference */
87 void (*on_dl_unit_data)(struct gprs_bssgp_pcu *pcu, struct msgb *msg,
88 struct tlv_parsed *tp);
Holger Hans Peter Freythere8d9a5f2013-07-28 19:11:20 +020089};
90
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +010091int gprs_gp_send_cb(void *ctx, struct msgb *msg);
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +010092int gprs_ns_prim_cb(struct osmo_prim_hdr *oph, void *ctx);
93void gprs_bssgp_update_queue_delay(const struct timespec *tv_recv,
94 const struct timespec *tv_now);
95void gprs_bssgp_update_frames_sent();
96void gprs_bssgp_update_bytes_received(unsigned bytes_recv, unsigned frames_recv);
97
Alexander Couzens290d9032020-09-16 21:52:02 +020098struct gprs_bssgp_pcu *gprs_bssgp_init(
99 struct gprs_rlcmac_bts *bts,
100 uint16_t nsei, uint16_t bvci,
101 uint16_t mcc, uint16_t mnc, bool mnc_3_digits,
Holger Hans Peter Freytherb67a8a32013-07-28 18:55:14 +0200102 uint16_t lac, uint16_t rac, uint16_t cell_id);
Andreas Eversbergbf5a0f62012-07-06 08:58:22 +0200103
Alexander Couzens94a367f2021-02-16 16:57:15 +0100104int gprs_ns_update_config(struct gprs_rlcmac_bts *bts, uint16_t nsei,
Alexander Couzens5bece2a2020-10-12 02:27:22 +0200105 const struct osmo_sockaddr *local,
106 const struct osmo_sockaddr *remote,
107 uint16_t *nsvci, uint16_t valid);
Alexander Couzenseb64d432019-05-25 03:10:51 +0200108
Alexander Couzens290d9032020-09-16 21:52:02 +0200109void gprs_bssgp_destroy(struct gprs_rlcmac_bts *bts);
Andreas Eversbergbf5a0f62012-07-06 08:58:22 +0200110
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100111#ifdef __cplusplus
112}
113#endif
Jacob Erlbeck6e4ccec2015-05-06 14:24:36 +0200114
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400115#endif // GPRS_BSSGP_PCU_H