aboutsummaryrefslogtreecommitdiffstats
path: root/include/osmocom/bsc/gsm_timers.h
blob: 78f04edd9f17cf7b603baf95d5ebf354acd31e1a (plain)
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
/* API to define Tnnn timers globally, configure in VTY and use for FSM state changes. */
#pragma once

#include <stdint.h>
#include <osmocom/core/utils.h>

struct osmo_fsm_inst;
struct vty;

enum T_unit {
	T_S = 0,	/*< most T are in seconds, keep 0 as default. */
	T_MS,		/*< milliseconds */
	T_M,		/*< minutes */
	T_CUSTOM,
};

extern const struct value_string T_unit_names[];
static inline const char *T_unit_name(enum T_unit val)
{ return get_value_string(T_unit_names, val); }

/* Define a GSM timer of the form Tnnn, with unit, default value and doc string. */
struct T_def {
	const int T; /*< T1234 number */
	const int default_val; /*< timeout duration (according to unit), default value. */
	const enum T_unit unit;
	const char *desc;
	int val; /*< currently active value, e.g. set by user config. */
};

/* Iterate an array of struct T_def, the last item should be fully zero, i.e. "{}" */
#define for_each_T_def(d, T_defs) \
	for (d = T_defs; d && (d->T || d->default_val || d->desc); d++)

int T_def_get(const struct T_def *T_defs, int T, enum T_unit as_unit, int val_if_not_present);
void T_defs_reset(struct T_def *T_defs);
struct T_def *T_def_get_entry(struct T_def *T_defs, int T);

void T_defs_vty_init(struct T_def *T_defs, int cfg_parent_node);
void T_defs_vty_write(struct vty *vty, const char *indent);


struct state_timeout {
	int T;
	bool keep_timer;
};

const struct state_timeout *get_state_timeout(uint32_t state,
					      const struct state_timeout *timeouts_array);

#define fsm_inst_state_chg_T(fi, state, timeouts_array, T_defs, default_timeout) \
	_fsm_inst_state_chg_T(fi, state, timeouts_array, T_defs, default_timeout, \
			      __FILE__, __LINE__)
int _fsm_inst_state_chg_T(struct osmo_fsm_inst *fi, uint32_t state,
			  const struct state_timeout *timeouts_array,
			  const struct T_def *T_defs, int default_timeout,
			  const char *file, int line);