summaryrefslogtreecommitdiff
path: root/src/util/event.c
blob: 014abda43a8dab99175d511e9407ad433601a794 (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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include <stdio.h>
#include <string.h>

#include <common/linux_list.h>
#include <libgsmd/libgsmd.h>
#include <libgsmd/event.h>

static int incall_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux)
{
	printf("EVENT: Incoming call type = %u\n", aux->u.call.type);

	return 0;
}

static int clip_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux)
{
	printf("EVENT: Incoming call clip = %s\n", aux->u.clip.addr.number);

	return 0;
}

static int colp_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux)
{
	printf("EVENT: Outgoing call colp = %s\n", aux->u.colp.addr.number);

	return 0;
}

static int netreg_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux)
{
	printf("EVENT: Netreg ");

	switch (aux->u.netreg.state) {
	case 0:
		printf("not searching for network ");
		break;
	case 1:
		printf("registered (home network) ");
		break;
	case 2:
		printf("searching for network ");
		break;
	case 3:
		printf("registration denied ");
		break;
	case 5:
		printf("registered (roaming) ");
		break;
	}

	if (aux->u.netreg.lac)
		printf("LocationAreaCode = 0x%04X ", aux->u.netreg.lac);
	if (aux->u.netreg.ci)
		printf("CellID = 0x%04X ", aux->u.netreg.ci);
	
	printf("\n");

	return 0;
}

static int sigq_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux)
{
	printf("EVENT: Signal Quality: %u\n", aux->u.signal.sigq.rssi);
	return 0;
}

static const char *cprog_names[] = {
	[GSMD_CALLPROG_SETUP]		= "SETUP",
	[GSMD_CALLPROG_DISCONNECT]	= "DISCONNECT",
	[GSMD_CALLPROG_ALERT]		= "ALERT",
	[GSMD_CALLPROG_CALL_PROCEED]	= "PROCEED",
	[GSMD_CALLPROG_SYNC]		= "SYNC",
	[GSMD_CALLPROG_PROGRESS]	= "PROGRESS",
	[GSMD_CALLPROG_CONNECTED]	= "CONNECTED",
	[GSMD_CALLPROG_RELEASE]		= "RELEASE",
	[GSMD_CALLPROG_REJECT]		= "REJECT",
	[GSMD_CALLPROG_UNKNOWN]		= "UNKNOWN",
};

static const char *cdir_names[] = {
	[GSMD_CALL_DIR_MO]		= "Outgoing",
	[GSMD_CALL_DIR_MT]		= "Incoming",
	[GSMD_CALL_DIR_CCBS]		= "CCBS",
	[GSMD_CALL_DIR_MO_REDIAL]	= "Outgoing Redial",
};

static int cprog_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux)
{
	const char *name, *dir;

	if (aux->u.call_status.prog >= ARRAY_SIZE(cprog_names))
		name = "UNDEFINED";
	else
		name = cprog_names[aux->u.call_status.prog];

	if (aux->u.call_status.dir >= ARRAY_SIZE(cdir_names))
		dir = "";
	else
		dir = cdir_names[aux->u.call_status.dir];

	printf("EVENT: %s Call Progress: %s\n", dir, name);

	return 0;
}

int event_init(struct lgsm_handle *lh)
{
	int rc;

	rc  = lgsm_evt_handler_register(lh, GSMD_EVT_IN_CALL, &incall_handler);
	rc |= lgsm_evt_handler_register(lh, GSMD_EVT_IN_CLIP, &clip_handler);
	rc |= lgsm_evt_handler_register(lh, GSMD_EVT_OUT_COLP, &colp_handler);
	rc |= lgsm_evt_handler_register(lh, GSMD_EVT_NETREG, &netreg_handler);
	rc |= lgsm_evt_handler_register(lh, GSMD_EVT_SIGNAL, &sigq_handler);
	rc |= lgsm_evt_handler_register(lh, GSMD_EVT_OUT_STATUS, &cprog_handler);

	return rc;
}

personal git repositories of Harald Welte. Your mileage may vary