comparison mncc/call_setup.c @ 243:59a166c50d0e

themwi-mncc: convert to libnumdb2
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 14 Aug 2023 19:13:26 -0800
parents 2ebad02adbe5
children
comparison
equal deleted inserted replaced
242:f86ec96cea6f 243:59a166c50d0e
11 #include <string.h> 11 #include <string.h>
12 #include <strings.h> 12 #include <strings.h>
13 #include <syslog.h> 13 #include <syslog.h>
14 #include "../include/mncc.h" 14 #include "../include/mncc.h"
15 #include "../include/gsm48_const.h" 15 #include "../include/gsm48_const.h"
16 #include "../include/number_db_v2.h"
17 #include "../libnumdb2/lookup_func.h"
16 #include "struct.h" 18 #include "struct.h"
17 #include "gsm_call.h" 19 #include "gsm_call.h"
18 20
19 preen_msc_provided_number(nums) 21 preen_msc_provided_number(nums)
20 struct gsm_mncc_number *nums; 22 struct gsm_mncc_number *nums;
56 void 58 void
57 process_mo_call_setup(msg) 59 process_mo_call_setup(msg)
58 struct gsm_mncc *msg; 60 struct gsm_mncc *msg;
59 { 61 {
60 struct gsm_call *call; 62 struct gsm_call *call;
61 char nanp[11]; 63 struct owned_number_rec *own;
62 int res, is_nanp, is_itn, is_local; 64 struct short_number_rec *snum;
65 int is_nanp, is_itn, is_local;
63 66
64 if (preen_msc_provided_number(&msg->calling)) 67 if (preen_msc_provided_number(&msg->calling))
65 msg->fields |= MNCC_F_CALLING; 68 msg->fields |= MNCC_F_CALLING;
66 else 69 else
67 msg->fields &= ~MNCC_F_CALLING; 70 msg->fields &= ~MNCC_F_CALLING;
91 break; 94 break;
92 if (msg->called.plan != GSM48_NPI_UNKNOWN && 95 if (msg->called.plan != GSM48_NPI_UNKNOWN &&
93 msg->called.plan != GSM48_NPI_ISDN_E164 && 96 msg->called.plan != GSM48_NPI_ISDN_E164 &&
94 msg->called.plan != GSM48_NPI_PRIVATE) 97 msg->called.plan != GSM48_NPI_PRIVATE)
95 break; 98 break;
96 res = lookup_short_dial_number(msg->called.number, nanp); 99 snum = numdb_lookup_short(msg->called.number);
97 if (!res) { 100 if (!snum) {
98 syslog(LOG_ERR, 101 syslog(LOG_ERR,
99 "rejecting MO call 0x%x: invalid short number", 102 "rejecting MO call 0x%x: unassigned short number",
100 msg->callref); 103 msg->callref);
101 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU, 104 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
102 GSM48_CC_CAUSE_UNASSIGNED_NR); 105 GSM48_CC_CAUSE_UNASSIGNED_NR);
103 call->gc_flag = 1; 106 call->gc_flag = 1;
104 return; 107 return;
105 } 108 }
106 if (nanp[0]) { 109 switch (snum->short_num_type) {
110 case SHORT_NUM_TYPE_ABBREV:
107 is_nanp = 1; 111 is_nanp = 1;
108 msg->called.type = GSM48_TON_INTERNATIONAL; 112 msg->called.type = GSM48_TON_INTERNATIONAL;
109 msg->called.plan = GSM48_NPI_ISDN_E164; 113 msg->called.plan = GSM48_NPI_ISDN_E164;
110 msg->called.number[0] = '1'; 114 sprintf(msg->called.number, "1%03u%03u%04u",
111 strcpy(msg->called.number+1, nanp); 115 snum->fullnum_prefix[0],
112 } else { 116 snum->fullnum_prefix[1], snum->short_num);
117 break;
118 case SHORT_NUM_TYPE_ITN:
113 is_itn = 1; 119 is_itn = 1;
114 msg->called.type = GSM48_TON_NET_SPEC; 120 msg->called.type = GSM48_TON_NET_SPEC;
115 msg->called.plan = GSM48_NPI_PRIVATE; 121 msg->called.plan = GSM48_NPI_PRIVATE;
122 break;
123 case SHORT_NUM_TYPE_TEST_SINK:
124 syslog(LOG_ERR,
125 "rejecting MO call 0x%x: test sink not implemented",
126 msg->callref);
127 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
128 GSM48_CC_CAUSE_DEST_OOO);
129 call->gc_flag = 1;
130 return;
131 default:
132 syslog(LOG_ERR,
133 "rejecting MO call 0x%x: unknown short number type 0x%02X",
134 msg->callref, snum->short_num_type);
135 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
136 GSM48_CC_CAUSE_DEST_OOO);
137 call->gc_flag = 1;
138 return;
116 } 139 }
117 break; 140 break;
118 case 10: 141 case 10:
119 if (msg->called.type != GSM48_TON_UNKNOWN && 142 if (msg->called.type != GSM48_TON_UNKNOWN &&
120 msg->called.type != GSM48_TON_NATIONAL) 143 msg->called.type != GSM48_TON_NATIONAL)
162 msg->called.type = GSM48_TON_INTERNATIONAL; 185 msg->called.type = GSM48_TON_INTERNATIONAL;
163 msg->called.plan = GSM48_NPI_ISDN_E164; 186 msg->called.plan = GSM48_NPI_ISDN_E164;
164 break; 187 break;
165 } 188 }
166 is_local = is_itn; 189 is_local = is_itn;
167 if (is_nanp && is_nanp_locally_owned(msg->called.number+1)) 190 if (is_nanp && (own = numdb_lookup_nanp(msg->called.number+1))) {
168 is_local = 1; 191 is_local = 1;
192 switch (own->usage & NUMBER_USAGE_MASK) {
193 case NUMBER_USAGE_TYPE_GSM_SUB:
194 break;
195 case NUMBER_USAGE_TYPE_ALIAS:
196 sprintf(msg->called.number, "1%03u%03u%04u",
197 own->remap[0], own->remap[1], own->remap[2]);
198 break;
199 default:
200 syslog(LOG_ERR,
201 "rejecting MO call 0x%x: unassigned owned NANP",
202 msg->callref);
203 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
204 GSM48_CC_CAUSE_UNASSIGNED_NR);
205 call->gc_flag = 1;
206 return;
207 }
208 }
169 /* weed out attempts to call yourself */ 209 /* weed out attempts to call yourself */
170 if (is_local && !strcmp(msg->calling.number, msg->called.number)) { 210 if (is_local && !strcmp(msg->calling.number, msg->called.number)) {
171 syslog(LOG_ERR, "rejecting MO call 0x%x: call to self", 211 syslog(LOG_ERR, "rejecting MO call 0x%x: call to self",
172 msg->callref); 212 msg->callref);
173 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU, 213 reject_mo_call(msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,