blob: 9405606923004f3e2bbecef7e9792114488da12a [file] [log] [blame]
Max6dc90b82018-02-19 17:17:28 +01001/* pdch.h
2 *
3 * Copyright (C) 2012 Ivan Klyuchnikov
4 * Copyright (C) 2013 by Holger Hans Peter Freyther
5 * Copyright (C) 2018 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
20 */
21
22#pragma once
23
Pau Espin Pedrol95e22662021-02-25 17:49:30 +010024#include <inttypes.h>
25
Max6dc90b82018-02-19 17:17:28 +010026#ifdef __cplusplus
27extern "C" {
28#include <osmocom/core/linuxlist.h>
Pau Espin Pedrolb2653fe2020-03-26 15:14:01 +010029#include "gsm_rlcmac.h"
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020030#include "coding_scheme.h"
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +010031#include "pdch_ul_controller.h"
Max6dc90b82018-02-19 17:17:28 +010032}
Max6dc90b82018-02-19 17:17:28 +010033#endif
34
35#include <tbf.h>
36
37#include <stdint.h>
38
Vadim Yanitskiybd0dac32019-10-05 21:57:14 +070039/* PTCCH (Packet Timing Advance Control Channel) */
40#define PTCCH_TAI_FREE 0x7f /*!< Special value for unused TA Indexes */
41#define PTCCH_TAI_NUM 16 /*!< Number of PTCCH/U slots and thus TA Indexes */
42#define PTCCH_PADDING 0x2b /*!< PTCCH/D messages need to be padded to 23 octets */
43
Pau Espin Pedrol22862882020-11-16 17:35:10 +010044#define USF_UNUSED 0x07
45/* 3GPP TS 05.08 version 8.23.0 "10.2.2 BTS output power". 360 ms */
46#define MS_RESYNC_NUM_FRAMES 18
47
Max6dc90b82018-02-19 17:17:28 +010048/*
49 * PDCH instance
50 */
51struct gprs_rlcmac_pdch {
52#ifdef __cplusplus
53 struct gprs_rlcmac_paging *dequeue_paging();
54 struct msgb *packet_paging_request();
55
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +020056 bool add_paging(uint8_t chan_needed, const struct osmo_mobile_identity *mi);
Max6dc90b82018-02-19 17:17:28 +010057
Max6dc90b82018-02-19 17:17:28 +010058 bool is_enabled() const;
59
60 void enable();
61 void disable();
62
63 /* dispatching of messages */
64 int rcv_block(uint8_t *data, uint8_t len, uint32_t fn,
65 struct pcu_l1_meas *meas);
66 int rcv_block_gprs(uint8_t *data, uint8_t data_len, uint32_t fn,
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020067 struct pcu_l1_meas *meas, enum CodingScheme cs);
Max6dc90b82018-02-19 17:17:28 +010068 int rcv_data_block(uint8_t *data, uint8_t data_len, uint32_t fn,
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020069 struct pcu_l1_meas *meas, enum CodingScheme cs);
Max6dc90b82018-02-19 17:17:28 +010070
Pau Espin Pedrol2182e622021-01-14 16:48:38 +010071 struct gprs_rlcmac_bts *bts() const;
Max6dc90b82018-02-19 17:17:28 +010072 uint8_t trx_no() const;
73
74 struct gprs_rlcmac_ul_tbf *ul_tbf_by_tfi(uint8_t tfi);
75 struct gprs_rlcmac_dl_tbf *dl_tbf_by_tfi(uint8_t tfi);
76
77 void attach_tbf(gprs_rlcmac_tbf *tbf);
78 void detach_tbf(gprs_rlcmac_tbf *tbf);
79
80 unsigned num_tbfs(enum gprs_rlcmac_tbf_direction dir) const;
Oliver Smith402451b2021-09-08 09:33:24 +020081 void num_tbfs_update(gprs_rlcmac_tbf *tbf, bool is_attach);
Max6dc90b82018-02-19 17:17:28 +010082
83 void reserve(enum gprs_rlcmac_tbf_direction dir);
84 void unreserve(enum gprs_rlcmac_tbf_direction dir);
85 unsigned num_reserved(enum gprs_rlcmac_tbf_direction dir) const;
86
87 uint8_t assigned_usf() const;
88 uint32_t assigned_tfi(enum gprs_rlcmac_tbf_direction dir) const;
Pau Espin Pedrol22862882020-11-16 17:35:10 +010089
90 bool has_gprs_only_tbf_attached() const;
Max6dc90b82018-02-19 17:17:28 +010091#endif
92
93 uint8_t m_is_enabled; /* TS is enabled */
94 uint8_t tsc; /* TSC of this slot */
95 uint8_t next_ul_tfi; /* next uplink TBF/TFI to schedule (0..31) */
96 uint8_t next_dl_tfi; /* next downlink TBF/TFI to schedule (0..31) */
97 uint8_t next_ctrl_prio; /* next kind of ctrl message to schedule */
98 struct llist_head paging_list; /* list of paging messages */
99 uint32_t last_rts_fn; /* store last frame number of RTS */
Pau Espin Pedrol22862882020-11-16 17:35:10 +0100100 /* store number of contiguous frame number where a DL block was transmitted which can be decoded by GPRS-only MS */
101 uint32_t fn_without_cs14;
Max6dc90b82018-02-19 17:17:28 +0100102
Vadim Yanitskiybd0dac32019-10-05 21:57:14 +0700103 /* PTCCH (Packet Timing Advance Control Channel) */
104 uint8_t ptcch_msg[GSM_MACBLOCK_LEN]; /* 'ready to use' PTCCH/D message */
105#ifdef __cplusplus
Vadim Yanitskiybd0dac32019-10-05 21:57:14 +0700106 /* Obtain an unused TA Index for a TBF */
107 uint8_t reserve_tai(uint8_t ta);
108 /* Mark a given TA Index as free, so it can be used again */
109 void release_tai(uint8_t tai);
110 /* Update the actual Timing Advance value for a given TA Index */
111 void update_ta(uint8_t tai, uint8_t ta);
112#endif
113
Vadim Yanitskiy542e3882020-07-19 00:47:20 +0700114 /* Frequency hopping parameters */
115 struct {
116 bool enabled;
117 /* 3GPP TS 45.002 HSN / MAIO (6 bit each) */
118 uint8_t hsn;
119 uint8_t maio;
120 /* 3GPP TS 44.018, 10.5.2.21 "Mobile Allocation" */
121 uint8_t ma_oct_len;
122 uint8_t ma_bit_len;
123 uint8_t ma[8];
124 } fh;
125
Max6dc90b82018-02-19 17:17:28 +0100126 /* back pointers */
127 struct gprs_rlcmac_trx *trx;
128 uint8_t ts_no;
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +0100129 struct pdch_ulc *ulc;
Max6dc90b82018-02-19 17:17:28 +0100130
131#ifdef __cplusplus
132private:
Pau Espin Pedrole13cdc52019-09-25 13:46:14 +0200133 int rcv_control_block(const uint8_t *data, uint8_t data_len, uint32_t fn,
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +0200134 struct pcu_l1_meas *meas, enum CodingScheme cs);
Max6dc90b82018-02-19 17:17:28 +0100135
136 void rcv_control_ack(Packet_Control_Acknowledgement_t *, uint32_t fn);
Pau Espin Pedrole13cdc52019-09-25 13:46:14 +0200137 void rcv_control_dl_ack_nack(Packet_Downlink_Ack_Nack_t *, uint32_t fn, struct pcu_l1_meas *meas);
138 void rcv_control_egprs_dl_ack_nack(EGPRS_PD_AckNack_t *, uint32_t fn, struct pcu_l1_meas *meas);
139 void rcv_resource_request(Packet_Resource_Request_t *t, uint32_t fn, struct pcu_l1_meas *meas);
Max6dc90b82018-02-19 17:17:28 +0100140 void rcv_measurement_report(Packet_Measurement_Report_t *t, uint32_t fn);
Pau Espin Pedrolc0a250d2021-01-21 18:46:13 +0100141 void rcv_cell_change_notification(Packet_Cell_Change_Notification_t *, uint32_t fn, struct pcu_l1_meas *meas);
Max6dc90b82018-02-19 17:17:28 +0100142 gprs_rlcmac_tbf *tbf_from_list_by_tfi(
143 LListHead<gprs_rlcmac_tbf> *tbf_list, uint8_t tfi,
144 enum gprs_rlcmac_tbf_direction dir);
145 gprs_rlcmac_tbf *tbf_by_tfi(uint8_t tfi,
146 enum gprs_rlcmac_tbf_direction dir);
Pau Espin Pedrol4f67a9b2021-06-30 16:03:06 +0200147
148 void free_resources();
Max6dc90b82018-02-19 17:17:28 +0100149#endif
150
Oliver Smith402451b2021-09-08 09:33:24 +0200151 uint8_t m_num_tbfs_gprs[2];
152 uint8_t m_num_tbfs_egprs[2];
Max6dc90b82018-02-19 17:17:28 +0100153 uint8_t m_num_reserved[2];
154 uint8_t m_assigned_usf; /* bit set */
155 uint32_t m_assigned_tfi[2]; /* bit set */
156 struct gprs_rlcmac_tbf *m_tbfs[2][32];
157};
158
159#ifdef __cplusplus
160
161inline unsigned gprs_rlcmac_pdch::num_tbfs(enum gprs_rlcmac_tbf_direction dir) const
162{
Oliver Smith402451b2021-09-08 09:33:24 +0200163 return m_num_tbfs_gprs[dir] + m_num_tbfs_egprs[dir];
Max6dc90b82018-02-19 17:17:28 +0100164}
165
166inline unsigned gprs_rlcmac_pdch::num_reserved(
167 enum gprs_rlcmac_tbf_direction dir) const
168{
169 return gprs_rlcmac_pdch::m_num_reserved[dir];
170}
171
172inline uint8_t gprs_rlcmac_pdch::assigned_usf() const
173{
174 return m_assigned_usf;
175}
176
177inline uint32_t gprs_rlcmac_pdch::assigned_tfi(
178 enum gprs_rlcmac_tbf_direction dir) const
179{
180 return m_assigned_tfi[dir];
181}
182
183inline bool gprs_rlcmac_pdch::is_enabled() const
184{
185 return m_is_enabled;
186}
187
188#endif /* __cplusplus */
Pau Espin Pedrol906aafc2021-01-18 17:53:29 +0100189
190#ifdef __cplusplus
191extern "C" {
192#endif
Pau Espin Pedrol702ebee2021-03-08 14:15:54 +0100193void pdch_init(struct gprs_rlcmac_pdch *pdch, struct gprs_rlcmac_trx *trx, uint8_t ts_nr);
Pau Espin Pedrol906aafc2021-01-18 17:53:29 +0100194void pdch_free_all_tbf(struct gprs_rlcmac_pdch *pdch);
Pau Espin Pedrole91c4c72021-01-18 17:54:30 +0100195void pdch_disable(struct gprs_rlcmac_pdch *pdch);
Pau Espin Pedrol4f67a9b2021-06-30 16:03:06 +0200196bool pdch_is_enabled(const struct gprs_rlcmac_pdch *pdch);
Pau Espin Pedrol906aafc2021-01-18 17:53:29 +0100197#ifdef __cplusplus
198}
Pau Espin Pedrol15c58ac2021-03-08 14:57:58 +0100199#endif
Pau Espin Pedrol95e22662021-02-25 17:49:30 +0100200
201#define LOGPDCH(pdch, category, level, fmt, args...) \
202 LOGP(category, level, "PDCH(bts=%" PRIu8 ",trx=%" PRIu8 ",ts=%" PRIu8 ") " fmt, \
203 (pdch)->trx->bts->nr, (pdch)->trx->trx_no, (pdch)->ts_no, \
204 ## args)