annotate sip-out/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 e54b0a9e322f
children e89619893c1e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
62
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
2 * In this module we implement our initial handling of MNCC_SETUP_IND.
62
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/socket.h>
109
9b87894704eb sip-in: first step toward final call clearing
Mychaela Falconia <falcon@freecalypso.org>
parents: 63
diff changeset
7 #include <sys/time.h>
62
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <netinet/in.h>
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdio.h>
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdint.h>
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <stdlib.h>
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <string.h>
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <strings.h>
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <syslog.h>
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "../include/mncc.h"
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "../include/gsm48_const.h"
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
17 #include "../include/out_routes.h"
62
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "call.h"
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
20 extern struct call *find_call_by_mncc_callref();
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
21
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
22 extern int block_1900_numbers;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
23 extern struct call *call_list;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
24
62
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 static void
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
26 reject_mo_call(mncc, callref, cause_loc, cause_val)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
27 struct mncc_conn *mncc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
28 uint32_t callref;
62
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 {
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
30 struct gsm_mncc msg;
62
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
32 bzero(&msg, sizeof(struct gsm_mncc));
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
33 msg.msg_type = MNCC_REJ_REQ;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
34 msg.callref = callref;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
35 mncc_set_cause(&msg, cause_loc, cause_val);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
36 send_mncc_to_sock(mncc, &msg, sizeof(struct gsm_mncc));
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
37 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
38
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
39 static void
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
40 send_call_proceeding(call)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
41 struct call *call;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
42 {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
43 struct gsm_mncc msg;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
44
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
45 bzero(&msg, sizeof(struct gsm_mncc));
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
46 msg.msg_type = MNCC_CALL_PROC_REQ;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
47 msg.callref = call->mncc_callref;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
48 send_mncc_to_sock(call->mncc, &msg, sizeof(struct gsm_mncc));
62
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 }
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 void
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
52 handle_setup_ind(mncc, msg, msglen)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
53 struct mncc_conn *mncc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
54 struct gsm_mncc *msg;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
55 unsigned msglen;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
56 {
62
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 struct call *call;
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
58 struct sip_out_dest *dest;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
59 struct special_num_route *special_rt;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
60 char to_sip_user[MAX_SIP_USER_PART+1];
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
61 int rc;
62
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62
154
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
63 if (msglen != sizeof(struct gsm_mncc)) {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
64 syslog(LOG_CRIT,
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
65 "FATAL: Rx MNCC_SETUP_IND has wrong length");
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
66 exit(1);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
67 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
68 /* check for duplicates */
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
69 call = find_call_by_mncc_callref(mncc, msg->callref);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
70 if (call) {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
71 syslog(LOG_ERR, "duplicate MNCC_SETUP_IND for callref 0x%x",
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
72 msg->callref);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
73 /* drop it like OsmoMSC's mncc_builtin does */
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
74 return;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
75 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
76 if (!(msg->fields & MNCC_F_CALLED) ||
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
77 !(msg->fields & MNCC_F_BEARER_CAP)) {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
78 syslog(LOG_ERR, "rejecting MO call 0x%x: missing mandatory IE",
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
79 msg->callref);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
80 reject_mo_call(mncc, msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
81 GSM48_CC_CAUSE_INVAL_MAND_INF);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
82 return;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
83 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
84 /* route based on destination address */
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
85 refresh_out_routes_db();
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
86 if (msg->called.type == GSM48_TON_INTERNATIONAL) {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
87 rc = grok_number_string(msg->called.number, 0);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
88 if (rc < 2 || rc > MAX_E164_NUMBER) {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
89 inv_nr_format: reject_mo_call(mncc, msg->callref,
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
90 GSM48_CAUSE_LOC_PRN_S_LU,
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
91 GSM48_CC_CAUSE_INV_NR_FORMAT);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
92 return;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
93 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
94 if (msg->called.number[0] == '0')
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
95 goto inv_nr_format;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
96 if (msg->called.number[0] == '1') {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
97 if (rc != 11)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
98 goto inv_nr_format;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
99 if (!is_nanp_valid_prefix(msg->called.number+1))
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
100 goto inv_nr_format;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
101 if (msg->called.number[1] == '9' &&
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
102 msg->called.number[2] == '0' &&
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
103 msg->called.number[3] == '0' &&
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
104 block_1900_numbers) {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
105 call_barred: reject_mo_call(mncc, msg->callref,
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
106 GSM48_CAUSE_LOC_PRN_S_LU,
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
107 GSM48_CC_CAUSE_OP_DET_BARRING);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
108 return;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
109 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
110 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
111 rc = route_e164_number(msg->called.number, &dest);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
112 if (!rc) {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
113 no_route_to_dest: reject_mo_call(mncc, msg->callref,
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
114 GSM48_CAUSE_LOC_PRN_S_LU,
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
115 GSM48_CC_CAUSE_NO_ROUTE);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
116 return;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
117 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
118 to_sip_user[0] = '+';
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
119 strcpy(to_sip_user+1, msg->called.number);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
120 } else {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
121 rc = route_special_number(msg->called.number, &dest,
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
122 &special_rt);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
123 if (!rc)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
124 goto no_route_to_dest;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
125 strcpy(to_sip_user, special_rt->sip_user);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
126 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
127 /* validate From number */
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
128 if (!(msg->fields & MNCC_F_CALLING))
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
129 goto call_barred;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
130 if (msg->calling.type != GSM48_TON_INTERNATIONAL)
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
131 goto call_barred;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
132 if (grok_number_string(msg->calling.number, 0) != 11 ||
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
133 msg->calling.number[0] != '1')
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
134 goto call_barred;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
135 /* speech-only restriction */
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
136 if (msg->bearer_cap.transfer != GSM48_BCAP_ITCAP_SPEECH ||
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
137 msg->bearer_cap.mode != GSM48_BCAP_TMOD_CIRCUIT) {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
138 syslog(LOG_ERR, "rejecting MO call 0x%x: bad bearer cap",
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
139 msg->callref);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
140 reject_mo_call(mncc, msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
141 GSM48_CC_CAUSE_BEARER_CA_UNAVAIL);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
142 return;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
143 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
144 /* TMGW must be up and running */
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
145 rc = connect_tmgw_socket();
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
146 if (rc < 0) {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
147 reject_mo_call(mncc, msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
148 GSM48_CC_CAUSE_NETWORK_OOO);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
149 return;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
150 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
151 /* allocate struct call and being stateful processing */
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
152 call = malloc(sizeof(struct call));
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
153 if (!call) {
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
154 syslog(LOG_CRIT, "failed malloc for outbound call!");
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
155 reject_mo_call(mncc, msg->callref, GSM48_CAUSE_LOC_PRN_S_LU,
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
156 GSM48_CC_CAUSE_RESOURCE_UNAVAIL);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
157 return;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
158 }
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
159 bzero(call, sizeof(struct call));
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
160 call->mncc = mncc;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
161 call->mncc_callref = msg->callref;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
162 call->from_user[0] = '+';
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
163 strcpy(call->from_user+1, msg->calling.number);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
164 sprintf(call->to_uri, "sip:%s@%s", to_sip_user, dest->domain);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
165 bcopy(&dest->sin, &call->udp_sin, sizeof(struct sockaddr_in));
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
166 call->next = call_list;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
167 call_list = call;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
168 send_call_proceeding(call);
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
169 call->overall_state = OVERALL_STATE_GSM_RTP;
e54b0a9e322f beginning of themwi-sip-out
Mychaela Falconia <falcon@freecalypso.org>
parents: 115
diff changeset
170 call->mncc_state = MNCC_STATE_MO_PROC;
62
75b7a7b61824 sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
171 }