annotate mncc/call_setup.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 847690ea7f4a
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 setup of new calls: either new MO calls
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * coming from GSM or new MT calls coming from a ThemWi call socket.
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 <sys/socket.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdint.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <string.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <strings.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <syslog.h>
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include "../include/mncc.h"
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "../include/gsm48_const.h"
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "../include/number_db_v2.h"
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "../libnumdb2/lookup_func.h"
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "struct.h"
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 #include "gsm_call.h"
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 preen_msc_provided_number(nums)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 struct gsm_mncc_number *nums;
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 int len;
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 len = grok_number_string(nums->number, 0);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 switch (len) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 case 4:
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 nums->type = GSM48_TON_NET_SPEC;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 nums->plan = GSM48_NPI_PRIVATE;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 case 11:
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 if (nums->number[0] != '1')
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 return(0);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 nums->type = GSM48_TON_INTERNATIONAL;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 nums->plan = GSM48_NPI_ISDN_E164;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 default:
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 return(0);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 nums->screen = GSM48_SCRN_NETWORK;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 return(1);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 void
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 reject_mo_call(callref, cause_loc, cause_val)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 uint32_t callref;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 struct gsm_mncc msg;
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 bzero(&msg, sizeof(struct gsm_mncc));
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 msg.msg_type = MNCC_REJ_REQ;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 msg.callref = callref;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 mncc_set_cause(&msg, cause_loc, cause_val);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 send_mncc_to_gsm(&msg, sizeof(struct gsm_mncc));
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
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 void
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 process_mo_call_setup(msg)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 struct gsm_mncc *msg;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 struct gsm_call *call;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 struct owned_number_rec *own;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 struct short_number_rec *snum;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 int is_nanp, is_itn, is_local;
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 if (preen_msc_provided_number(&msg->calling))
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 msg->fields |= MNCC_F_CALLING;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 else
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 msg->fields &= ~MNCC_F_CALLING;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 if (!(msg->fields & MNCC_F_CALLED)) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 syslog(LOG_ERR, "rejecting MO call 0x%x: no called number",
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 msg->callref);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 GSM48_CC_CAUSE_INVAL_MAND_INF);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 return;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 call = create_gsm_call(msg->callref);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 if (!call) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 syslog(LOG_ERR, "rejecting MO call 0x%x: no memory for call",
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 msg->callref);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 return;
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 /* route based on destination address */
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 refresh_number_db();
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 is_nanp = is_itn = 0;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 switch (grok_number_string(msg->called.number, 0)) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 case 4:
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 if (msg->called.type != GSM48_TON_UNKNOWN &&
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 msg->called.type != GSM48_TON_NET_SPEC &&
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 msg->called.type != GSM48_TON_SHORT_CODE)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 if (msg->called.plan != GSM48_NPI_UNKNOWN &&
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 msg->called.plan != GSM48_NPI_ISDN_E164 &&
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 msg->called.plan != GSM48_NPI_PRIVATE)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 snum = numdb_lookup_short(msg->called.number);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 if (!snum) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 syslog(LOG_ERR,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
102 "rejecting MO call 0x%x: unassigned short number",
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
103 msg->callref);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 GSM48_CC_CAUSE_UNASSIGNED_NR);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
106 call->gc_flag = 1;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
107 return;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
108 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
109 switch (snum->short_num_type) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
110 case SHORT_NUM_TYPE_ABBREV:
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
111 is_nanp = 1;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
112 msg->called.type = GSM48_TON_INTERNATIONAL;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
113 msg->called.plan = GSM48_NPI_ISDN_E164;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
114 sprintf(msg->called.number, "1%03u%03u%04u",
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
115 snum->fullnum_prefix[0],
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
116 snum->fullnum_prefix[1], snum->short_num);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
117 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
118 case SHORT_NUM_TYPE_ITN:
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
119 is_itn = 1;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
120 msg->called.type = GSM48_TON_NET_SPEC;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
121 msg->called.plan = GSM48_NPI_PRIVATE;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
122 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
123 case SHORT_NUM_TYPE_TEST_SINK:
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
124 syslog(LOG_ERR,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
125 "rejecting MO call 0x%x: test sink not implemented",
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
126 msg->callref);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
127 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
128 GSM48_CC_CAUSE_DEST_OOO);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
129 call->gc_flag = 1;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
130 return;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
131 default:
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
132 syslog(LOG_ERR,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
133 "rejecting MO call 0x%x: unknown short number type 0x%02X",
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 msg->callref, snum->short_num_type);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 GSM48_CC_CAUSE_DEST_OOO);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
137 call->gc_flag = 1;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138 return;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
141 case 10:
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 if (msg->called.type != GSM48_TON_UNKNOWN &&
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 msg->called.type != GSM48_TON_NATIONAL)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 if (msg->called.plan != GSM48_NPI_UNKNOWN &&
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 msg->called.plan != GSM48_NPI_ISDN_E164 &&
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
147 msg->called.plan != GSM48_NPI_NATIONAL)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
149 if (!is_nanp_valid_prefix(msg->called.number)) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
150 syslog(LOG_ERR,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
151 "rejecting MO call 0x%x: invalid NANP number",
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
152 msg->callref);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
154 GSM48_CC_CAUSE_INV_NR_FORMAT);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
155 call->gc_flag = 1;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
156 return;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
157 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
158 is_nanp = 1;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
159 /* canonicalize to international format */
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
160 bcopy(msg->called.number, msg->called.number+1, 11);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
161 msg->called.number[0] = '1';
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
162 msg->called.type = GSM48_TON_INTERNATIONAL;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
163 msg->called.plan = GSM48_NPI_ISDN_E164;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
164 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
165 case 11:
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
166 if (msg->called.type != GSM48_TON_UNKNOWN &&
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
167 msg->called.type != GSM48_TON_INTERNATIONAL)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
168 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
169 if (msg->called.plan != GSM48_NPI_UNKNOWN &&
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 msg->called.plan != GSM48_NPI_ISDN_E164)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
172 if (msg->called.number[0] != '1')
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
173 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
174 if (!is_nanp_valid_prefix(msg->called.number+1)) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 syslog(LOG_ERR,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
176 "rejecting MO call 0x%x: invalid NANP number",
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
177 msg->callref);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
178 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
179 GSM48_CC_CAUSE_INV_NR_FORMAT);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
180 call->gc_flag = 1;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
181 return;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
182 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
183 is_nanp = 1;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
184 /* canonicalize to international format */
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 msg->called.type = GSM48_TON_INTERNATIONAL;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 msg->called.plan = GSM48_NPI_ISDN_E164;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
188 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189 is_local = is_itn;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 if (is_nanp && (own = numdb_lookup_nanp(msg->called.number+1))) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 is_local = 1;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 switch (own->usage & NUMBER_USAGE_MASK) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 case NUMBER_USAGE_TYPE_GSM_SUB:
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 case NUMBER_USAGE_TYPE_ALIAS:
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 sprintf(msg->called.number, "1%03u%03u%04u",
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 own->remap[0], own->remap[1], own->remap[2]);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 break;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 default:
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
200 syslog(LOG_ERR,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
201 "rejecting MO call 0x%x: unassigned owned NANP",
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
202 msg->callref);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
203 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 GSM48_CC_CAUSE_UNASSIGNED_NR);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
205 call->gc_flag = 1;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
206 return;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
207 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
208 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
209 /* weed out attempts to call yourself */
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
210 if (is_local && !strcmp(msg->calling.number, msg->called.number)) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
211 syslog(LOG_ERR, "rejecting MO call 0x%x: call to self",
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
212 msg->callref);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
213 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
214 GSM48_CC_CAUSE_INCOMPAT_DEST);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
215 call->gc_flag = 1;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
216 return;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
217 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
218 /* actually route the call */
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
219 if (is_local)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
220 internal_switch_mo_setup(call, msg);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
221 else
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
222 outbound_mo_setup(call, msg);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
223 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
224
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
225 static void
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
226 reject_mt_call(conn, callref, cause_loc, cause_val)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
227 struct socket_conn *conn;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
228 uint32_t callref;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
229 {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
230 struct gsm_mncc msg;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
231
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
232 bzero(&msg, sizeof(struct gsm_mncc));
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
233 msg.msg_type = MNCC_REJ_REQ;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
234 msg.callref = callref;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
235 mncc_set_cause(&msg, cause_loc, cause_val);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
236 mncc_signal_to_socket_nocall(conn, &msg);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
237 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
238
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
239 void
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
240 process_ext_mtcall_setup(conn, msg)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
241 struct socket_conn *conn;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
242 struct gsm_mncc *msg;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
243 {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
244 struct gsm_call *call;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
245
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
246 if (!(msg->fields & MNCC_F_CALLED) && !msg->imsi[0]) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
247 syslog(LOG_ERR, "rejecting ext MT: no called number");
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
248 reject_mt_call(conn, msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
249 GSM48_CC_CAUSE_INVAL_MAND_INF);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
250 return;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
251 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
252 call = create_new_mt_call();
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
253 if (!call) {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
254 syslog(LOG_ERR, "rejecting ext MT: no memory for call");
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
255 reject_mt_call(conn, msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
256 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
257 return;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
258 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
259 call->socket = conn;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
260 call->socket_ref = msg->callref;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
261 conn->ncalls++;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
262 syslog(LOG_DEBUG, "mapped socket callref 0x%x to GSM callref 0x%x",
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
263 msg->callref, call->callref);
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
264 /* forward to GSM MNCC interface */
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
265 msg->callref = call->callref;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
266 send_mncc_to_gsm(msg, sizeof(struct gsm_mncc));
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
267 }
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
268
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
269 preen_connected_number(msg)
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
270 struct gsm_mncc *msg;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
271 {
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
272 if (preen_msc_provided_number(&msg->connected))
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
273 msg->fields |= MNCC_F_CONNECTED;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
274 else
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
275 msg->fields &= ~MNCC_F_CONNECTED;
053f04687106 mncc: initial import from old ThemWi
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
276 }