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