blob: 674cccaa387ed1895546c1bdcef6ef165d765296 [file] [log] [blame]
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04001/* pcu_l1_if.h
Ivan Kluchnikov5c2f9fb2012-02-05 02:27:17 +04002 *
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +04003 * Copyright (C) 2012 Ivan Klyuchnikov
Ivan Kluchnikov5c2f9fb2012-02-05 02:27:17 +04004 *
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 Kluchnikov8ee60512012-03-05 19:24:57 +040020#ifndef PCU_L1_IF_H
21#define PCU_L1_IF_H
Ivan Kluchnikov5c2f9fb2012-02-05 02:27:17 +040022
Andreas Eversberg0aed6542012-06-23 10:33:16 +020023#include <stdint.h>
Andreas Eversberga23c7ee2012-12-18 10:47:28 +010024#ifdef __cplusplus
Ivan Kluchnikove3a05962012-03-18 15:48:51 +040025extern "C" {
Andreas Eversberga23c7ee2012-12-18 10:47:28 +010026#endif
Ivan Kluchnikove3a05962012-03-18 15:48:51 +040027#include <osmocom/core/write_queue.h>
28#include <osmocom/core/socket.h>
29#include <osmocom/core/timer.h>
Andreas Eversberg0aed6542012-06-23 10:33:16 +020030#include <osmocom/core/bitvec.h>
Ivan Kluchnikove3a05962012-03-18 15:48:51 +040031#include <osmocom/gsm/gsm_utils.h>
Max0a8fae82017-03-08 18:53:30 +010032#include <osmocom/pcu/pcuif_proto.h>
Andreas Eversberga23c7ee2012-12-18 10:47:28 +010033#ifdef __cplusplus
Ivan Kluchnikove3a05962012-03-18 15:48:51 +040034}
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +020035#endif
Ivan Kluchnikove3a05962012-03-18 15:48:51 +040036
Maxd71e8b32016-09-19 16:17:06 +020037static 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 Nguyen1bcfa9a2017-11-01 14:41:37 -040046static 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
65static 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 Erlbeck20f6fd12015-06-08 11:05:45 +020074/*
75 * L1 Measurement values
76 */
77
Jacob Erlbeck51b11512015-06-11 16:54:50 +020078struct pcu_l1_meas_ts {
79 unsigned have_ms_i_level:1;
80
81 int16_t ms_i_level; /* I_LEVEL in dB */
Jacob Erlbeck51b11512015-06-11 16:54:50 +020082};
83
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +010084static inline void pcu_l1_meas_ts_set_ms_i_level(struct pcu_l1_meas_ts* ts, int16_t v) {
85 ts->ms_i_level = v;
86 ts->have_ms_i_level = 1;
87}
88
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +020089struct pcu_l1_meas {
90 unsigned have_rssi:1;
91 unsigned have_ber:1;
92 unsigned have_bto:1;
93 unsigned have_link_qual:1;
Jacob Erlbeck51b11512015-06-11 16:54:50 +020094 unsigned have_ms_rx_qual:1;
95 unsigned have_ms_c_value:1;
96 unsigned have_ms_sign_var:1;
97 unsigned have_ms_i_level:1;
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +020098
99 int8_t rssi; /* RSSI in dBm */
100 uint8_t ber; /* Bit error rate in % */
101 int16_t bto; /* Burst timing offset in quarter bits */
Jacob Erlbeck51b11512015-06-11 16:54:50 +0200102 int16_t link_qual; /* Link quality in dB */
103 int16_t ms_rx_qual; /* MS RXQUAL value in % */
104 int16_t ms_c_value; /* C value in dB */
105 int16_t ms_sign_var; /* SIGN_VAR in dB */
106
107 struct pcu_l1_meas_ts ts[8];
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +0200108};
109
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100110static inline void pcu_l1_meas_set_rssi(struct pcu_l1_meas *m, int8_t v) {
111 m->rssi = v;
112 m->have_rssi = 1;
113}
114static inline void pcu_l1_meas_set_ber(struct pcu_l1_meas *m, uint8_t v) {
115 m->ber = v;
116 m->have_ber = 1;
117}
118static inline void pcu_l1_meas_set_bto(struct pcu_l1_meas *m, int16_t v) {
119 m->bto = v;
120 m->have_bto = 1;
121}
122static inline void pcu_l1_meas_set_link_qual(struct pcu_l1_meas *m, int16_t v) {
123 m->link_qual = v;
124 m->have_link_qual = 1;
125}
126static inline void pcu_l1_meas_set_ms_rx_qual(struct pcu_l1_meas *m, int16_t v) {
127 m->ms_rx_qual = v;
128 m->have_ms_rx_qual = 1;
129}
130static inline void pcu_l1_meas_set_ms_c_value(struct pcu_l1_meas *m, int16_t v) {
131 m->ms_c_value = v;
132 m->have_ms_c_value = 1;
133}
134static inline void pcu_l1_meas_set_ms_sign_var(struct pcu_l1_meas *m, int16_t v) {
135 m->ms_sign_var = v;
136 m->have_ms_sign_var = 1;
137}
138static inline void pcu_l1_meas_set_ms_i_level(struct pcu_l1_meas *m, size_t idx, int16_t v) {
139 pcu_l1_meas_ts_set_ms_i_level(&m->ts[idx], v);
140 m->have_ms_i_level = 1;
141}
142
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +0200143#ifdef __cplusplus
Pau Espin Pedrolda971ee2020-12-16 15:59:45 +0100144void pcu_l1if_tx_pdtch(msgb *msg, uint8_t trx, uint8_t ts, uint16_t arfcn,
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200145 uint32_t fn, uint8_t block_nr);
Pau Espin Pedrolac3fd122021-01-13 18:54:38 +0100146void pcu_l1if_tx_ptcch(struct gprs_rlcmac_bts *bts,
147 uint8_t trx, uint8_t ts, uint16_t arfcn,
Vadim Yanitskiy78f58612019-10-05 22:22:08 +0700148 uint32_t fn, uint8_t block_nr,
149 uint8_t *data, size_t data_len);
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200150void pcu_l1if_tx_agch(bitvec * block, int len);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400151
Pau Espin Pedrold7c32652019-12-23 12:41:34 +0100152void pcu_l1if_tx_pch(bitvec * block, int plen, uint16_t pgroup);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400153
Max0a8fae82017-03-08 18:53:30 +0100154int pcu_tx_txt_ind(enum gsm_pcu_if_text_type t, const char *fmt, ...);
155
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200156int pcu_l1if_open(void);
157void pcu_l1if_close(void);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400158
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400159int pcu_rx(uint8_t msg_type, struct gsm_pcu_if *pcu_prim);
160int pcu_sock_send(struct msgb *msg);
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100161#endif
162
163#ifdef __cplusplus
Jacob Erlbeckaf75ce82015-08-26 13:22:28 +0200164extern "C" {
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100165#endif
Max878bd1f2016-07-20 13:05:05 +0200166int pcu_rx_rts_req_pdtch(uint8_t trx, uint8_t ts,
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100167 uint32_t fn, uint8_t block_nr);
Vadim Yanitskiy78f58612019-10-05 22:22:08 +0700168int pcu_rx_rts_req_ptcch(uint8_t trx, uint8_t ts,
169 uint32_t fn, uint8_t block_nr);
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100170
Vadim Yanitskiy6fd47332020-05-21 19:23:33 +0700171int pcu_rx_rach_ind_ptcch(uint8_t trx_nr, uint8_t ts_nr, uint32_t fn, int16_t qta);
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100172int pcu_rx_data_ind_pdtch(uint8_t trx, uint8_t ts, uint8_t *data,
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +0200173 uint8_t len, uint32_t fn, struct pcu_l1_meas *meas);
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100174
Jacob Erlbeckaf75ce82015-08-26 13:22:28 +0200175void pcu_rx_block_time(uint16_t arfcn, uint32_t fn, uint8_t ts_no);
176void pcu_rx_ra_time(uint16_t arfcn, uint32_t fn, uint8_t ts_no);
Pau Espin Pedrold7c32652019-12-23 12:41:34 +0100177uint16_t imsi2paging_group(const char* imsi);
Jacob Erlbeckaf75ce82015-08-26 13:22:28 +0200178#ifdef __cplusplus
179}
180#endif
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400181#endif // PCU_L1_IF_H