summaryrefslogtreecommitdiffstats
path: root/src/host/layer23/include/osmocom/bb/mobile/primitives.h
blob: 39b4945405ba9fa2772a0eed76fe0d7b4b92e5e2 (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
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
#pragma once

#include <osmocom/bb/mobile/gsm411_sms.h>

#include <osmocom/core/prim.h>

struct mobile_prim;

/**
 * Mobile Script<->App primitives. Application script will receive
 * indications and will send primitives to the lower layers. Here
 * we will convert from internal state/events to the primitives. In
 * the future the indications might be generated at lower levels
 * directly.
 */
enum mobile_prims {
	PRIM_MOB_TIMER,
	PRIM_MOB_TIMER_CANCEL,
	PRIM_MOB_STARTED,
	PRIM_MOB_SHUTDOWN,
	PRIM_MOB_SMS,
	PRIM_MOB_MM,
};

struct mobile_prim_intf {
	struct osmocom_ms *ms;
	void (*indication)(struct mobile_prim_intf *, struct mobile_prim *prim);

	/* Internal state */
	struct llist_head entry;
	struct llist_head timers;
};

/**
 * Primitive to create timers and get indication once they have
 * expired. Currently there is no way to cancel timers.
 */
struct mobile_timer_param {
	uint64_t timer_id;	  	/*!< Unique Id identifying the timer */
	int seconds;			/*!< Seconds the timer should fire in */
};

/**
 * Primitive to indicate starting of the mobile.
 */
struct mobile_started_param {
	bool started;
};

/**
 * Primitive to indicate shutdown of the mobile. It will go through
 * various states.
 */
struct mobile_shutdown_param {
	int old_state;
	int new_state;
};

/**
 * SMS related configs.
 */
struct mobile_sms_param {
	struct gsm_sms sms;

	bool cause_valid;
	int cause;
};

/**
 * Mobility Management (MM) state changes.
 */
struct mobile_mm_param {
	int state;			/*!< The new MM state */
	int substate;			/*!< The current substate */
	int prev_substate;		/*!< The previous substate */
};

struct mobile_prim {
	struct osmo_prim_hdr hdr;	/*!< Primitive base class */
	union {
		struct mobile_timer_param timer;
		struct mobile_started_param started;
		struct mobile_shutdown_param shutdown;
		struct mobile_sms_param sms;
		struct mobile_mm_param mm;
	} u;
};


struct mobile_prim_intf *mobile_prim_intf_alloc(struct osmocom_ms *ms);
int mobile_prim_intf_req(struct mobile_prim_intf *intf, struct mobile_prim *hdr);
void mobile_prim_intf_free(struct mobile_prim_intf *intf);

struct mobile_prim *mobile_prim_alloc(unsigned int primitive, enum osmo_prim_operation op);

void mobile_prim_ntfy_started(struct osmocom_ms *ms, bool started);
void mobile_prim_ntfy_shutdown(struct osmocom_ms *ms, int old_state, int new_state);
void mobile_prim_ntfy_sms_new(struct osmocom_ms *ms, struct gsm_sms *sms);
void mobile_prim_ntfy_sms_status(struct osmocom_ms *ms, struct gsm_sms *sms, uint8_t cause);
void mobile_prim_ntfy_mm_status(struct osmocom_ms *ms, int state, int subs, int old_subs);