File size: 7,097 Bytes
258fb37
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
/*
 * Copyright (C) 2019 by Sukchan Lee <acetcom@gmail.com>
 *
 * This file is part of Open5GS.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <https://www.gnu.org/licenses/>.
 */

#include "mme-timer.h"
#include "mme-event.h"
#include "mme-context.h"

static mme_timer_cfg_t g_mme_timer_cfg[MAX_NUM_OF_MME_TIMER] = {
    /* Paging procedure for EPS services initiated */
    [MME_TIMER_T3413] =
        { .have = true, .max_count = 2, .duration = ogs_time_from_sec(2) },

    /* DETACH REQUEST sent */
    [MME_TIMER_T3422] =
        { .have = true, .max_count = 4, .duration = ogs_time_from_sec(3) },

    /* ATTACH ACCEPT sent
     * TRACKING AREA UPDATE ACCEPT sent with GUTI
     * TRACKING AREA UPDATE ACCEPT sent with TMSI
     * GUTI REALLOCATION COMMAND sent */
    [MME_TIMER_T3450] =
        { .have = true, .max_count = 4, .duration = ogs_time_from_sec(6) },

    /* AUTHENTICATION REQUEST sent
     * SECURITY MODE COMMAND sent */
    [MME_TIMER_T3460] =
        { .have = true, .max_count = 4, .duration = ogs_time_from_sec(3) },

    /* IDENTITY REQUEST sent */
    [MME_TIMER_T3470] =
        { .have = true, .max_count = 4, .duration = ogs_time_from_sec(3) },

    /* ESM INFORMATION REQUEST sent */
    [MME_TIMER_T3489] =
        { .have = true, .max_count = 2, .duration = ogs_time_from_sec(4) },

    [MME_TIMER_SGS_CLI_CONN_TO_SRV] =
        { .have = true, .duration = ogs_time_from_sec(3) },

    [MME_TIMER_S1_HOLDING] =
        { .have = true, .duration = ogs_time_from_sec(30) },

    [MME_TIMER_S11_HOLDING] =
        { .have = true, .duration = ogs_time_from_msec(300) },

    [MME_TIMER_GN_HOLDING] =
        { .have = true, .duration = ogs_time_from_sec(20) },
};

mme_timer_cfg_t *mme_timer_cfg(mme_timer_e id)
{
    ogs_assert(id < MAX_NUM_OF_MME_TIMER);
    if (g_mme_timer_cfg[id].have != true) {
        ogs_fatal("No timer[%d] configuration", id);
        ogs_assert_if_reached();
    }
    return &g_mme_timer_cfg[id];
}

const char *mme_timer_get_name(mme_timer_e id)
{
    switch (id) {
    case MME_TIMER_S1_DELAYED_SEND:
        return "MME_TIMER_S1_DELAYED_SEND";
    case MME_TIMER_T3413:
        return "MME_TIMER_T3413";
    case MME_TIMER_T3422:
        return "MME_TIMER_T3422";
    case MME_TIMER_T3450:
        return "MME_TIMER_T3450";
    case MME_TIMER_T3460:
        return "MME_TIMER_T3460";
    case MME_TIMER_T3470:
        return "MME_TIMER_T3470";
    case MME_TIMER_T3489:
        return "MME_TIMER_T3489";
    case MME_TIMER_MOBILE_REACHABLE:
        return "MME_TIMER_MOBILE_REACHABLE";
    case MME_TIMER_IMPLICIT_DETACH:
        return "MME_TIMER_IMPLICIT_DETACH";
    case MME_TIMER_SGS_CLI_CONN_TO_SRV:
        return "MME_TIMER_SGS_CLI_CONN_TO_SRV";
    case MME_TIMER_S1_HOLDING:
        return "MME_TIMER_S1_HOLDING";
    case MME_TIMER_S11_HOLDING:
        return "MME_TIMER_S11_HOLDING";
    default:
       break;
    }

    return "UNKNOWN_TIMER";
}

void mme_timer_s1_delayed_send(void *data)
{
    int rv;
    mme_event_t *e = data;
    ogs_assert(e);

    e->timer_id = MME_TIMER_S1_DELAYED_SEND;

    rv = ogs_queue_push(ogs_app()->queue, e);
    if (rv != OGS_OK) {
        ogs_error("ogs_queue_push() failed:%d", (int)rv);
        ogs_timer_delete(e->timer);
        mme_event_free(e);
    }
}


