annotate mncc/call_setup.c @ 167:2ebad02adbe5

themwi-mncc: route outbound calls to themwi-sip-out
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 12 Oct 2022 18:08:34 -0800
parents 660126bd5f59
children 59a166c50d0e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement setup of new calls: either new MO calls
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * coming from GSM or new MT calls coming from a ThemWi call socket.
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <sys/socket.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdint.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <string.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <strings.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <syslog.h>
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "../include/mncc.h"
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "../include/gsm48_const.h"
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "struct.h"
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "gsm_call.h"
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 preen_msc_provided_number(nums)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 struct gsm_mncc_number *nums;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 int len;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 len = grok_number_string(nums->number, 0);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 switch (len) {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 case 4:
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 nums->type = GSM48_TON_NET_SPEC;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 nums->plan = GSM48_NPI_PRIVATE;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 break;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 case 11:
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 if (nums->number[0] != '1')
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return(0);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 nums->type = GSM48_TON_INTERNATIONAL;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 nums->plan = GSM48_NPI_ISDN_E164;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 break;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 default:
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 return(0);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 nums->screen = GSM48_SCRN_NETWORK;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 return(1);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 void
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 reject_mo_call(callref, cause_loc, cause_val)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 uint32_t callref;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 struct gsm_mncc msg;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 bzero(&msg, sizeof(struct gsm_mncc));
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 msg.msg_type = MNCC_REJ_REQ;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 msg.callref = callref;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 mncc_set_cause(&msg, cause_loc, cause_val);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 send_mncc_to_gsm(&msg, sizeof(struct gsm_mncc));
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 void
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 process_mo_call_setup(msg)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 struct gsm_mncc *msg;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 struct gsm_call *call;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 char nanp[11];
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 int res, is_nanp, is_itn, is_local;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 if (preen_msc_provided_number(&msg->calling))
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 msg->fields |= MNCC_F_CALLING;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 else
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 msg->fields &= ~MNCC_F_CALLING;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 if (!(msg->fields & MNCC_F_CALLED)) {
28
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
69 syslog(LOG_ERR, "rejecting MO call 0x%x: no called number",
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
70 msg->callref);
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 GSM48_CC_CAUSE_INVAL_MAND_INF);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 return;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 call = create_gsm_call(msg->callref);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (!call) {
28
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
77 syslog(LOG_ERR, "rejecting MO call 0x%x: no memory for call",
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
78 msg->callref);
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 return;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 /* route based on destination address */
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 refresh_number_db();
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 is_nanp = is_itn = 0;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 switch (grok_number_string(msg->called.number, 0)) {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 case 4:
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 if (msg->called.type != GSM48_TON_UNKNOWN &&
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 msg->called.type != GSM48_TON_NET_SPEC &&
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 msg->called.type != GSM48_TON_SHORT_CODE)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 break;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 if (msg->called.plan != GSM48_NPI_UNKNOWN &&
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 msg->called.plan != GSM48_NPI_ISDN_E164 &&
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 msg->called.plan != GSM48_NPI_PRIVATE)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 break;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 res = lookup_short_dial_number(msg->called.number, nanp);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 if (!res) {
28
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
98 syslog(LOG_ERR,
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
99 "rejecting MO call 0x%x: invalid short number",
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
100 msg->callref);
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 GSM48_CC_CAUSE_UNASSIGNED_NR);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 call->gc_flag = 1;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 return;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 if (nanp[0]) {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 is_nanp = 1;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 msg->called.type = GSM48_TON_INTERNATIONAL;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 msg->called.plan = GSM48_NPI_ISDN_E164;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 msg->called.number[0] = '1';
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 strcpy(msg->called.number+1, nanp);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 } else {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 is_itn = 1;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 msg->called.type = GSM48_TON_NET_SPEC;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 msg->called.plan = GSM48_NPI_PRIVATE;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 break;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 case 10:
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 if (msg->called.type != GSM48_TON_UNKNOWN &&
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 msg->called.type != GSM48_TON_NATIONAL)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 break;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 if (msg->called.plan != GSM48_NPI_UNKNOWN &&
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 msg->called.plan != GSM48_NPI_ISDN_E164 &&
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 msg->called.plan != GSM48_NPI_NATIONAL)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 break;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 if (!is_nanp_valid_prefix(msg->called.number)) {
28
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
127 syslog(LOG_ERR,
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
128 "rejecting MO call 0x%x: invalid NANP number",
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
129 msg->callref);
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 GSM48_CC_CAUSE_INV_NR_FORMAT);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 call->gc_flag = 1;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 return;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 is_nanp = 1;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 /* canonicalize to international format */
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 bcopy(msg->called.number, msg->called.number+1, 11);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 msg->called.number[0] = '1';
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 msg->called.type = GSM48_TON_INTERNATIONAL;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 msg->called.plan = GSM48_NPI_ISDN_E164;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 break;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 case 11:
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 if (msg->called.type != GSM48_TON_UNKNOWN &&
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 msg->called.type != GSM48_TON_INTERNATIONAL)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 break;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 if (msg->called.plan != GSM48_NPI_UNKNOWN &&
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 msg->called.plan != GSM48_NPI_ISDN_E164)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 break;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 if (msg->called.number[0] != '1')
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 break;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 if (!is_nanp_valid_prefix(msg->called.number+1)) {
28
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
152 syslog(LOG_ERR,
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
153 "rejecting MO call 0x%x: invalid NANP number",
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
154 msg->callref);
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 GSM48_CC_CAUSE_INV_NR_FORMAT);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 call->gc_flag = 1;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 return;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 is_nanp = 1;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 /* canonicalize to international format */
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 msg->called.type = GSM48_TON_INTERNATIONAL;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 msg->called.plan = GSM48_NPI_ISDN_E164;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 break;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 is_local = is_itn;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 if (is_nanp && is_nanp_locally_owned(msg->called.number+1))
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 is_local = 1;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 /* weed out attempts to call yourself */
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 if (is_local && !strcmp(msg->calling.number, msg->called.number)) {
28
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
171 syslog(LOG_ERR, "rejecting MO call 0x%x: call to self",
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
172 msg->callref);
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 GSM48_CC_CAUSE_INCOMPAT_DEST);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 call->gc_flag = 1;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 return;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 /* actually route the call */
167
2ebad02adbe5 themwi-mncc: route outbound calls to themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
179 if (is_local)
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 internal_switch_mo_setup(call, msg);
167
2ebad02adbe5 themwi-mncc: route outbound calls to themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
181 else
2ebad02adbe5 themwi-mncc: route outbound calls to themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 28
diff changeset
182 outbound_mo_setup(call, msg);
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 static void
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 reject_mt_call(conn, callref, cause_loc, cause_val)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 struct socket_conn *conn;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 uint32_t callref;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 struct gsm_mncc msg;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 bzero(&msg, sizeof(struct gsm_mncc));
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 msg.msg_type = MNCC_REJ_REQ;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 msg.callref = callref;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 mncc_set_cause(&msg, cause_loc, cause_val);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 mncc_signal_to_socket_nocall(conn, &msg);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 void
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 process_ext_mtcall_setup(conn, msg)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 struct socket_conn *conn;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 struct gsm_mncc *msg;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 struct gsm_call *call;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 if (!(msg->fields & MNCC_F_CALLED) && !msg->imsi[0]) {
28
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
207 syslog(LOG_ERR, "rejecting ext MT: no called number");
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 reject_mt_call(conn, msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 GSM48_CC_CAUSE_INVAL_MAND_INF);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 return;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 call = create_new_mt_call();
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 if (!call) {
28
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
214 syslog(LOG_ERR, "rejecting ext MT: no memory for call");
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 reject_mt_call(conn, msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 return;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 call->socket = conn;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 call->socket_ref = msg->callref;
28
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
221 conn->ncalls++;
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
222 syslog(LOG_DEBUG, "mapped socket callref 0x%x to GSM callref 0x%x",
660126bd5f59 themwi-mncc: fix one bug, add debug syslog output
Mychaela Falconia <falcon@freecalypso.org>
parents: 27
diff changeset
223 msg->callref, call->callref);
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224 /* forward to GSM MNCC interface */
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 msg->callref = call->callref;
27
c6572f4c31d2 themwi-mncc: fix bug in forwarding from call socket to GSM
Mychaela Falconia <falcon@freecalypso.org>
parents: 15
diff changeset
226 send_mncc_to_gsm(msg, sizeof(struct gsm_mncc));
15
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 }
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 preen_connected_number(msg)
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 struct gsm_mncc *msg;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231 {
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 if (preen_msc_provided_number(&msg->connected))
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 msg->fields |= MNCC_F_CONNECTED;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 else
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 msg->fields &= ~MNCC_F_CONNECTED;
ccc5ab6d8388 first version of themwi-mncc for ThemWi2
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 }