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