static void emm_timer_event_send(mme_timer_e timer_id, void *data)
{
    int rv;
    mme_event_t *e = NULL;

    ogs_assert(data);

    e = mme_event_new(MME_EVENT_EMM_TIMER);
    e->timer_id = timer_id;
    e->mme_ue_id = OGS_POINTER_TO_UINT(data);

    rv = ogs_queue_push(ogs_app()->queue, e);
    if (rv != OGS_OK) {
        ogs_error("ogs_queue_push() failed:%d", (int)rv);
        mme_event_free(e);
    }
}

void mme_timer_t3413_expire(void *data)
{
    emm_timer_event_send(MME_TIMER_T3413, data);
}
void mme_timer_t3422_expire(void *data)
{
    emm_timer_event_send(MME_TIMER_T3422, data);
}
void mme_timer_t3450_expire(void *data)
{
    emm_timer_event_send(MME_TIMER_T3450, data);
}
void mme_timer_t3460_expire(void *data)
{
    emm_timer_event_send(MME_TIMER_T3460, data);
}
void mme_timer_t3470_expire(void *data)
{
    emm_timer_event_send(MME_TIMER_T3470, data);
}
void mme_timer_mobile_reachable_expire(void *data)
{
    emm_timer_event_send(MME_TIMER_MOBILE_REACHABLE, data);
}
void mme_timer_implicit_detach_expire(void *data)
{
    emm_timer_event_send(MME_TIMER_IMPLICIT_DETACH, data);
}

static void esm_timer_event_send(mme_timer_e timer_id, void *data)
{
    int rv;
    mme_event_t *e = NULL;

    ogs_assert(data);

    e = mme_event_new(MME_EVENT_ESM_TIMER);
    e->timer_id = timer_id;
    e->bearer_id = OGS_POINTER_TO_UINT(data);

    rv = ogs_queue_push(ogs_app()->queue, e);
    if (rv != OGS_OK) {
        ogs_error("ogs_queue_push() failed:%d", (int)rv);
        mme_event_free(e);
    }
}

void mme_timer_t3489_expire(void *data)
{
    esm_timer_event_send(MME_TIMER_T3489, data);
}

void mme_timer_sgs_cli_conn_to_srv(void *data)
{
    int rv;
    mme_event_t *e = NULL;
    ogs_assert(data);

    e = mme_event_new(MME_EVENT_SGSAP_TIMER);
    e->timer_id = MME_TIMER_SGS_CLI_CONN_TO_SRV;
    e->vlr = data;

    rv = ogs_queue_push(ogs_app()->queue, e);
    if (rv != OGS_OK) {
        ogs_error("ogs_queue_push() failed:%d", (int)rv);
        mme_event_free(e);
    }
}

void mme_timer_s1_holding_timer_expire(void *data)
{
    int rv;
    mme_event_t *e = NULL;

    ogs_assert(data);

    e = mme_event_new(MME_EVENT_S1AP_TIMER);

    e->timer_id = MME_TIMER_S1_HOLDING;
    e->enb_ue_id = OGS_POINTER_TO_UINT(data);

    rv = ogs_queue_push(ogs_app()->queue, e);
    if (rv != OGS_OK) {
        ogs_error("ogs_queue_push() failed:%d", (int)rv);
        mme_event_free(e);
    }
}

void mme_timer_s11_holding_timer_expire(void *data)
{
    int rv;
    mme_event_t *e = NULL;

    ogs_assert(data);

    e = mme_event_new(MME_EVENT_S11_TIMER);

    e->timer_id = MME_TIMER_S11_HOLDING;
    e->sgw_ue_id = OGS_POINTER_TO_UINT(data);

    rv = ogs_queue_push(ogs_app()->queue, e);
    if (rv != OGS_OK) {
        ogs_error("ogs_queue_push() failed:%d", (int)rv);
        mme_event_free(e);
    }
}

void mme_timer_gn_holding_timer_expire(void *data)
{
    int rv;
    mme_event_t *e = NULL;

    ogs_assert(data);

    e = mme_event_new(MME_EVENT_GN_TIMER);

    e->timer_id = MME_TIMER_GN_HOLDING;
    e->mme_ue_id = OGS_POINTER_TO_UINT(data);

    rv = ogs_queue_push(ogs_app()->queue, e);
    if (rv != OGS_OK) {
        ogs_error("ogs_queue_push() failed:%d", (int)rv);
        mme_event_free(e);
    }
}