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