Work on Radio Ressource.
[osmocom-bb.git] / src / host / gsm48-andreas / gsm48_l3.h
1 /*
2  * (C) 2010 by Andreas Eversberg <jolly@eversberg.eu>
3  *
4  * All Rights Reserved
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License along
17  * with this program; if not, write to the Free Software Foundation, Inc.,
18  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19  *
20  */
21
22 /* application layer primitives */
23
24 /* GSM 6.1.2 */
25 #define GSM_MMR_REG_REQ         0x1101
26 #define GSM_MMR_REG_CNF         0x1102
27 #define GSM_MMR_NREG_REQ        0x1103
28 #define GSM_MMR_NREG_IND        0x1104
29
30 #define MMR_F_IMSI              0x0001
31 #define MMR_F_CAUSE             0x0002
32
33 struct gsm48_mmr {
34         u_int32_t       msg_type;
35
36         u_int32_t       fields;
37         char            imsi[16];
38         u_int8_t        cause;
39 };
40
41 /* GSM 6.3.2 */
42 #define GSM_MNSS_BEGIN_REQ      0x2110
43 #define GSM_MNSS_BEGIN_IND      0x2112
44 #define GSM_MNSS_FACILITY_REQ   0x2120
45 #define GSM_MNSS_FACILITY_IND   0x2122
46 #define GSM_MNSS_END_REQ        0x2130
47 #define GSM_MNSS_END_IND        0x2132
48
49 #define MNSS_F_REGISTER         0x0001
50 #define MNSS_F_FACILITY         0x0002
51 #define MNSS_F_RELCOMPL         0x0004
52
53 struct gsm48_mnss {
54         u_int32_t       msg_type;
55         u_int32_t       callref;
56
57         u_int32_t       fields;
58         struct gsm_mnss_register        register;
59         struct gsm_mnss_facility        facility;
60         struct gsm_mnss_release_compl   release_compl;
61 };
62
63 /* interlayer primitives */
64
65 /* GSM 04.07 9.1.2 */
66 #define RR_EST_REQ              0x8110
67 #define RR_EST_IND              0x8112
68 #define RR_EST_CNF              0x8111
69 #define RR_REL_IND              0x8122
70 #define RR_SYNC_IND             0x8132
71 #define RR_DATA_REQ             0x8140
72 #define RR_DATA_IND             0x8142
73 #define RR_UNIT_DATA_IND        0x8152
74 #define RR_ABORT_REQ            0x8160
75 #define RR_ABORT_IND            0x8162
76 #define RR_ACT_REQ              0x8170
77
78 struct gsm48_rr {
79         u_int32_t       msg_type; /* RR_* primitive */
80         struct msgb     *msg; /* gsm48 msg */
81         u_int8_t        cause;
82 };
83
84 /* GSM 04.07 9.2.2 */
85 #define MMCC_EST_REQ            0x9110
86 #define MMCC_EST_IND            0x9112
87 #define MMCC_EST_CNF            0x9111
88 #define MMCC_REL_REQ            0x9120
89 #define MMCC_REL_IND            0x9122
90 #define MMCC_DATA_REQ           0x9130
91 #define MMCC_DATA_IND           0x9132
92 #define MMCC_UNIT_DATA_REQ      0x9140
93 #define MMCC_UNIT_DATA_IND      0x9142
94 #define MMCC_SYNC_IND           0x9152
95 #define MMCC_REEST_REQ          0x9160
96 #define MMCC_REEST_CNF          0x9161
97 #define MMCC_ERR_IND            0x9172
98 #define MMCC_PROMPT_IND         0x9182
99 #define MMCC_PROMPT_REJ         0x9184
100 #define MMSS_EST_REQ            0x9210
101 #define MMSS_EST_IND            0x9212
102 #define MMSS_EST_CNF            0x9211
103 #define MMSS_REL_REQ            0x9220
104 #define MMSS_REL_IND            0x9222
105 #define MMSS_DATA_REQ           0x9230
106 #define MMSS_DATA_IND           0x9232
107 #define MMSS_UNIT_DATA_REQ      0x9240
108 #define MMSS_UNIT_DATA_IND      0x9242
109 #define MMSS_REEST_REQ          0x9260
110 #define MMSS_REEST_CNF          0x9261
111 #define MMSS_ERR_IND            0x9272
112 #define MMSS_PROMPT_IND         0x9282
113 #define MMSS_PROMPT_REJ         0x9284
114 #define MMSMS_EST_REQ           0x9310
115 #define MMSMS_EST_IND           0x9312
116 #define MMSMS_EST_CNF           0x9311
117 #define MMSMS_REL_REQ           0x9320
118 #define MMSMS_REL_IND           0x9322
119 #define MMSMS_DATA_REQ          0x9330
120 #define MMSMS_DATA_IND          0x9332
121 #define MMSMS_UNIT_DATA_REQ     0x9340
122 #define MMSMS_UNIT_DATA_IND     0x9342
123 #define MMSMS_REEST_REQ         0x9360
124 #define MMSMS_REEST_CNF         0x9361
125 #define MMSMS_ERR_IND           0x9372
126 #define MMSMS_PROMPT_IND        0x9382
127 #define MMSMS_PROMPT_REJ        0x9384
128
129 /* GSM 04.07 9.1.1 */
130 #define GSM_RRSTATE_IDLE                0
131 #define GSM_RRSTATE_CONN_PEND           1
132 #define GSM_RRSTATE_DEDICATED           2
133
134 /* GSM 04.07 6.1.1 */
135 #define GSM_MMRSTATE_NOTUPDATED         0
136 #define GSM_MMRSTATE_WAIT               1
137 #define GSM_MMRSTATE_UPDATED            2
138
139 /* GSM 04.07 9.2.1 */
140 #define GSM_MMCCSTATE_IDLE              0
141 #define GSM_MMCCSTATE_CONN_PEND         1
142 #define GSM_MMCCSTATE_DEDICATED         2
143 #define GSM_MMCCSTATE_CONN_SUSP         3
144 #define GSM_MMCCSTATE_REESTPEND         4
145 #define GSM_MMSSSTATE_IDLE              0
146 #define GSM_MMSSSTATE_CONN_PEND         1
147 #define GSM_MMSSSTATE_DEDICATED         2
148 #define GSM_MMSSSTATE_CONN_SUSP         3
149 #define GSM_MMSSSTATE_REESTPEND         4
150 #define GSM_MMSMSSTATE_IDLE             0
151 #define GSM_MMSMSSTATE_CONN_PEND        1
152 #define GSM_MMSMSSTATE_DEDICATED        2
153 #define GSM_MMSMSSTATE_CONN_SUSP        3
154 #define GSM_MMSMSSTATE_REESTPEND        4
155
156 /* GSM 04.08 4.1.2.1 */
157 #define GSM_MMSTATE_NULL                0
158 #define GSM_MMSTATE_LOC_UPD_INIT        3
159 #define GSM_MMSTATE_WAIT_OUT_MM_CONN    5
160 #define GSM_MMSTATE_MM_CONN_ACTIVE      6
161 #define GSM_MMSTATE_IMSI_DETACH_INIT    7
162 #define GSM_MMSTATE_PROCESS_CM_SERV_P   8
163 #define GSM_MMSTATE_WAIT_NETWORK_CMD    9
164 #define GSM_MMSTATE_LOC_UPD_REJ         10
165 #define GSM_MMSTATE_WAIT_RR_CONN_LUPD   13
166 #define GSM_MMSTATE_WAIT_RR_CONN_MM_CON 14
167 #define GSM_MMSTATE_WAIT_RR_CONN_IMSI_D 15
168 #define GSM_MMSTATE_WAIT_REEST          17
169 #define GSM_MMSTATE_WAIT_RR_ACTIVE      18
170 #define GSM_MMSTATE_MM_IDLE             19
171 #define GSM_MMSTATE_WAIT_ADD_OUT_MM_CON 20
172 #define GSM_MMSTATE_MM_CONN_ACTIVE_VGCS 21
173 #define GSM_MMSTATE_WAIT_RR_CONN_VGCS   22
174 #define GSM_MMSTATE_LOC_UPD_PEND        23
175 #define GSM_MMSTATE_IMSI_DETACH_PEND    24
176 #define GSM_MMSTATE_RR_CONN_RELEASE_NA  25
177
178 /* GSM 04.08 4.1.2.1 */
179 #define GSM_MMIDLESS_NORMAL_SERVICE     1
180 #define GSM_MMIDLESS_ATTEMPT_UPDATE     2
181 #define GSM_MMIDLESS_LIMITED_SERVICE    3
182 #define GSM_MMIDLESS_NO_IMSI            4
183 #define GSM_MMIDLESS_NO_CELL_AVAIL      5
184 #define GSM_MMIDLESS_LOC_UPD_NEEDED     6
185 #define GSM_MMIDLESS_PLMN_SEARCH        7
186 #define GSM_MMIDLESS_PLMN_SEARCH_NORMAL 8
187 #define GSM_MMIDLESS_RX_VGCS_NORMAL     9
188 #define GSM_MMIDLESS_RX_VGCS_LIMITED    10
189
190 /* GSM 04.08 4.1.2.2 */
191 #define GSM_MMUSTATE_U1_UPDATED         1
192 #define GSM_MMUSTATE_U2_NOT_UPDATED     2
193 #define GSM_MMUSTATE_U3_ROAMING_NA      3
194
195 /* GSM 04.08 5.1.2.2 */
196 #define GSM_CCSTATE_NULL                0
197 #define GSM_CCSTATE_INITIATED           1
198 #define GSM_CCSTATE_MO_CALL_PROC        3
199 #define GSM_CCSTATE_CALL_DELIVERED      4
200 #define GSM_CCSTATE_CALL_PRESENT        6
201 #define GSM_CCSTATE_CALL_RECEIVED       7
202 #define GSM_CCSTATE_CONNECT_REQUEST     8
203 #define GSM_CCSTATE_MO_TERM_CALL_CONF   9
204 #define GSM_CCSTATE_ACTIVE              10
205 #define GSM_CCSTATE_DISCONNECT_REQ      12
206 #define GSM_CCSTATE_DISCONNECT_IND      12
207 #define GSM_CCSTATE_RELEASE_REQ         19
208 #define GSM_CCSTATE_MO_ORIG_MODIFY      26
209 #define GSM_CCSTATE_MO_TERM_MODIFY      27
210 #define GSM_CCSTATE_CONNECT_IND         28
211
212 /* MM events */
213 #define MMEVENT_NEW_LAI                 0xa001
214 #define MMEVENT_TIMEOUT_T3211           0xa002
215 #define MMEVENT_TIMEOUT_T3212           0xa003
216 #define MMEVENT_TIMEOUT_T3213           0xa004
217 #define MMEVENT_IMSI_DETACH             0xa005
218 #define MMEVENT_IMSI_ATTACH             0xa006
219 #define MMEVENT_POWER_OFF               0xa007
220 #define MMEVENT_PAGING                  0xa009
221 #define MMEVENT_AUTH_RESPONSE           0xa00a
222
223 struct gsm_mmevent {
224         u_int32_t       msg_type;
225
226         u_int8_t        sres[4];
227 };
228
229 /* GSM 04.08 MM timers */
230 #define GSM_T3210_MS    20, 0
231 #define GSM_T3211_MS    15, 0
232 // T3212 is given by SYSTEM INFORMATION
233 #define GSM_T3213_MS    4, 0
234 #define GSM_T3220_MS    5, 0
235 #define GSM_T3230_MS    15, 0
236 #define GSM_T3240_MS    10, 0
237 #define GSM_T3241_MS    300, 0
238
239
240 /* MM sublayer instance */
241 struct gsm_mmlayer {
242         struct osmocom_ms       *ms;
243         int                     state;
244         int                     substate;
245         int                     update_state;
246         struct timer_list       t3211;
247         struct timer_list       t3212;
248         struct timer_list       t3213;
249         int                     t3212_value;
250 };
251
252 /* GSM 04.08 RR timers */
253 #define GSM_T3126_MS    5, 0
254
255 struct gsm_rr_chan_desc {
256         struct gsm48_chan_desc  chan_desc;
257         uint8_t                 power_command;
258         uint8_t                 frq_list_before[131];
259         uint8_t                 frq_list_after[131];
260         uint8_t                 cell_chan_desc[16];
261         uint8_t                 ...
262         uint8_t
263         uint8_t
264 };
265
266 /* RR sublayer instance */
267 struct gsm_rrlayer {
268         struct osmocom_ms       *ms;
269         int                     state;
270
271         struct timer_list       t3122;
272         struct timer_list       t3124;
273         struct timer_list       t3126;
274         int                     t3126_value;
275
276         /* states if RR-EST-REQ was used */
277         int                     rr_est_req;
278         struct msgb             *rr_est_msg;
279
280         /* channel request states */
281         u_int8_t                chan_req;
282         /* cr_hist must be signed and greater 8 bit */
283         int                     cr_hist[3];
284
285         /* collection of all channel descriptions */
286         struct gsm_rr_chan_desc chan_desc;
287
288         /* special states when changing channel */
289         int                     hando_susp_state;
290         int                     assign_susp_state;
291         int                     resume_last_state;
292         struct gsm_rr_chan_desc chan_last;
293
294 };
295
296 #define RR_EST_CAUSE_EMERGENCY          1
297 #define RR_EST_CAUSE_REESTAB_TCH_F      2
298 #define RR_EST_CAUSE_REESTAB_TCH_H      3
299 #define RR_EST_CAUSE_REESTAB_2_TCH_H    4
300 #define RR_EST_CAUSE_ANS_PAG_ANY        5
301 #define RR_EST_CAUSE_ANS_PAG_SDCCH      6
302 #define RR_EST_CAUSE_ANS_PAG_TCH_F      7
303 #define RR_EST_CAUSE_ANS_PAG_TCH_ANY    8
304 #define RR_EST_CAUSE_ORIG_TCHF          9
305 #define RR_EST_CAUSE_LOC_UPD            12
306 #define RR_EST_CAUSE_OTHER_SDCCH        13
307
308 #define RR_REL_CAUSE_UNDEFINED          0
309 #define RR_REL_CAUSE_NOT_AUTHORIZED     1
310 #define RR_REL_CAUSE_RA_FAILURE         2
311
312
313