blob: 7a544fe43c2e84233f6c8299d4e7a393dae5b165 [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
24#ifdef __cplusplus
25extern "C" {
26#include <osmocom/core/linuxlist.h>
Pau Espin Pedrolb2653fe2020-03-26 15:14:01 +010027#include "gsm_rlcmac.h"
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020028#include "coding_scheme.h"
Max6dc90b82018-02-19 17:17:28 +010029}
30
Max6dc90b82018-02-19 17:17:28 +010031#include <bts.h>
32#endif
33
34#include <tbf.h>
35
36#include <stdint.h>
37
Vadim Yanitskiybd0dac32019-10-05 21:57:14 +070038/* PTCCH (Packet Timing Advance Control Channel) */
39#define PTCCH_TAI_FREE 0x7f /*!< Special value for unused TA Indexes */
40#define PTCCH_TAI_NUM 16 /*!< Number of PTCCH/U slots and thus TA Indexes */
41#define PTCCH_PADDING 0x2b /*!< PTCCH/D messages need to be padded to 23 octets */
42
Pau Espin Pedrol22862882020-11-16 17:35:10 +010043#define USF_UNUSED 0x07
44/* 3GPP TS 05.08 version 8.23.0 "10.2.2 BTS output power". 360 ms */
45#define MS_RESYNC_NUM_FRAMES 18
46
Max6dc90b82018-02-19 17:17:28 +010047/*
48 * PDCH instance
49 */
50struct gprs_rlcmac_pdch {
51#ifdef __cplusplus
52 struct gprs_rlcmac_paging *dequeue_paging();
53 struct msgb *packet_paging_request();
54
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +020055 bool add_paging(uint8_t chan_needed, const struct osmo_mobile_identity *mi);
Max6dc90b82018-02-19 17:17:28 +010056
57 void free_resources();
58
59 bool is_enabled() const;
60
61 void enable();
62 void disable();
63
64 /* dispatching of messages */
65 int rcv_block(uint8_t *data, uint8_t len, uint32_t fn,
66 struct pcu_l1_meas *meas);
67 int rcv_block_gprs(uint8_t *data, uint8_t data_len, uint32_t fn,
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020068 struct pcu_l1_meas *meas, enum CodingScheme cs);
Max6dc90b82018-02-19 17:17:28 +010069 int rcv_data_block(uint8_t *data, uint8_t data_len, uint32_t fn,
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020070 struct pcu_l1_meas *meas, enum CodingScheme cs);
Max6dc90b82018-02-19 17:17:28 +010071
72 gprs_rlcmac_bts *bts_data() const;
Pau Espin Pedrol2182e622021-01-14 16:48:38 +010073 struct gprs_rlcmac_bts *bts() const;
Max6dc90b82018-02-19 17:17:28 +010074 uint8_t trx_no() const;
75
76 struct gprs_rlcmac_ul_tbf *ul_tbf_by_tfi(uint8_t tfi);
77 struct gprs_rlcmac_dl_tbf *dl_tbf_by_tfi(uint8_t tfi);
78
79 void attach_tbf(gprs_rlcmac_tbf *tbf);
80 void detach_tbf(gprs_rlcmac_tbf *tbf);
81
82 unsigned num_tbfs(enum gprs_rlcmac_tbf_direction dir) const;
83
84 void reserve(enum gprs_rlcmac_tbf_direction dir);
85 void unreserve(enum gprs_rlcmac_tbf_direction dir);
86 unsigned num_reserved(enum gprs_rlcmac_tbf_direction dir) const;
87
88 uint8_t assigned_usf() const;
89 uint32_t assigned_tfi(enum gprs_rlcmac_tbf_direction dir) const;
Pau Espin Pedrol22862882020-11-16 17:35:10 +010090
91 bool has_gprs_only_tbf_attached() const;
Max6dc90b82018-02-19 17:17:28 +010092#endif
93
94 uint8_t m_is_enabled; /* TS is enabled */
95 uint8_t tsc; /* TSC of this slot */
96 uint8_t next_ul_tfi; /* next uplink TBF/TFI to schedule (0..31) */
97 uint8_t next_dl_tfi; /* next downlink TBF/TFI to schedule (0..31) */
98 uint8_t next_ctrl_prio; /* next kind of ctrl message to schedule */
99 struct llist_head paging_list; /* list of paging messages */
100 uint32_t last_rts_fn; /* store last frame number of RTS */
Pau Espin Pedrol22862882020-11-16 17:35:10 +0100101 /* store number of contiguous frame number where a DL block was transmitted which can be decoded by GPRS-only MS */
102 uint32_t fn_without_cs14;
Max6dc90b82018-02-19 17:17:28 +0100103
Vadim Yanitskiybd0dac32019-10-05 21:57:14 +0700104 /* PTCCH (Packet Timing Advance Control Channel) */
105 uint8_t ptcch_msg[GSM_MACBLOCK_LEN]; /* 'ready to use' PTCCH/D message */
106#ifdef __cplusplus
107 /* Initialize the PTCCH/D message */
108 void init_ptcch_msg(void);
109 /* Obtain an unused TA Index for a TBF */
110 uint8_t reserve_tai(uint8_t ta);
111 /* Mark a given TA Index as free, so it can be used again */
112 void release_tai(uint8_t tai);
113 /* Update the actual Timing Advance value for a given TA Index */
114 void update_ta(uint8_t tai, uint8_t ta);
115#endif
116
Vadim Yanitskiy542e3882020-07-19 00:47:20 +0700117 /* Frequency hopping parameters */
118 struct {
119 bool enabled;
120 /* 3GPP TS 45.002 HSN / MAIO (6 bit each) */
121 uint8_t hsn;
122 uint8_t maio;
123 /* 3GPP TS 44.018, 10.5.2.21 "Mobile Allocation" */
124 uint8_t ma_oct_len;
125 uint8_t ma_bit_len;
126 uint8_t ma[8];
127 } fh;
128
Max6dc90b82018-02-19 17:17:28 +0100129 /* back pointers */
130 struct gprs_rlcmac_trx *trx;
131 uint8_t ts_no;
132
133#ifdef __cplusplus
134private:
Pau Espin Pedrole13cdc52019-09-25 13:46:14 +0200135 int rcv_control_block(const uint8_t *data, uint8_t data_len, uint32_t fn,
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +0200136 struct pcu_l1_meas *meas, enum CodingScheme cs);
Max6dc90b82018-02-19 17:17:28 +0100137
138 void rcv_control_ack(Packet_Control_Acknowledgement_t *, uint32_t fn);
Pau Espin Pedrole13cdc52019-09-25 13:46:14 +0200139 void rcv_control_dl_ack_nack(Packet_Downlink_Ack_Nack_t *, uint32_t fn, struct pcu_l1_meas *meas);
140 void rcv_control_egprs_dl_ack_nack(EGPRS_PD_AckNack_t *, uint32_t fn, struct pcu_l1_meas *meas);
141 void rcv_resource_request(Packet_Resource_Request_t *t, uint32_t fn, struct pcu_l1_meas *meas);
Max6dc90b82018-02-19 17:17:28 +0100142 void rcv_measurement_report(Packet_Measurement_Report_t *t, uint32_t fn);
143 gprs_rlcmac_tbf *tbf_from_list_by_tfi(
144 LListHead<gprs_rlcmac_tbf> *tbf_list, uint8_t tfi,
145 enum gprs_rlcmac_tbf_direction dir);
146 gprs_rlcmac_tbf *tbf_by_tfi(uint8_t tfi,
147 enum gprs_rlcmac_tbf_direction dir);
148#endif
149
150 uint8_t m_num_tbfs[2];
151 uint8_t m_num_reserved[2];
152 uint8_t m_assigned_usf; /* bit set */
153 uint32_t m_assigned_tfi[2]; /* bit set */
154 struct gprs_rlcmac_tbf *m_tbfs[2][32];
155};
156
157#ifdef __cplusplus
158
159inline unsigned gprs_rlcmac_pdch::num_tbfs(enum gprs_rlcmac_tbf_direction dir) const
160{
161 return m_num_tbfs[dir];
162}
163
164inline unsigned gprs_rlcmac_pdch::num_reserved(
165 enum gprs_rlcmac_tbf_direction dir) const
166{
167 return gprs_rlcmac_pdch::m_num_reserved[dir];
168}
169
170inline uint8_t gprs_rlcmac_pdch::assigned_usf() const
171{
172 return m_assigned_usf;
173}
174
175inline uint32_t gprs_rlcmac_pdch::assigned_tfi(
176 enum gprs_rlcmac_tbf_direction dir) const
177{
178 return m_assigned_tfi[dir];
179}
180
181inline bool gprs_rlcmac_pdch::is_enabled() const
182{
183 return m_is_enabled;
184}
185
186#endif /* __cplusplus */