blob: 1618260c9ce167844a0c75ce6395c513ce230331 [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
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +020046/*
47 * L1 Measurement values
48 */
49
Jacob Erlbeck51b11512015-06-11 16:54:50 +020050struct pcu_l1_meas_ts {
51 unsigned have_ms_i_level:1;
52
53 int16_t ms_i_level; /* I_LEVEL in dB */
54
55#ifdef __cplusplus
56 pcu_l1_meas_ts& set_ms_i_level(int16_t v) {
57 ms_i_level = v; have_ms_i_level = 1; return *this;
58 }
59
60 pcu_l1_meas_ts() :
Harald Welte1f2bb6e2016-11-26 15:22:08 +010061 have_ms_i_level(0),
62 ms_i_level(0)
Jacob Erlbeck51b11512015-06-11 16:54:50 +020063 {}
64#endif
65};
66
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +020067struct pcu_l1_meas {
68 unsigned have_rssi:1;
69 unsigned have_ber:1;
70 unsigned have_bto:1;
71 unsigned have_link_qual:1;
Jacob Erlbeck51b11512015-06-11 16:54:50 +020072 unsigned have_ms_rx_qual:1;
73 unsigned have_ms_c_value:1;
74 unsigned have_ms_sign_var:1;
75 unsigned have_ms_i_level:1;
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +020076
77 int8_t rssi; /* RSSI in dBm */
78 uint8_t ber; /* Bit error rate in % */
79 int16_t bto; /* Burst timing offset in quarter bits */
Jacob Erlbeck51b11512015-06-11 16:54:50 +020080 int16_t link_qual; /* Link quality in dB */
81 int16_t ms_rx_qual; /* MS RXQUAL value in % */
82 int16_t ms_c_value; /* C value in dB */
83 int16_t ms_sign_var; /* SIGN_VAR in dB */
84
85 struct pcu_l1_meas_ts ts[8];
86
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +020087#ifdef __cplusplus
88 pcu_l1_meas& set_rssi(int8_t v) { rssi = v; have_rssi = 1; return *this;}
89 pcu_l1_meas& set_ber(uint8_t v) { ber = v; have_ber = 1; return *this;}
90 pcu_l1_meas& set_bto(int16_t v) { bto = v; have_bto = 1; return *this;}
91 pcu_l1_meas& set_link_qual(int16_t v) {
92 link_qual = v; have_link_qual = 1; return *this;
93 }
Jacob Erlbeck51b11512015-06-11 16:54:50 +020094 pcu_l1_meas& set_ms_rx_qual(int16_t v) {
95 ms_rx_qual = v; have_ms_rx_qual = 1; return *this;
96 }
97 pcu_l1_meas& set_ms_c_value(int16_t v) {
98 ms_c_value = v; have_ms_c_value = 1; return *this;
99 }
100 pcu_l1_meas& set_ms_sign_var(int16_t v) {
101 ms_sign_var = v; have_ms_sign_var = 1; return *this;
102 }
103 pcu_l1_meas& set_ms_i_level(size_t idx, int16_t v) {
104 ts[idx].set_ms_i_level(v); have_ms_i_level = 1; return *this;
105 }
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +0200106 pcu_l1_meas() :
107 have_rssi(0),
108 have_ber(0),
109 have_bto(0),
Jacob Erlbeck51b11512015-06-11 16:54:50 +0200110 have_link_qual(0),
111 have_ms_rx_qual(0),
112 have_ms_c_value(0),
113 have_ms_sign_var(0),
Harald Welte963cdaf2016-11-26 15:24:06 +0100114 have_ms_i_level(0),
115 rssi(0),
116 ber(0),
117 bto(0),
118 link_qual(0),
119 ms_rx_qual(0),
120 ms_c_value(0),
121 ms_sign_var(0)
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +0200122 {}
123#endif
124};
125
126#ifdef __cplusplus
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200127void pcu_l1if_tx_pdtch(msgb *msg, uint8_t trx, uint8_t ts, uint16_t arfcn,
128 uint32_t fn, uint8_t block_nr);
129void pcu_l1if_tx_ptcch(msgb *msg, uint8_t trx, uint8_t ts, uint16_t arfcn,
130 uint32_t fn, uint8_t block_nr);
131void pcu_l1if_tx_agch(bitvec * block, int len);
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400132
Holger Hans Peter Freyther52c911b2013-08-24 18:30:54 +0200133void pcu_l1if_tx_pch(bitvec * block, int plen, const char *imsi);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400134
Max0a8fae82017-03-08 18:53:30 +0100135int pcu_tx_txt_ind(enum gsm_pcu_if_text_type t, const char *fmt, ...);
136
Andreas Eversberg0aed6542012-06-23 10:33:16 +0200137int pcu_l1if_open(void);
138void pcu_l1if_close(void);
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400139
Ivan Kluchnikovef7f28c2012-07-12 14:49:15 +0400140int pcu_rx(uint8_t msg_type, struct gsm_pcu_if *pcu_prim);
141int pcu_sock_send(struct msgb *msg);
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100142#endif
143
144#ifdef __cplusplus
Jacob Erlbeckaf75ce82015-08-26 13:22:28 +0200145extern "C" {
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100146#endif
Max878bd1f2016-07-20 13:05:05 +0200147int pcu_rx_rts_req_pdtch(uint8_t trx, uint8_t ts,
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100148 uint32_t fn, uint8_t block_nr);
149
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100150int pcu_rx_data_ind_pdtch(uint8_t trx, uint8_t ts, uint8_t *data,
Jacob Erlbeck20f6fd12015-06-08 11:05:45 +0200151 uint8_t len, uint32_t fn, struct pcu_l1_meas *meas);
Andreas Eversberga23c7ee2012-12-18 10:47:28 +0100152
Jacob Erlbeckaf75ce82015-08-26 13:22:28 +0200153void pcu_rx_block_time(uint16_t arfcn, uint32_t fn, uint8_t ts_no);
154void pcu_rx_ra_time(uint16_t arfcn, uint32_t fn, uint8_t ts_no);
155
156#ifdef __cplusplus
157}
158#endif
Ivan Kluchnikov8ee60512012-03-05 19:24:57 +0400159#endif // PCU_L1_IF_H