annotate mgw/dlcx.c @ 62:75b7a7b61824

sip-in: got as far as sending MNCC_SETUP_REQ to themwi-mncc
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 17 Sep 2022 18:43:08 -0800
parents 020ba624bdd8
children f280328e7e2e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
32
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * In this module we implement our DLCX operation.
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/socket.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <netinet/in.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
38
020ba624bdd8 mgw source: #include <stdlib.h> in files using tmgw_ctrl.h
Mychaela Falconia <falcon@freecalypso.org>
parents: 32
diff changeset
9 #include <stdint.h>
32
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <stdlib.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <string.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include <strings.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 #include <syslog.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 #include <unistd.h>
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 #include "../include/tmgw_ctrl.h"
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 #include "../include/tmgw_const.h"
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 #include "struct.h"
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 #include "select.h"
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 extern struct endpoint *find_ep_by_id();
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 static struct endpoint *delq;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 static void
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 put_on_delq(ep)
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 struct endpoint *ep;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 ep->next = delq;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 delq = ep;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 }
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 void
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 process_dlcx(conn, req, resp)
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 struct ctrl_conn *conn;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 struct tmgw_ctrl_req *req;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 struct tmgw_ctrl_resp *resp;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 struct endpoint *ep, **epp;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 for (epp = &conn->endp_list; ep = *epp; epp = &ep->next)
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 if (ep->ep_id == req->ep_id)
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 break;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (!ep) {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 resp->res = TMGW_RESP_ERR_PROT;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 return;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 }
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 syslog(LOG_INFO, "DLCX endpoint id %u", ep->ep_id);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 *epp = ep->next;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 put_on_delq(ep);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 resp->res = TMGW_RESP_OK;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 }
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 void
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 dlcx_all_on_conn(conn)
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 struct ctrl_conn *conn;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 struct endpoint *ep, *np;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 for (ep = conn->endp_list; ep; ep = np) {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 np = ep->next;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 put_on_delq(ep);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 void
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 free_rtp_end(roe)
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 struct rtp_one_end *roe;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 close(roe->rtp_fd);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 close(roe->rtcp_fd);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 FD_CLR(roe->rtp_fd, &select_for_read);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 FD_CLR(roe->rtcp_fd, &select_for_read);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 }
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 void
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 free_deleted_endpoints()
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 struct endpoint *ep, *np;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 for (ep = delq; ep; ep = np) {
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 np = ep->next;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (ep->ep_type & TMGW_EP_HAS_GSM_SOCK)
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 free_rtp_end(&ep->rtp_gsm);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 if (ep->ep_type & TMGW_EP_HAS_PSTN_SOCK)
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 free_rtp_end(&ep->rtp_pstn);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 free(ep);
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 }
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 delq = 0;
b3f74df7b808 beginning of themwi-mgw
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }