blob: 3bf701a40359ecdd78051d19f83194f375b0c239 [file] [log] [blame]
Pau Espin Pedroldc2aaac2021-05-14 12:50:46 +02001/* tbf_fsm.c
2 *
3 * Copyright (C) 2021 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
4 * Author: Pau Espin Pedrol <pespin@sysmocom.de>
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (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
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 */
20
21#include <unistd.h>
22
23#include <talloc.h>
24
25#include <tbf_fsm.h>
26#include <gprs_rlcmac.h>
27#include <gprs_debug.h>
28#include <gprs_ms.h>
29#include <encoding.h>
30#include <bts.h>
31
32#define X(s) (1 << (s))
33
34const struct osmo_tdef_state_timeout tbf_fsm_timeouts[32] = {
35 [TBF_ST_NULL] = {},
36 [TBF_ST_ASSIGN] = { },
37 [TBF_ST_FLOW] = { },
38 [TBF_ST_FINISHED] = {},
39 [TBF_ST_WAIT_RELEASE] = {},
40 [TBF_ST_RELEASING] = {},
41};
42
43const struct value_string tbf_fsm_event_names[] = {
44 { TBF_EV_FOOBAR, "FOOBAR" },
45 { 0, NULL }
46};
47
48static void tbf_fsm_cleanup(struct osmo_fsm_inst *fi, enum osmo_fsm_term_cause cause)
49{
50 /* TODO: needed ?
51 * struct tbf_fsm_ctx *ctx = (struct tbf_fsm_ctx *)fi->priv;
52 */
53}
54
55static int tbf_fsm_timer_cb(struct osmo_fsm_inst *fi)
56{
57 switch (fi->T) {
58 default:
59 break;
60 }
61 return 0;
62}
63
64static struct osmo_fsm_state tbf_fsm_states[] = {
65 [TBF_ST_NULL] = {
66 .in_event_mask =
67 0,
68 .out_state_mask =
69 X(TBF_ST_ASSIGN) |
70 X(TBF_ST_FLOW) |
71 X(TBF_ST_RELEASING),
72 .name = "NULL",
73 //.action = st_null,
74 },
75 [TBF_ST_ASSIGN] = {
76 .in_event_mask =
77 0,
78 .out_state_mask =
79 X(TBF_ST_FLOW) |
80 X(TBF_ST_FINISHED) |
81 X(TBF_ST_RELEASING),
82 .name = "ASSIGN",
83 //.onenter = st_assign_on_enter,
84 //.action = st_assign,
85 },
86 [TBF_ST_FLOW] = {
87 .in_event_mask =
88 0,
89 .out_state_mask =
90 X(TBF_ST_FINISHED) |
91 X(TBF_ST_WAIT_RELEASE) |
92 X(TBF_ST_RELEASING),
93 .name = "FLOW",
94 //.onenter = st_flow_on_enter,
95 //.action = st_flow,
96 },
97 [TBF_ST_FINISHED] = {
98 .in_event_mask =
99 0,
100 .out_state_mask =
101 X(TBF_ST_WAIT_RELEASE),
102 .name = "FINISHED",
103 //.onenter = st_finished_on_enter,
104 //.action = st_finished,
105 },
106 [TBF_ST_WAIT_RELEASE] = {
107 .in_event_mask =
108 0,
109 .out_state_mask =
110 X(TBF_ST_RELEASING),
111 .name = "WAIT_RELEASE",
112 //.action = st_wait_release,
113 },
114 [TBF_ST_RELEASING] = {
115 .in_event_mask =
116 0,
117 .out_state_mask =
118 0,
119 .name = "RELEASING",
120 //.action = st_releasing,
121 },
122};
123
124struct osmo_fsm tbf_fsm = {
125 .name = "TBF",
126 .states = tbf_fsm_states,
127 .num_states = ARRAY_SIZE(tbf_fsm_states),
128 .timer_cb = tbf_fsm_timer_cb,
129 .cleanup = tbf_fsm_cleanup,
130 .log_subsys = DTBF,
131 .event_names = tbf_fsm_event_names,
132};
133
134static __attribute__((constructor)) void tbf_fsm_init(void)
135{
136 OSMO_ASSERT(osmo_fsm_register(&tbf_fsm) == 0);
137}