FreeCalypso > hg > themwi-system-sw
annotate sip-in/call_setup.c @ 70:47976db01894
sip-in/sip_log.c: extern declaration of global variable
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 19 Sep 2022 21:30:33 -0800 |
parents | e5aee661e3b2 |
children | 9b87894704eb |
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 /* |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * In this module we implement incoming call setup toward GSM. |
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> |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #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
|
8 #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
|
9 #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
|
10 #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
|
11 #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
|
12 #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
|
13 #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
|
14 #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
|
15 #include "../include/gsm48_const.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 "call.h" |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 static void |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 fill_calling_number(from, caller) |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 char *from; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 struct gsm_mncc_number *caller; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 { |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 char *num; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 int cc; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (!strcasecmp(from, "Restricted")) { |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 caller->present = GSM48_PRES_RESTR; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 if (*from == '+') |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 num = from + 1; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 else |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 num = from; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 cc = grok_number_string(num, 0); |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 if (cc < 1 || cc > 32) { |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 /* not a valid number */ |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 caller->present = GSM48_PRES_UNAVAIL; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 return; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 /* accept "From" user as a valid number */ |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 strcpy(caller->number, num); |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 caller->plan = GSM48_NPI_ISDN_E164; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (*from == '+') |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 caller->type = GSM48_TON_INTERNATIONAL; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 } |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 void |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 proceed_with_call_setup(call) |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 struct call *call; |
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 struct gsm_mncc setup_msg; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 allocate_mncc_callref(call); |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 bzero(&setup_msg, sizeof setup_msg); |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 setup_msg.msg_type = MNCC_SETUP_REQ; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 setup_msg.callref = call->mncc_callref; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 /* fill called number */ |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 setup_msg.called.type = GSM48_TON_INTERNATIONAL; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 setup_msg.called.plan = GSM48_NPI_ISDN_E164; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 setup_msg.called.number[0] = '1'; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 strcpy(setup_msg.called.number+1, call->called_nanp); |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 setup_msg.fields |= MNCC_F_CALLED; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 /* fill calling number */ |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 call->from_user[call->from_user_len] = '\0'; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 fill_calling_number(call->from_user, &setup_msg.calling); |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 call->from_user[call->from_user_len] = '@'; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 setup_msg.fields |= MNCC_F_CALLING; |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 send_mncc_to_gsm(&setup_msg, sizeof(struct gsm_mncc)); |
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 call->overall_state = OVERALL_STATE_CALL_GSM; |
63
e5aee661e3b2
sip-in: beginning to handle incoming MNCC messages from themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
62
diff
changeset
|
70 call->mncc_state = MNCC_STATE_STARTED; |
62
75b7a7b61824
sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 } |