comparison sip-out/e911.c @ 259:9f96e5b14755

sip-out: implement E911 special handling
author Mychaela Falconia <falcon@freecalypso.org>
date Tue, 15 Aug 2023 11:28:30 -0800
parents
children
comparison
equal deleted inserted replaced
258:aab047d9efcb 259:9f96e5b14755
1 /*
2 * In this module we implement E911 routing, i.e., special handling
3 * for calls to either the real 911 or E911 test numbers.
4 */
5
6 #include <sys/types.h>
7 #include <sys/socket.h>
8 #include <stdio.h>
9 #include <stdint.h>
10 #include <stdlib.h>
11 #include <string.h>
12 #include <strings.h>
13 #include <syslog.h>
14 #include "../include/mncc.h"
15 #include "../include/gsm48_const.h"
16 #include "../include/number_db_v2.h"
17 #include "../libnumdb2/lookup_func.h"
18
19 e911_call_preen(msg)
20 struct gsm_mncc *msg;
21 {
22 struct owned_number_rec *nr;
23
24 syslog(LOG_NOTICE, "E911 call attempt from %s to %s, emergency flag %d",
25 msg->calling.number, msg->called.number, msg->emergency);
26 refresh_number_db();
27 nr = numdb_lookup_nanp(msg->calling.number+1);
28 if (!nr) {
29 syslog(LOG_NOTICE,
30 "E911 call rejected: calling number is not in database");
31 return 0;
32 }
33 if (nr->number_flags & NUMBER_FLAG_E911PROV) {
34 syslog(LOG_NOTICE,
35 "E911 call allowed: calling number has E911 flag set");
36 return 1;
37 }
38 if (nr->usage & NUMBER_USAGE_FLAG_E911_VIA) {
39 sprintf(msg->calling.number, "1%03u%03u%04u",
40 nr->remap[0], nr->remap[1], nr->remap[2]);
41 syslog(LOG_NOTICE, "E911 call: source number changed to %s",
42 msg->calling.number);
43 return 1;
44 }
45 syslog(LOG_NOTICE,
46 "E911 call rejected: calling number is not E911-provisioned");
47 return 0;
48 }