Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 1 | /* pcu_l1_if.h |
Ivan Kluchnikov | 5c2f9fb | 2012-02-05 02:27:17 +0400 | [diff] [blame] | 2 | * |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 3 | * Copyright (C) 2012 Ivan Klyuchnikov |
Ivan Kluchnikov | 5c2f9fb | 2012-02-05 02:27:17 +0400 | [diff] [blame] | 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
| 18 | */ |
| 19 | |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 20 | #ifndef PCU_L1_IF_H |
| 21 | #define PCU_L1_IF_H |
Ivan Kluchnikov | 5c2f9fb | 2012-02-05 02:27:17 +0400 | [diff] [blame] | 22 | |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 23 | #include <stdint.h> |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 24 | #ifdef __cplusplus |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 25 | extern "C" { |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 26 | #endif |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 27 | #include <osmocom/core/write_queue.h> |
| 28 | #include <osmocom/core/socket.h> |
| 29 | #include <osmocom/core/timer.h> |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 30 | #include <osmocom/core/bitvec.h> |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 31 | #include <osmocom/gsm/gsm_utils.h> |
Max | 0a8fae8 | 2017-03-08 18:53:30 +0100 | [diff] [blame] | 32 | #include <osmocom/pcu/pcuif_proto.h> |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 33 | #ifdef __cplusplus |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 34 | } |
Jacob Erlbeck | 20f6fd1 | 2015-06-08 11:05:45 +0200 | [diff] [blame] | 35 | #endif |
Ivan Kluchnikov | e3a0596 | 2012-03-18 15:48:51 +0400 | [diff] [blame] | 36 | |
Max | d71e8b3 | 2016-09-19 16:17:06 +0200 | [diff] [blame] | 37 | static inline uint8_t qta2ta(int16_t qta) |
| 38 | { |
| 39 | if (qta < 0) |
| 40 | return 0; |
| 41 | if (qta > 252) |
| 42 | qta = 252; |
| 43 | return qta >> 2; |
| 44 | } |
| 45 | |
Minh-Quang Nguyen | 1bcfa9a | 2017-11-01 14:41:37 -0400 | [diff] [blame] | 46 | static inline int8_t sign_qta2ta(int16_t qta) |
| 47 | { |
| 48 | int8_t ta_adj = 0; |
| 49 | |
| 50 | if (qta < -252) |
| 51 | qta = -252; |
| 52 | |
| 53 | if (qta > 252) |
| 54 | qta = 252; |
| 55 | |
| 56 | /* 1-bit TA adjustment if TA error reported by L1 is outside +/- 2 qbits */ |
| 57 | if (qta > 2) |
| 58 | ta_adj = 1; |
| 59 | if (qta < -2) |
| 60 | ta_adj = -1; |
| 61 | |
| 62 | return (qta >> 2) + ta_adj; |
| 63 | } |
| 64 | |
| 65 | static inline uint8_t ta_limit(int16_t ta) |
| 66 | { |
| 67 | if (ta < 0) |
| 68 | ta = 0; |
| 69 | if (ta > 63) |
| 70 | ta = 63; |
| 71 | return ta; |
| 72 | } |
| 73 | |
Jacob Erlbeck | 20f6fd1 | 2015-06-08 11:05:45 +0200 | [diff] [blame] | 74 | /* |
| 75 | * L1 Measurement values |
| 76 | */ |
| 77 | |
Jacob Erlbeck | 51b1151 | 2015-06-11 16:54:50 +0200 | [diff] [blame] | 78 | struct pcu_l1_meas_ts { |
| 79 | unsigned have_ms_i_level:1; |
| 80 | |
| 81 | int16_t ms_i_level; /* I_LEVEL in dB */ |
| 82 | |
| 83 | #ifdef __cplusplus |
| 84 | pcu_l1_meas_ts& set_ms_i_level(int16_t v) { |
| 85 | ms_i_level = v; have_ms_i_level = 1; return *this; |
| 86 | } |
| 87 | |
| 88 | pcu_l1_meas_ts() : |
Harald Welte | 1f2bb6e | 2016-11-26 15:22:08 +0100 | [diff] [blame] | 89 | have_ms_i_level(0), |
| 90 | ms_i_level(0) |
Jacob Erlbeck | 51b1151 | 2015-06-11 16:54:50 +0200 | [diff] [blame] | 91 | {} |
| 92 | #endif |
| 93 | }; |
| 94 | |
Jacob Erlbeck | 20f6fd1 | 2015-06-08 11:05:45 +0200 | [diff] [blame] | 95 | struct pcu_l1_meas { |
| 96 | unsigned have_rssi:1; |
| 97 | unsigned have_ber:1; |
| 98 | unsigned have_bto:1; |
| 99 | unsigned have_link_qual:1; |
Jacob Erlbeck | 51b1151 | 2015-06-11 16:54:50 +0200 | [diff] [blame] | 100 | unsigned have_ms_rx_qual:1; |
| 101 | unsigned have_ms_c_value:1; |
| 102 | unsigned have_ms_sign_var:1; |
| 103 | unsigned have_ms_i_level:1; |
Jacob Erlbeck | 20f6fd1 | 2015-06-08 11:05:45 +0200 | [diff] [blame] | 104 | |
| 105 | int8_t rssi; /* RSSI in dBm */ |
| 106 | uint8_t ber; /* Bit error rate in % */ |
| 107 | int16_t bto; /* Burst timing offset in quarter bits */ |
Jacob Erlbeck | 51b1151 | 2015-06-11 16:54:50 +0200 | [diff] [blame] | 108 | int16_t link_qual; /* Link quality in dB */ |
| 109 | int16_t ms_rx_qual; /* MS RXQUAL value in % */ |
| 110 | int16_t ms_c_value; /* C value in dB */ |
| 111 | int16_t ms_sign_var; /* SIGN_VAR in dB */ |
| 112 | |
| 113 | struct pcu_l1_meas_ts ts[8]; |
| 114 | |
Jacob Erlbeck | 20f6fd1 | 2015-06-08 11:05:45 +0200 | [diff] [blame] | 115 | #ifdef __cplusplus |
| 116 | pcu_l1_meas& set_rssi(int8_t v) { rssi = v; have_rssi = 1; return *this;} |
| 117 | pcu_l1_meas& set_ber(uint8_t v) { ber = v; have_ber = 1; return *this;} |
| 118 | pcu_l1_meas& set_bto(int16_t v) { bto = v; have_bto = 1; return *this;} |
| 119 | pcu_l1_meas& set_link_qual(int16_t v) { |
| 120 | link_qual = v; have_link_qual = 1; return *this; |
| 121 | } |
Jacob Erlbeck | 51b1151 | 2015-06-11 16:54:50 +0200 | [diff] [blame] | 122 | pcu_l1_meas& set_ms_rx_qual(int16_t v) { |
| 123 | ms_rx_qual = v; have_ms_rx_qual = 1; return *this; |
| 124 | } |
| 125 | pcu_l1_meas& set_ms_c_value(int16_t v) { |
| 126 | ms_c_value = v; have_ms_c_value = 1; return *this; |
| 127 | } |
| 128 | pcu_l1_meas& set_ms_sign_var(int16_t v) { |
| 129 | ms_sign_var = v; have_ms_sign_var = 1; return *this; |
| 130 | } |
| 131 | pcu_l1_meas& set_ms_i_level(size_t idx, int16_t v) { |
| 132 | ts[idx].set_ms_i_level(v); have_ms_i_level = 1; return *this; |
| 133 | } |
Jacob Erlbeck | 20f6fd1 | 2015-06-08 11:05:45 +0200 | [diff] [blame] | 134 | pcu_l1_meas() : |
| 135 | have_rssi(0), |
| 136 | have_ber(0), |
| 137 | have_bto(0), |
Jacob Erlbeck | 51b1151 | 2015-06-11 16:54:50 +0200 | [diff] [blame] | 138 | have_link_qual(0), |
| 139 | have_ms_rx_qual(0), |
| 140 | have_ms_c_value(0), |
| 141 | have_ms_sign_var(0), |
Harald Welte | 963cdaf | 2016-11-26 15:24:06 +0100 | [diff] [blame] | 142 | have_ms_i_level(0), |
| 143 | rssi(0), |
| 144 | ber(0), |
| 145 | bto(0), |
| 146 | link_qual(0), |
| 147 | ms_rx_qual(0), |
| 148 | ms_c_value(0), |
| 149 | ms_sign_var(0) |
Jacob Erlbeck | 20f6fd1 | 2015-06-08 11:05:45 +0200 | [diff] [blame] | 150 | {} |
| 151 | #endif |
| 152 | }; |
| 153 | |
| 154 | #ifdef __cplusplus |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 155 | void pcu_l1if_tx_pdtch(msgb *msg, uint8_t trx, uint8_t ts, uint16_t arfcn, |
| 156 | uint32_t fn, uint8_t block_nr); |
Vadim Yanitskiy | 78f5861 | 2019-10-05 22:22:08 +0700 | [diff] [blame] | 157 | void pcu_l1if_tx_ptcch(uint8_t trx, uint8_t ts, uint16_t arfcn, |
| 158 | uint32_t fn, uint8_t block_nr, |
| 159 | uint8_t *data, size_t data_len); |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 160 | void pcu_l1if_tx_agch(bitvec * block, int len); |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 161 | |
Pau Espin Pedrol | d7c3265 | 2019-12-23 12:41:34 +0100 | [diff] [blame] | 162 | void pcu_l1if_tx_pch(bitvec * block, int plen, uint16_t pgroup); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 163 | |
Max | 0a8fae8 | 2017-03-08 18:53:30 +0100 | [diff] [blame] | 164 | int pcu_tx_txt_ind(enum gsm_pcu_if_text_type t, const char *fmt, ...); |
| 165 | |
Andreas Eversberg | 0aed654 | 2012-06-23 10:33:16 +0200 | [diff] [blame] | 166 | int pcu_l1if_open(void); |
| 167 | void pcu_l1if_close(void); |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 168 | |
Ivan Kluchnikov | ef7f28c | 2012-07-12 14:49:15 +0400 | [diff] [blame] | 169 | int pcu_rx(uint8_t msg_type, struct gsm_pcu_if *pcu_prim); |
| 170 | int pcu_sock_send(struct msgb *msg); |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 171 | #endif |
| 172 | |
| 173 | #ifdef __cplusplus |
Jacob Erlbeck | af75ce8 | 2015-08-26 13:22:28 +0200 | [diff] [blame] | 174 | extern "C" { |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 175 | #endif |
Max | 878bd1f | 2016-07-20 13:05:05 +0200 | [diff] [blame] | 176 | int pcu_rx_rts_req_pdtch(uint8_t trx, uint8_t ts, |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 177 | uint32_t fn, uint8_t block_nr); |
Vadim Yanitskiy | 78f5861 | 2019-10-05 22:22:08 +0700 | [diff] [blame] | 178 | int pcu_rx_rts_req_ptcch(uint8_t trx, uint8_t ts, |
| 179 | uint32_t fn, uint8_t block_nr); |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 180 | |
Vadim Yanitskiy | 6fd4733 | 2020-05-21 19:23:33 +0700 | [diff] [blame] | 181 | int pcu_rx_rach_ind_ptcch(uint8_t trx_nr, uint8_t ts_nr, uint32_t fn, int16_t qta); |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 182 | int pcu_rx_data_ind_pdtch(uint8_t trx, uint8_t ts, uint8_t *data, |
Jacob Erlbeck | 20f6fd1 | 2015-06-08 11:05:45 +0200 | [diff] [blame] | 183 | uint8_t len, uint32_t fn, struct pcu_l1_meas *meas); |
Andreas Eversberg | a23c7ee | 2012-12-18 10:47:28 +0100 | [diff] [blame] | 184 | |
Jacob Erlbeck | af75ce8 | 2015-08-26 13:22:28 +0200 | [diff] [blame] | 185 | void pcu_rx_block_time(uint16_t arfcn, uint32_t fn, uint8_t ts_no); |
| 186 | void pcu_rx_ra_time(uint16_t arfcn, uint32_t fn, uint8_t ts_no); |
Pau Espin Pedrol | d7c3265 | 2019-12-23 12:41:34 +0100 | [diff] [blame] | 187 | uint16_t imsi2paging_group(const char* imsi); |
Jacob Erlbeck | af75ce8 | 2015-08-26 13:22:28 +0200 | [diff] [blame] | 188 | #ifdef __cplusplus |
| 189 | } |
| 190 | #endif |
Ivan Kluchnikov | 8ee6051 | 2012-03-05 19:24:57 +0400 | [diff] [blame] | 191 | #endif // PCU_L1_IF_H |