fw/l1a: Add a message to safely count the length of a txqueue
[osmocom-bb.git] / include / l1ctl_proto.h
1 /* Messages to be sent between the different layers */
2
3 /* (C) 2010 by Harald Welte <laforge@gnumonks.org>
4  * (C) 2010 by Holger Hans Peter Freyther
5  *
6  * All Rights Reserved
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation; either version 2 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License along
19  * with this program; if not, write to the Free Software Foundation, Inc.,
20  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21  *
22  */
23
24 #ifndef __L1CTL_PROTO_H__
25 #define __L1CTL_PROTO_H__
26
27 enum {
28         _L1CTL_NONE             = 0,
29         L1CTL_FBSB_REQ,
30         L1CTL_FBSB_CONF,
31         L1CTL_DATA_IND,
32         L1CTL_RACH_REQ,
33         L1CTL_DM_EST_REQ,
34         L1CTL_DATA_REQ,
35         L1CTL_RESET_IND,
36         L1CTL_PM_REQ,           /* power measurement */
37         L1CTL_PM_CONF,          /* power measurement */
38         L1CTL_ECHO_REQ,
39         L1CTL_ECHO_CONF,
40         L1CTL_RACH_CONF,
41         L1CTL_RESET_REQ,
42         L1CTL_RESET_CONF,
43         L1CTL_DATA_CONF,
44         L1CTL_CCCH_MODE_REQ,
45         L1CTL_CCCH_MODE_CONF,
46         L1CTL_DM_REL_REQ,
47         L1CTL_PARAM_REQ,
48         L1CTL_DM_FREQ_REQ,
49         L1CTL_CRYPTO_REQ,
50         L1CTL_SIM_REQ,
51         L1CTL_SIM_CONF,
52         L1CTL_TCH_MODE_REQ,
53         L1CTL_TCH_MODE_CONF,
54 };
55
56 enum ccch_mode {
57         CCCH_MODE_NONE = 0,
58         CCCH_MODE_NON_COMBINED,
59         CCCH_MODE_COMBINED,
60 };
61
62 /*
63  * NOTE: struct size. We do add manual padding out of the believe
64  * that it will avoid some unaligned access.
65  */
66
67 /* there are no more messages in a sequence */
68 #define L1CTL_F_DONE    0x01
69
70 struct l1ctl_hdr {
71         uint8_t msg_type;
72         uint8_t flags;
73         uint8_t padding[2];
74         uint8_t data[0];
75 } __attribute__((packed));
76
77 /*
78  * downlink info ... down from the BTS..
79  */
80 struct l1ctl_info_dl {
81         /* GSM 08.58 channel number (9.3.1) */
82         uint8_t chan_nr;
83         /* GSM 08.58 link identifier (9.3.2) */
84         uint8_t link_id;
85         /* the ARFCN and the band. FIXME: what about MAIO? */
86         uint16_t band_arfcn;
87
88         uint32_t frame_nr;
89
90         uint8_t rx_level;       /* 0 .. 63 in typical GSM notation (dBm+110) */
91         uint8_t snr;            /* Signal/Noise Ration (dB) */
92         uint8_t num_biterr;
93         uint8_t fire_crc;
94
95         uint8_t payload[0];
96 } __attribute__((packed));
97
98 /* new CCCH was found. This is following the header */
99 struct l1ctl_fbsb_conf {
100         int16_t initial_freq_err;
101         uint8_t result;
102         uint8_t bsic;
103         /* FIXME: contents of cell_info ? */
104 } __attribute__((packed));
105
106 /* CCCH mode was changed */
107 struct l1ctl_ccch_mode_conf {
108         uint8_t ccch_mode;      /* enum ccch_mode */
109         uint8_t padding[3];
110 } __attribute__((packed));
111
112 /* TCH mode was changed */
113 struct l1ctl_tch_mode_conf {
114         uint8_t tch_mode;       /* enum tch_mode */
115         uint8_t padding[3];
116 } __attribute__((packed));
117
118 /* data on the CCCH was found. This is following the header */
119 struct l1ctl_data_ind {
120         uint8_t data[23];
121 } __attribute__((packed));
122
123 /*
124  * uplink info
125  */
126 struct l1ctl_info_ul {
127         /* GSM 08.58 channel number (9.3.1) */
128         uint8_t chan_nr;
129         /* GSM 08.58 link identifier (9.3.2) */
130         uint8_t link_id;
131         uint8_t padding[2];
132
133         uint8_t payload[0];
134 } __attribute__((packed));
135
136 /*
137  * msg for FBSB_REQ
138  * the l1_info_ul header is in front
139  */
140 struct l1ctl_fbsb_req {
141         uint16_t band_arfcn;
142         uint16_t timeout;       /* in TDMA frames */
143
144         uint16_t freq_err_thresh1;
145         uint16_t freq_err_thresh2;
146
147         uint8_t num_freqerr_avg;
148         uint8_t flags;          /* L1CTL_FBSB_F_* */
149         uint8_t sync_info_idx;
150         uint8_t ccch_mode;      /* enum ccch_mode */
151 } __attribute__((packed));
152
153 #define L1CTL_FBSB_F_FB0        (1 << 0)
154 #define L1CTL_FBSB_F_FB1        (1 << 1)
155 #define L1CTL_FBSB_F_SB         (1 << 2)
156 #define L1CTL_FBSB_F_FB01SB     (L1CTL_FBSB_F_FB0|L1CTL_FBSB_F_FB1|L1CTL_FBSB_F_SB)
157
158 /*
159  * msg for CCCH_MODE_REQ
160  * the l1_info_ul header is in front
161  */
162 struct l1ctl_ccch_mode_req {
163         uint8_t ccch_mode;      /* enum ccch_mode */
164         uint8_t padding[3];
165 } __attribute__((packed));
166
167 /*
168  * msg for TCH_MODE_REQ
169  * the l1_info_ul header is in front
170  */
171 struct l1ctl_tch_mode_req {
172         uint8_t tch_mode;       /* enum gsm48_chan_mode */
173         uint8_t padding[3];
174 } __attribute__((packed));
175
176 /* the l1_info_ul header is in front */
177 struct l1ctl_rach_req {
178         uint8_t ra;
179         uint8_t combined;
180         uint16_t offset;
181 } __attribute__((packed));
182
183 /* the l1_info_ul header is in front */
184 struct l1ctl_par_req {
185         int8_t ta;
186         uint8_t tx_power;
187         uint8_t padding[2];
188 } __attribute__((packed));
189
190 struct l1ctl_h0 {
191         uint16_t band_arfcn;
192 } __attribute__((packed));
193
194 struct l1ctl_h1 {
195         uint8_t hsn;
196         uint8_t maio;
197         uint8_t n;
198         uint8_t _padding[1];
199         uint16_t ma[64];
200 } __attribute__((packed));
201
202 struct l1ctl_dm_est_req {
203         uint8_t tsc;
204         uint8_t h;
205         union {
206                 struct l1ctl_h0 h0;
207                 struct l1ctl_h1 h1;
208         };
209         uint8_t tch_mode;
210         uint8_t _padding[1];
211 } __attribute__((packed));
212
213 struct l1ctl_dm_freq_req {
214         uint16_t fn;
215         uint8_t tsc;
216         uint8_t h;
217         union {
218                 struct l1ctl_h0 h0;
219                 struct l1ctl_h1 h1;
220         };
221 } __attribute__((packed));
222
223 struct l1ctl_crypto_req {
224         uint8_t algo;
225         uint8_t key[0];
226 } __attribute__((packed));
227
228 struct l1ctl_pm_req {
229         uint8_t type;
230         uint8_t padding[3];
231
232         union {
233                 struct {
234                         uint16_t band_arfcn_from;
235                         uint16_t band_arfcn_to;
236                 } range;
237         };
238 } __attribute__((packed));
239
240 /* a single L1CTL_PM response */
241 struct l1ctl_pm_conf {
242         uint16_t band_arfcn;
243         uint8_t pm[2];
244 } __attribute__((packed));
245
246 enum l1ctl_reset_type {
247         L1CTL_RES_T_BOOT,       /* only _IND */
248         L1CTL_RES_T_FULL,
249         L1CTL_RES_T_SCHED,
250 };
251
252 /* argument to L1CTL_RESET_REQ and L1CTL_RESET_IND */
253 struct l1ctl_reset {
254         uint8_t type;
255         uint8_t pad[3];
256 } __attribute__((packed));
257
258 #endif /* __L1CTL_PROTO_H__ */