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. |
| 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 |
| 25 | extern "C" { |
| 26 | #include <osmocom/core/linuxlist.h> |
Pau Espin Pedrol | b2653fe | 2020-03-26 15:14:01 +0100 | [diff] [blame] | 27 | #include "gsm_rlcmac.h" |
Pau Espin Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 28 | #include "coding_scheme.h" |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 29 | } |
| 30 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 31 | #include <bts.h> |
| 32 | #endif |
| 33 | |
| 34 | #include <tbf.h> |
| 35 | |
| 36 | #include <stdint.h> |
| 37 | |
Vadim Yanitskiy | bd0dac3 | 2019-10-05 21:57:14 +0700 | [diff] [blame] | 38 | /* 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 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 43 | /* |
| 44 | * PDCH instance |
| 45 | */ |
| 46 | struct gprs_rlcmac_pdch { |
| 47 | #ifdef __cplusplus |
| 48 | struct gprs_rlcmac_paging *dequeue_paging(); |
| 49 | struct msgb *packet_paging_request(); |
| 50 | |
Pau Espin Pedrol | fbfab29 | 2019-12-23 13:19:25 +0100 | [diff] [blame] | 51 | bool add_paging(uint8_t chan_needed, const uint8_t *mi, uint8_t mi_len); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 52 | |
| 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 Pedrol | 2ae8337 | 2020-05-18 11:35:35 +0200 | [diff] [blame] | 64 | struct pcu_l1_meas *meas, enum CodingScheme cs); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 65 | 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] | 66 | struct pcu_l1_meas *meas, enum CodingScheme cs); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 67 | |
| 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 Yanitskiy | bd0dac3 | 2019-10-05 21:57:14 +0700 | [diff] [blame] | 96 | /* 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 | |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 109 | /* back pointers */ |
| 110 | struct gprs_rlcmac_trx *trx; |
| 111 | uint8_t ts_no; |
| 112 | |
| 113 | #ifdef __cplusplus |
| 114 | private: |
Pau Espin Pedrol | e13cdc5 | 2019-09-25 13:46:14 +0200 | [diff] [blame] | 115 | 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] | 116 | struct pcu_l1_meas *meas, enum CodingScheme cs); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 117 | |
| 118 | void rcv_control_ack(Packet_Control_Acknowledgement_t *, uint32_t fn); |
Pau Espin Pedrol | e13cdc5 | 2019-09-25 13:46:14 +0200 | [diff] [blame] | 119 | 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); |
Max | 6dc90b8 | 2018-02-19 17:17:28 +0100 | [diff] [blame] | 122 | 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 | |
| 139 | inline unsigned gprs_rlcmac_pdch::num_tbfs(enum gprs_rlcmac_tbf_direction dir) const |
| 140 | { |
| 141 | return m_num_tbfs[dir]; |
| 142 | } |
| 143 | |
| 144 | inline 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 | |
| 150 | inline uint8_t gprs_rlcmac_pdch::assigned_usf() const |
| 151 | { |
| 152 | return m_assigned_usf; |
| 153 | } |
| 154 | |
| 155 | inline uint32_t gprs_rlcmac_pdch::assigned_tfi( |
| 156 | enum gprs_rlcmac_tbf_direction dir) const |
| 157 | { |
| 158 | return m_assigned_tfi[dir]; |
| 159 | } |
| 160 | |
| 161 | inline bool gprs_rlcmac_pdch::is_enabled() const |
| 162 | { |
| 163 | return m_is_enabled; |
| 164 | } |
| 165 | |
| 166 | #endif /* __cplusplus */ |