Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 1 | /* 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. |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #pragma once |
| 19 | |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 20 | #include <inttypes.h> |
| 21 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 22 | #ifdef __cplusplus |
| 23 | extern "C" { |
| 24 | #include <osmocom/core/linuxlist.h> |
Pau Espin Pedrol | b2653fe | 2020-03-26 15:14:01 +0100 | [diff] [blame] | 25 | #include "gsm_rlcmac.h" |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 26 | #include "coding_scheme.h" |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 27 | #include "pdch_ul_controller.h" |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 28 | } |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 29 | #endif |
| 30 | |
| 31 | #include <tbf.h> |
| 32 | |
| 33 | #include <stdint.h> |
| 34 | |
Vadim Yanitskiy | bd0dac3 | 2019-10-05 21:57:14 +0700 | [diff] [blame] | 35 | /* PTCCH (Packet Timing Advance Control Channel) */ |
| 36 | #define PTCCH_TAI_FREE 0x7f /*!< Special value for unused TA Indexes */ |
| 37 | #define PTCCH_TAI_NUM 16 /*!< Number of PTCCH/U slots and thus TA Indexes */ |
| 38 | #define PTCCH_PADDING 0x2b /*!< PTCCH/D messages need to be padded to 23 octets */ |
| 39 | |
Pau Espin Pedrol | 2286288 | 2020-11-16 17:35:10 +0100 | [diff] [blame] | 40 | #define USF_UNUSED 0x07 |
| 41 | /* 3GPP TS 05.08 version 8.23.0 "10.2.2 BTS output power". 360 ms */ |
| 42 | #define MS_RESYNC_NUM_FRAMES 18 |
| 43 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 44 | /* |
| 45 | * PDCH instance |
| 46 | */ |
| 47 | struct gprs_rlcmac_pdch { |
| 48 | #ifdef __cplusplus |
| 49 | struct gprs_rlcmac_paging *dequeue_paging(); |
| 50 | struct msgb *packet_paging_request(); |
| 51 | |
Neels Hofmeyr | 59fc0bd | 2020-08-21 16:21:23 +0200 | [diff] [blame] | 52 | bool add_paging(uint8_t chan_needed, const struct osmo_mobile_identity *mi); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 53 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 54 | bool is_enabled() const; |
| 55 | |
| 56 | void enable(); |
| 57 | void disable(); |
| 58 | |
| 59 | /* dispatching of messages */ |
| 60 | int rcv_block(uint8_t *data, uint8_t len, uint32_t fn, |
| 61 | struct pcu_l1_meas *meas); |
| 62 | int rcv_block_gprs(uint8_t *data, uint8_t data_len, uint32_t fn, |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 63 | struct pcu_l1_meas *meas, enum CodingScheme cs); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 64 | int rcv_data_block(uint8_t *data, uint8_t data_len, uint32_t fn, |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 65 | struct pcu_l1_meas *meas, enum CodingScheme cs); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 66 | |
Pau Espin Pedrol | 2182e62 | 2021-01-14 16:48:38 +0100 | [diff] [blame] | 67 | struct gprs_rlcmac_bts *bts() const; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 68 | uint8_t trx_no() const; |
| 69 | |
| 70 | struct gprs_rlcmac_ul_tbf *ul_tbf_by_tfi(uint8_t tfi); |
| 71 | struct gprs_rlcmac_dl_tbf *dl_tbf_by_tfi(uint8_t tfi); |
| 72 | |
| 73 | void attach_tbf(gprs_rlcmac_tbf *tbf); |
| 74 | void detach_tbf(gprs_rlcmac_tbf *tbf); |
| 75 | |
| 76 | unsigned num_tbfs(enum gprs_rlcmac_tbf_direction dir) const; |
Oliver Smith | 402451b | 2021-09-08 09:33:24 +0200 | [diff] [blame] | 77 | void num_tbfs_update(gprs_rlcmac_tbf *tbf, bool is_attach); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 78 | |
| 79 | void reserve(enum gprs_rlcmac_tbf_direction dir); |
| 80 | void unreserve(enum gprs_rlcmac_tbf_direction dir); |
| 81 | unsigned num_reserved(enum gprs_rlcmac_tbf_direction dir) const; |
| 82 | |
| 83 | uint8_t assigned_usf() const; |
| 84 | uint32_t assigned_tfi(enum gprs_rlcmac_tbf_direction dir) const; |
Pau Espin Pedrol | 2286288 | 2020-11-16 17:35:10 +0100 | [diff] [blame] | 85 | |
| 86 | bool has_gprs_only_tbf_attached() const; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 87 | #endif |
| 88 | |
| 89 | uint8_t m_is_enabled; /* TS is enabled */ |
| 90 | uint8_t tsc; /* TSC of this slot */ |
| 91 | uint8_t next_ul_tfi; /* next uplink TBF/TFI to schedule (0..31) */ |
| 92 | uint8_t next_dl_tfi; /* next downlink TBF/TFI to schedule (0..31) */ |
| 93 | uint8_t next_ctrl_prio; /* next kind of ctrl message to schedule */ |
| 94 | struct llist_head paging_list; /* list of paging messages */ |
| 95 | uint32_t last_rts_fn; /* store last frame number of RTS */ |
Pau Espin Pedrol | 2286288 | 2020-11-16 17:35:10 +0100 | [diff] [blame] | 96 | /* store number of contiguous frame number where a DL block was transmitted which can be decoded by GPRS-only MS */ |
| 97 | uint32_t fn_without_cs14; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 98 | |
Vadim Yanitskiy | bd0dac3 | 2019-10-05 21:57:14 +0700 | [diff] [blame] | 99 | /* PTCCH (Packet Timing Advance Control Channel) */ |
| 100 | uint8_t ptcch_msg[GSM_MACBLOCK_LEN]; /* 'ready to use' PTCCH/D message */ |
| 101 | #ifdef __cplusplus |
Vadim Yanitskiy | bd0dac3 | 2019-10-05 21:57:14 +0700 | [diff] [blame] | 102 | /* Obtain an unused TA Index for a TBF */ |
| 103 | uint8_t reserve_tai(uint8_t ta); |
| 104 | /* Mark a given TA Index as free, so it can be used again */ |
| 105 | void release_tai(uint8_t tai); |
| 106 | /* Update the actual Timing Advance value for a given TA Index */ |
| 107 | void update_ta(uint8_t tai, uint8_t ta); |
| 108 | #endif |
| 109 | |
Vadim Yanitskiy | 542e388 | 2020-07-19 00:47:20 +0700 | [diff] [blame] | 110 | /* Frequency hopping parameters */ |
| 111 | struct { |
| 112 | bool enabled; |
| 113 | /* 3GPP TS 45.002 HSN / MAIO (6 bit each) */ |
| 114 | uint8_t hsn; |
| 115 | uint8_t maio; |
| 116 | /* 3GPP TS 44.018, 10.5.2.21 "Mobile Allocation" */ |
| 117 | uint8_t ma_oct_len; |
| 118 | uint8_t ma_bit_len; |
| 119 | uint8_t ma[8]; |
| 120 | } fh; |
| 121 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 122 | /* back pointers */ |
| 123 | struct gprs_rlcmac_trx *trx; |
| 124 | uint8_t ts_no; |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 125 | struct pdch_ulc *ulc; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 126 | |
| 127 | #ifdef __cplusplus |
| 128 | private: |
Pau Espin Pedrol | e13cdc5 | 2019-09-25 13:46:14 +0200 | [diff] [blame] | 129 | int rcv_control_block(const uint8_t *data, uint8_t data_len, uint32_t fn, |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 130 | struct pcu_l1_meas *meas, enum CodingScheme cs); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 131 | |
| 132 | void rcv_control_ack(Packet_Control_Acknowledgement_t *, uint32_t fn); |
Pau Espin Pedrol | e13cdc5 | 2019-09-25 13:46:14 +0200 | [diff] [blame] | 133 | void rcv_control_dl_ack_nack(Packet_Downlink_Ack_Nack_t *, uint32_t fn, struct pcu_l1_meas *meas); |
| 134 | void rcv_control_egprs_dl_ack_nack(EGPRS_PD_AckNack_t *, uint32_t fn, struct pcu_l1_meas *meas); |
| 135 | void rcv_resource_request(Packet_Resource_Request_t *t, uint32_t fn, struct pcu_l1_meas *meas); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 136 | void rcv_measurement_report(Packet_Measurement_Report_t *t, uint32_t fn); |
Pau Espin Pedrol | c0a250d | 2021-01-21 18:46:13 +0100 | [diff] [blame] | 137 | void rcv_cell_change_notification(Packet_Cell_Change_Notification_t *, uint32_t fn, struct pcu_l1_meas *meas); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 138 | gprs_rlcmac_tbf *tbf_from_list_by_tfi( |
| 139 | LListHead<gprs_rlcmac_tbf> *tbf_list, uint8_t tfi, |
| 140 | enum gprs_rlcmac_tbf_direction dir); |
| 141 | gprs_rlcmac_tbf *tbf_by_tfi(uint8_t tfi, |
| 142 | enum gprs_rlcmac_tbf_direction dir); |
Pau Espin Pedrol | 4f67a9b | 2021-06-30 16:03:06 +0200 | [diff] [blame] | 143 | |
| 144 | void free_resources(); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 145 | #endif |
| 146 | |
Oliver Smith | 402451b | 2021-09-08 09:33:24 +0200 | [diff] [blame] | 147 | uint8_t m_num_tbfs_gprs[2]; |
| 148 | uint8_t m_num_tbfs_egprs[2]; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 149 | uint8_t m_num_reserved[2]; |
| 150 | uint8_t m_assigned_usf; /* bit set */ |
| 151 | uint32_t m_assigned_tfi[2]; /* bit set */ |
| 152 | struct gprs_rlcmac_tbf *m_tbfs[2][32]; |
| 153 | }; |
| 154 | |
| 155 | #ifdef __cplusplus |
| 156 | |
| 157 | inline unsigned gprs_rlcmac_pdch::num_tbfs(enum gprs_rlcmac_tbf_direction dir) const |
| 158 | { |
Oliver Smith | 402451b | 2021-09-08 09:33:24 +0200 | [diff] [blame] | 159 | return m_num_tbfs_gprs[dir] + m_num_tbfs_egprs[dir]; |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | inline unsigned gprs_rlcmac_pdch::num_reserved( |
| 163 | enum gprs_rlcmac_tbf_direction dir) const |
| 164 | { |
| 165 | return gprs_rlcmac_pdch::m_num_reserved[dir]; |
| 166 | } |
| 167 | |
| 168 | inline uint8_t gprs_rlcmac_pdch::assigned_usf() const |
| 169 | { |
| 170 | return m_assigned_usf; |
| 171 | } |
| 172 | |
| 173 | inline uint32_t gprs_rlcmac_pdch::assigned_tfi( |
| 174 | enum gprs_rlcmac_tbf_direction dir) const |
| 175 | { |
| 176 | return m_assigned_tfi[dir]; |
| 177 | } |
| 178 | |
| 179 | inline bool gprs_rlcmac_pdch::is_enabled() const |
| 180 | { |
| 181 | return m_is_enabled; |
| 182 | } |
| 183 | |
| 184 | #endif /* __cplusplus */ |
Pau Espin Pedrol | 906aafc | 2021-01-18 17:53:29 +0100 | [diff] [blame] | 185 | |
| 186 | #ifdef __cplusplus |
| 187 | extern "C" { |
| 188 | #endif |
Pau Espin Pedrol | 702ebee | 2021-03-08 14:15:54 +0100 | [diff] [blame] | 189 | void pdch_init(struct gprs_rlcmac_pdch *pdch, struct gprs_rlcmac_trx *trx, uint8_t ts_nr); |
Pau Espin Pedrol | 906aafc | 2021-01-18 17:53:29 +0100 | [diff] [blame] | 190 | void pdch_free_all_tbf(struct gprs_rlcmac_pdch *pdch); |
Pau Espin Pedrol | e91c4c7 | 2021-01-18 17:54:30 +0100 | [diff] [blame] | 191 | void pdch_disable(struct gprs_rlcmac_pdch *pdch); |
Pau Espin Pedrol | 4f67a9b | 2021-06-30 16:03:06 +0200 | [diff] [blame] | 192 | bool pdch_is_enabled(const struct gprs_rlcmac_pdch *pdch); |
Pau Espin Pedrol | 0dcbc07 | 2021-11-10 19:09:10 +0100 | [diff] [blame] | 193 | bool pdch_is_full(const struct gprs_rlcmac_pdch *pdch); |
Pau Espin Pedrol | 23ae0e3 | 2022-12-15 16:25:27 +0100 | [diff] [blame] | 194 | const char *pdch_name(const struct gprs_rlcmac_pdch *pdch); |
| 195 | char *pdch_name_buf(const struct gprs_rlcmac_pdch *pdch, char *buf, size_t buf_size); |
Pau Espin Pedrol | 906aafc | 2021-01-18 17:53:29 +0100 | [diff] [blame] | 196 | #ifdef __cplusplus |
| 197 | } |
Pau Espin Pedrol | 15c58ac | 2021-03-08 14:57:58 +0100 | [diff] [blame] | 198 | #endif |
Pau Espin Pedrol | 95e2266 | 2021-02-25 17:49:30 +0100 | [diff] [blame] | 199 | |
| 200 | #define LOGPDCH(pdch, category, level, fmt, args...) \ |
Pau Espin Pedrol | 23ae0e3 | 2022-12-15 16:25:27 +0100 | [diff] [blame] | 201 | LOGP(category, level, "%s " fmt, pdch_name(pdch), ## args) |