Merge branch 'master' into testing
[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         L1CTL_VOICE_REQ,
55         L1CTL_VOICE_CONF,
56         L1CTL_VOICE_IND,
57 };
58
59 enum ccch_mode {
60         CCCH_MODE_NONE = 0,
61         CCCH_MODE_NON_COMBINED,
62         CCCH_MODE_COMBINED,
63 };
64
65 /*
66  * NOTE: struct size. We do add manual padding out of the believe
67  * that it will avoid some unaligned access.
68  */
69
70 /* there are no more messages in a sequence */
71 #define L1CTL_F_DONE    0x01
72
73 struct l1ctl_hdr {
74         uint8_t msg_type;
75         uint8_t flags;
76         uint8_t padding[2];
77         uint8_t data[0];
78 } __attribute__((packed));
79
80 /*
81  * downlink info ... down from the BTS..
82  */
83 struct l1ctl_info_dl {
84         /* GSM 08.58 channel number (9.3.1) */
85         uint8_t chan_nr;
86         /* GSM 08.58 link identifier (9.3.2) */
87         uint8_t link_id;
88         /* the ARFCN and the band. FIXME: what about MAIO? */
89         uint16_t band_arfcn;
90
91         uint32_t frame_nr;
92
93         uint8_t rx_level;       /* 0 .. 63 in typical GSM notation (dBm+110) */
94         uint8_t snr;            /* Signal/Noise Ration (dB) */
95         uint8_t num_biterr;
96         uint8_t fire_crc;
97
98         uint8_t payload[0];
99 } __attribute__((packed));
100
101 /* new CCCH was found. This is following the header */
102 struct l1ctl_fbsb_conf {
103         int16_t initial_freq_err;
104         uint8_t result;
105         uint8_t bsic;
106         /* FIXME: contents of cell_info ? */
107 } __attribute__((packed));
108
109 /* CCCH mode was changed */
110 struct l1ctl_ccch_mode_conf {
111         uint8_t ccch_mode;      /* enum ccch_mode */
112         uint8_t padding[3];
113 } __attribute__((packed));
114
115 /* TCH mode was changed */
116 struct l1ctl_tch_mode_conf {
117         uint8_t tch_mode;       /* enum tch_mode */
118         uint8_t padding[3];
119 } __attribute__((packed));
120
121 /* data on the CCCH was found. This is following the header */
122 struct l1ctl_data_ind {
123         uint8_t data[23];
124 } __attribute__((packed));
125
126 /* voice data from network */
127 struct l1ctl_voice_ind {
128         uint8_t data[33];
129 } __attribute__((packed));
130
131 /*
132  * uplink info
133  */
134 struct l1ctl_info_ul {
135         /* GSM 08.58 channel number (9.3.1) */
136         uint8_t chan_nr;
137         /* GSM 08.58 link identifier (9.3.2) */
138         uint8_t link_id;
139         uint8_t padding[2];
140
141         uint8_t payload[0];
142 } __attribute__((packed));
143
144 /*
145  * msg for FBSB_REQ
146  * the l1_info_ul header is in front
147  */
148 struct l1ctl_fbsb_req {
149         uint16_t band_arfcn;
150         uint16_t timeout;       /* in TDMA frames */
151
152         uint16_t freq_err_thresh1;
153         uint16_t freq_err_thresh2;
154
155         uint8_t num_freqerr_avg;
156         uint8_t flags;          /* L1CTL_FBSB_F_* */
157         uint8_t sync_info_idx;
158         uint8_t ccch_mode;      /* enum ccch_mode */
159 } __attribute__((packed));
160
161 #define L1CTL_FBSB_F_FB0        (1 << 0)
162 #define L1CTL_FBSB_F_FB1        (1 << 1)
163 #define L1CTL_FBSB_F_SB         (1 << 2)
164 #define L1CTL_FBSB_F_FB01SB     (L1CTL_FBSB_F_FB0|L1CTL_FBSB_F_FB1|L1CTL_FBSB_F_SB)
165
166 /*
167  * msg for CCCH_MODE_REQ
168  * the l1_info_ul header is in front
169  */
170 struct l1ctl_ccch_mode_req {
171         uint8_t ccch_mode;      /* enum ccch_mode */
172         uint8_t padding[3];
173 } __attribute__((packed));
174
175 /*
176  * msg for TCH_MODE_REQ
177  * the l1_info_ul header is in front
178  */
179 struct l1ctl_tch_mode_req {
180         uint8_t tch_mode;       /* enum gsm48_chan_mode */
181         uint8_t padding[3];
182 } __attribute__((packed));
183
184 /* the l1_info_ul header is in front */
185 struct l1ctl_rach_req {
186         uint8_t ra;
187         uint8_t combined;
188         uint16_t offset;
189 } __attribute__((packed));
190
191 /* the l1_info_ul header is in front */
192 struct l1ctl_par_req {
193         int8_t ta;
194         uint8_t tx_power;
195         uint8_t padding[2];
196 } __attribute__((packed));
197
198 struct l1ctl_h0 {
199         uint16_t band_arfcn;
200 } __attribute__((packed));
201
202 struct l1ctl_h1 {
203         uint8_t hsn;
204         uint8_t maio;
205         uint8_t n;
206         uint8_t _padding[1];
207         uint16_t ma[64];
208 } __attribute__((packed));
209
210 struct l1ctl_dm_est_req {
211         uint8_t tsc;
212         uint8_t h;
213         union {
214                 struct l1ctl_h0 h0;
215                 struct l1ctl_h1 h1;
216         };
217         uint8_t tch_mode;
218         uint8_t _padding[1];
219 } __attribute__((packed));
220
221 struct l1ctl_dm_freq_req {
222         uint16_t fn;
223         uint8_t tsc;
224         uint8_t h;
225         union {
226                 struct l1ctl_h0 h0;
227                 struct l1ctl_h1 h1;
228         };
229 } __attribute__((packed));
230
231 struct l1ctl_crypto_req {
232         uint8_t algo;
233         uint8_t key[0];
234 } __attribute__((packed));
235
236 struct l1ctl_pm_req {
237         uint8_t type;
238         uint8_t padding[3];
239
240         union {
241                 struct {
242                         uint16_t band_arfcn_from;
243                         uint16_t band_arfcn_to;
244                 } range;
245         };
246 } __attribute__((packed));
247
248 /* a single L1CTL_PM response */
249 struct l1ctl_pm_conf {
250         uint16_t band_arfcn;
251         uint8_t pm[2];
252 } __attribute__((packed));
253
254 enum l1ctl_reset_type {
255         L1CTL_RES_T_BOOT,       /* only _IND */
256         L1CTL_RES_T_FULL,
257         L1CTL_RES_T_SCHED,
258 };
259
260 /* argument to L1CTL_RESET_REQ and L1CTL_RESET_IND */
261 struct l1ctl_reset {
262         uint8_t type;
263         uint8_t pad[3];
264 } __attribute__((packed));
265
266 /* voice data to network */
267 struct l1ctl_voice_req {
268         uint8_t data[33];
269 } __attribute__((packed));
270
271 #endif /* __L1CTL_PROTO_H__ */