annotate mncc/gsm_call.c @ 2:053f04687106

mncc: initial import from old ThemWi
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 08 Jun 2024 23:12:12 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement allocation, freeing and retrieval
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * of gsm_call structures.
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdio.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdint.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <strings.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <syslog.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include "struct.h"
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "gsm_call.h"
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 struct gsm_call *call_list_head;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 static uint32_t mt_callref;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 struct gsm_call *
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 find_gsm_callref(callref)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 uint32_t callref;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 struct gsm_call *call;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 for (call = call_list_head; call; call = call->next) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (call->gc_flag)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 continue;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if (call->callref == callref)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 return call;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return 0;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 struct gsm_call *
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 find_socket_call(conn, ref)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 struct socket_conn *conn;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 uint32_t ref;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 struct gsm_call *call;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 for (call = call_list_head; call; call = call->next) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (call->gc_flag)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 continue;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (call->socket == conn && call->socket_ref == ref)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 return call;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 return 0;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 struct gsm_call *
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 create_gsm_call(callref)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 uint32_t callref;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 struct gsm_call *call;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 call = malloc(sizeof(struct gsm_call));
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 if (call) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 bzero(call, sizeof(struct gsm_call));
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 call->callref = callref;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 call->next = call_list_head;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 call_list_head = call;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 return call;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 uint32_t
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 alloc_mt_callref()
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 mt_callref++;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if (mt_callref > 0x7FFFFFFF)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 mt_callref = 1;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 return mt_callref;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 struct gsm_call *
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 create_new_mt_call()
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 uint32_t callref;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 for (;;) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 callref = alloc_mt_callref();
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 if (!find_gsm_callref(callref))
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 syslog(LOG_DEBUG, "creating new MT callref 0x%x", callref);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 return create_gsm_call(callref);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 gc_call_list()
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 struct gsm_call *call, **cp;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 for (cp = &call_list_head; call = *cp; ) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 if (call->gc_flag) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 *cp = call->next;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 free(call);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 continue;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 cp = &call->next;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 }