FreeCalypso > hg > themwi-system-sw
view sip-out/mgw_ops.c @ 243:59a166c50d0e
themwi-mncc: convert to libnumdb2
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Mon, 14 Aug 2023 19:13:26 -0800 |
parents | e54b0a9e322f |
children |
line wrap: on
line source
/* * In this module we implement all transactions from themwi-sip-out * toward themwi-mgw. */ #include <sys/types.h> #include <sys/socket.h> #include <sys/time.h> #include <netinet/in.h> #include <stdio.h> #include <stdint.h> #include <stdlib.h> #include <string.h> #include <strings.h> #include <syslog.h> #include "../include/tmgw_ctrl.h" #include "../include/tmgw_const.h" #include "../include/out_routes.h" #include "call.h" extern struct call *call_list; struct call * find_call_with_mgw_xact(xact_id) uint32_t xact_id; { struct call *call; for (call = call_list; call; call = call->next) if (call->mgw_xact && call->mgw_xact_id == xact_id) return call; return 0; } uint32_t get_new_tmgw_xact_id() { static uint32_t next_xact_id; for (;;) { next_xact_id++; if (!find_call_with_mgw_xact(next_xact_id)) return next_xact_id; } } void tmgw_send_crcx(call) struct call *call; { struct tmgw_ctrl_req req; bzero(&req, sizeof req); req.opcode = TMGW_CTRL_OP_CRCX; req.transact_ref = get_new_tmgw_xact_id(); req.ep_id = TMGW_EP_TYPE_GATEWAY; req.setup_mask = TMGW_CTRL_MASK_GSM_CONN; bcopy(&call->gsm_rtp_osmo, &req.gsm_addr, sizeof(struct sockaddr_storage)); req.gsm_payload_type = call->gsm_payload_type; req.gsm_payload_msg_type = call->gsm_payload_msg_type; send_req_to_tmgw(&req); call->mgw_xact = TMGW_CTRL_OP_CRCX; call->mgw_xact_id = req.transact_ref; } void tmgw_send_mdcx_connect(call, ibt) struct call *call; { struct tmgw_ctrl_req req; bzero(&req, sizeof req); req.opcode = TMGW_CTRL_OP_MDCX; req.transact_ref = get_new_tmgw_xact_id(); req.ep_id = call->mgw_ep_id; req.setup_mask = TMGW_CTRL_MASK_PSTN_CONN | TMGW_CTRL_MASK_FWD_MODE; bcopy(&call->pstn_rtp_remote, &req.pstn_addr, sizeof(struct sockaddr_in)); req.pstn_payload_type = call->use_pcma ? PSTN_CODEC_PCMA : PSTN_CODEC_PCMU; req.fwd_mode = ibt ? TMGW_FWD_MODE_RECVONLY : TMGW_FWD_MODE_SENDRECV; send_req_to_tmgw(&req); call->mgw_state = ibt ? MGW_STATE_MDCX_IBT : MGW_STATE_MDCX_CONN; call->mgw_xact = TMGW_CTRL_OP_MDCX; call->mgw_xact_id = req.transact_ref; } void tmgw_send_mdcx_hold(call) struct call *call; { struct tmgw_ctrl_req req; bzero(&req, sizeof req); req.opcode = TMGW_CTRL_OP_MDCX; req.transact_ref = get_new_tmgw_xact_id(); req.ep_id = call->mgw_ep_id; req.setup_mask = TMGW_CTRL_MASK_FWD_MODE; req.fwd_mode = TMGW_FWD_MODE_INACTIVE; send_req_to_tmgw(&req); call->mgw_state = MGW_STATE_MDCX_HOLD; call->mgw_xact = TMGW_CTRL_OP_MDCX; call->mgw_xact_id = req.transact_ref; } void tmgw_send_mdcx_retrieve(call) struct call *call; { struct tmgw_ctrl_req req; bzero(&req, sizeof req); req.opcode = TMGW_CTRL_OP_MDCX; req.transact_ref = get_new_tmgw_xact_id(); req.ep_id = call->mgw_ep_id; req.setup_mask = TMGW_CTRL_MASK_FWD_MODE; req.fwd_mode = TMGW_FWD_MODE_SENDRECV; send_req_to_tmgw(&req); call->mgw_state = MGW_STATE_MDCX_RETR; call->mgw_xact = TMGW_CTRL_OP_MDCX; call->mgw_xact_id = req.transact_ref; } void tmgw_send_dlcx(call) struct call *call; { struct tmgw_ctrl_req req; bzero(&req, sizeof req); req.opcode = TMGW_CTRL_OP_DLCX; req.transact_ref = get_new_tmgw_xact_id(); req.ep_id = call->mgw_ep_id; send_req_to_tmgw(&req); call->mgw_state = MGW_STATE_DELETING; call->mgw_xact = TMGW_CTRL_OP_DLCX; call->mgw_xact_id = req.transact_ref; } void tmgw_send_dtmf_start(call) struct call *call; { struct tmgw_ctrl_req req; bzero(&req, sizeof req); req.opcode = TMGW_CTRL_OP_DTMF_START; req.transact_ref = get_new_tmgw_xact_id(); req.ep_id = call->mgw_ep_id; req.fwd_mode = call->dtmf_digit; send_req_to_tmgw(&req); call->mgw_state = MGW_STATE_DTMF_OP; call->mgw_xact = TMGW_CTRL_OP_DTMF_START; call->mgw_xact_id = req.transact_ref; } void tmgw_send_dtmf_stop(call) struct call *call; { struct tmgw_ctrl_req req; bzero(&req, sizeof req); req.opcode = TMGW_CTRL_OP_DTMF_STOP; req.transact_ref = get_new_tmgw_xact_id(); req.ep_id = call->mgw_ep_id; send_req_to_tmgw(&req); call->mgw_state = MGW_STATE_DTMF_OP; call->mgw_xact = TMGW_CTRL_OP_DTMF_STOP; call->mgw_xact_id = req.transact_ref; }