blob: e1e3688fe4754eec4c14812aeadf313f81a0aea4 [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
Max6dc90b82018-02-19 17:17:28 +010043/*
44 * PDCH instance
45 */
46struct gprs_rlcmac_pdch {
47#ifdef __cplusplus
48 struct gprs_rlcmac_paging *dequeue_paging();
49 struct msgb *packet_paging_request();
50
Neels Hofmeyr59fc0bd2020-08-21 16:21:23 +020051 bool add_paging(uint8_t chan_needed, const struct osmo_mobile_identity *mi);
Max6dc90b82018-02-19 17:17:28 +010052
53 void free_resources();
54
55 bool is_enabled() const;
56
57 void enable();
58 void disable();
59
60 /* dispatching of messages */
61 int rcv_block(uint8_t *data, uint8_t len, uint32_t fn,
62 struct pcu_l1_meas *meas);
63 int rcv_block_gprs(uint8_t *data, uint8_t data_len, uint32_t fn,
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020064 struct pcu_l1_meas *meas, enum CodingScheme cs);
Max6dc90b82018-02-19 17:17:28 +010065 int rcv_data_block(uint8_t *data, uint8_t data_len, uint32_t fn,
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +020066 struct pcu_l1_meas *meas, enum CodingScheme cs);
Max6dc90b82018-02-19 17:17:28 +010067
68 gprs_rlcmac_bts *bts_data() const;
69 BTS *bts() const;
70 uint8_t trx_no() const;
71
72 struct gprs_rlcmac_ul_tbf *ul_tbf_by_tfi(uint8_t tfi);
73 struct gprs_rlcmac_dl_tbf *dl_tbf_by_tfi(uint8_t tfi);
74
75 void attach_tbf(gprs_rlcmac_tbf *tbf);
76 void detach_tbf(gprs_rlcmac_tbf *tbf);
77
78 unsigned num_tbfs(enum gprs_rlcmac_tbf_direction dir) const;
79
80 void reserve(enum gprs_rlcmac_tbf_direction dir);
81 void unreserve(enum gprs_rlcmac_tbf_direction dir);
82 unsigned num_reserved(enum gprs_rlcmac_tbf_direction dir) const;
83
84 uint8_t assigned_usf() const;
85 uint32_t assigned_tfi(enum gprs_rlcmac_tbf_direction dir) const;
86#endif
87
88 uint8_t m_is_enabled; /* TS is enabled */
89 uint8_t tsc; /* TSC of this slot */
90 uint8_t next_ul_tfi; /* next uplink TBF/TFI to schedule (0..31) */
91 uint8_t next_dl_tfi; /* next downlink TBF/TFI to schedule (0..31) */
92 uint8_t next_ctrl_prio; /* next kind of ctrl message to schedule */
93 struct llist_head paging_list; /* list of paging messages */
94 uint32_t last_rts_fn; /* store last frame number of RTS */
95
Vadim Yanitskiybd0dac32019-10-05 21:57:14 +070096 /* PTCCH (Packet Timing Advance Control Channel) */
97 uint8_t ptcch_msg[GSM_MACBLOCK_LEN]; /* 'ready to use' PTCCH/D message */
98#ifdef __cplusplus
99 /* Initialize the PTCCH/D message */
100 void init_ptcch_msg(void);
101 /* Obtain an unused TA Index for a TBF */
102 uint8_t reserve_tai(uint8_t ta);
103 /* Mark a given TA Index as free, so it can be used again */
104 void release_tai(uint8_t tai);
105 /* Update the actual Timing Advance value for a given TA Index */
106 void update_ta(uint8_t tai, uint8_t ta);
107#endif
108
Max6dc90b82018-02-19 17:17:28 +0100109 /* back pointers */
110 struct gprs_rlcmac_trx *trx;
111 uint8_t ts_no;
112
113#ifdef __cplusplus
114private:
Pau Espin Pedrole13cdc52019-09-25 13:46:14 +0200115 int rcv_control_block(const uint8_t *data, uint8_t data_len, uint32_t fn,
Pau Espin Pedrol2ae83372020-05-18 11:35:35 +0200116 struct pcu_l1_meas *meas, enum CodingScheme cs);
Max6dc90b82018-02-19 17:17:28 +0100117
118 void rcv_control_ack(Packet_Control_Acknowledgement_t *, uint32_t fn);
Pau Espin Pedrole13cdc52019-09-25 13:46:14 +0200119 void rcv_control_dl_ack_nack(Packet_Downlink_Ack_Nack_t *, uint32_t fn, struct pcu_l1_meas *meas);
120 void rcv_control_egprs_dl_ack_nack(EGPRS_PD_AckNack_t *, uint32_t fn, struct pcu_l1_meas *meas);
121 void rcv_resource_request(Packet_Resource_Request_t *t, uint32_t fn, struct pcu_l1_meas *meas);
Max6dc90b82018-02-19 17:17:28 +0100122 void rcv_measurement_report(Packet_Measurement_Report_t *t, uint32_t fn);
123 gprs_rlcmac_tbf *tbf_from_list_by_tfi(
124 LListHead<gprs_rlcmac_tbf> *tbf_list, uint8_t tfi,
125 enum gprs_rlcmac_tbf_direction dir);
126 gprs_rlcmac_tbf *tbf_by_tfi(uint8_t tfi,
127 enum gprs_rlcmac_tbf_direction dir);
128#endif
129
130 uint8_t m_num_tbfs[2];
131 uint8_t m_num_reserved[2];
132 uint8_t m_assigned_usf; /* bit set */
133 uint32_t m_assigned_tfi[2]; /* bit set */
134 struct gprs_rlcmac_tbf *m_tbfs[2][32];
135};
136
137#ifdef __cplusplus
138
139inline unsigned gprs_rlcmac_pdch::num_tbfs(enum gprs_rlcmac_tbf_direction dir) const
140{
141 return m_num_tbfs[dir];
142}
143
144inline unsigned gprs_rlcmac_pdch::num_reserved(
145 enum gprs_rlcmac_tbf_direction dir) const
146{
147 return gprs_rlcmac_pdch::m_num_reserved[dir];
148}
149
150inline uint8_t gprs_rlcmac_pdch::assigned_usf() const
151{
152 return m_assigned_usf;
153}
154
155inline uint32_t gprs_rlcmac_pdch::assigned_tfi(
156 enum gprs_rlcmac_tbf_direction dir) const
157{
158 return m_assigned_tfi[dir];
159}
160
161inline bool gprs_rlcmac_pdch::is_enabled() const
162{
163 return m_is_enabled;
164}
165
166#endif /* __cplusplus */