FreeCalypso > hg > themwi-system-sw
comparison mncc/gsm_call.c @ 15:ccc5ab6d8388
first version of themwi-mncc for ThemWi2
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 26 Jun 2022 16:31:47 -0800 |
parents | |
children | 660126bd5f59 |
comparison
equal
deleted
inserted
replaced
14:aea422af79dd | 15:ccc5ab6d8388 |
---|---|
1 /* | |
2 * In this module we implement allocation, freeing and retrieval | |
3 * of gsm_call structures. | |
4 */ | |
5 | |
6 #include <sys/types.h> | |
7 #include <stdio.h> | |
8 #include <stdint.h> | |
9 #include <stdlib.h> | |
10 #include <string.h> | |
11 #include <strings.h> | |
12 #include <syslog.h> | |
13 #include "struct.h" | |
14 #include "gsm_call.h" | |
15 | |
16 struct gsm_call *call_list_head; | |
17 | |
18 static uint32_t mt_callref; | |
19 | |
20 struct gsm_call * | |
21 find_gsm_callref(callref) | |
22 uint32_t callref; | |
23 { | |
24 struct gsm_call *call; | |
25 | |
26 for (call = call_list_head; call; call = call->next) { | |
27 if (call->gc_flag) | |
28 continue; | |
29 if (call->callref == callref) | |
30 return call; | |
31 } | |
32 return 0; | |
33 } | |
34 | |
35 struct gsm_call * | |
36 find_socket_call(conn, ref) | |
37 struct socket_conn *conn; | |
38 uint32_t ref; | |
39 { | |
40 struct gsm_call *call; | |
41 | |
42 for (call = call_list_head; call; call = call->next) { | |
43 if (call->gc_flag) | |
44 continue; | |
45 if (call->socket == conn && call->socket_ref == ref) | |
46 return call; | |
47 } | |
48 return 0; | |
49 } | |
50 | |
51 struct gsm_call * | |
52 create_gsm_call(callref) | |
53 uint32_t callref; | |
54 { | |
55 struct gsm_call *call; | |
56 | |
57 call = malloc(sizeof(struct gsm_call)); | |
58 if (call) { | |
59 bzero(call, sizeof(struct gsm_call)); | |
60 call->callref = callref; | |
61 call->next = call_list_head; | |
62 call_list_head = call; | |
63 } | |
64 return call; | |
65 } | |
66 | |
67 uint32_t | |
68 alloc_mt_callref() | |
69 { | |
70 mt_callref++; | |
71 if (mt_callref > 0x7FFFFFFF) | |
72 mt_callref = 1; | |
73 return mt_callref; | |
74 } | |
75 | |
76 struct gsm_call * | |
77 create_new_mt_call() | |
78 { | |
79 uint32_t callref; | |
80 | |
81 for (;;) { | |
82 callref = alloc_mt_callref(); | |
83 if (!find_gsm_callref(callref)) | |
84 break; | |
85 } | |
86 return create_gsm_call(callref); | |
87 } | |
88 | |
89 gc_call_list() | |
90 { | |
91 struct gsm_call *call, **cp; | |
92 | |
93 for (cp = &call_list_head; call = *cp; ) { | |
94 if (call->gc_flag) { | |
95 *cp = call->next; | |
96 free(call); | |
97 continue; | |
98 } | |
99 cp = &call->next; | |
100 } | |
101 } |