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