1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
10 \*****************************************************************************/
14 unsigned int new_remote = 1000;
19 Premote::Premote(int type, char *portname, struct port_settings *settings, struct interface *interface, int remote_id) : Port(type, portname, settings)
21 union parameter param;
23 p_callerinfo.itype = (interface->extension)?INFO_ITYPE_ISDN_EXTENSION:INFO_ITYPE_ISDN;
24 p_r_ref = new_remote++;
25 SCPY(p_r_remote_app, interface->remote_app);
26 SCPY(p_r_interface_name, interface->name);
27 p_r_tones = (interface->is_tones == IS_YES);
29 /* send new ref to remote socket */
30 memset(¶m, 0, sizeof(union parameter));
31 if (type == PORT_TYPE_REMOTE_OUT)
32 param.newref.direction = 1; /* new ref from lcr */
33 p_r_remote_id = remote_id;
34 if (admin_message_from_lcr(p_r_remote_id, p_r_ref, MESSAGE_NEWREF, ¶m) < 0)
35 FATAL("No socket with remote application '%s' found, this shall not happen. because we already created one.\n", p_r_remote_app);
37 PDEBUG(DEBUG_PORT, "Created new RemotePort(%s).\n", portname);
46 PDEBUG(DEBUG_PORT, "Destroyed Remote process(%s).\n", p_name);
50 * endpoint sends messages to the port
52 int Premote::message_epoint(unsigned int epoint_id, int message_type, union parameter *param)
54 struct epoint_list *epointlist;
56 if (Port::message_epoint(epoint_id, message_type, param))
59 if (message_type == MESSAGE_SETUP) {
60 struct interface *interface;
61 interface = getinterfacebyname(p_r_interface_name);
63 PERROR("Cannot find interface %s.\n", p_r_interface_name);
66 /* attach only if not already */
67 epointlist = p_epointlist;
69 if (epointlist->epoint_id == epoint_id)
71 epointlist = epointlist->next;
74 epointlist_new(epoint_id);
76 /* set context to pbx */
77 if (!param->setup.dialinginfo.context[0]) {
78 if (interface->remote_context[0])
79 SCPY(param->setup.dialinginfo.context, interface->remote_context);
81 SCPY(param->setup.dialinginfo.context, "lcr");
86 /* look for Remote's interface */
87 if (admin_message_from_lcr(p_r_remote_id, p_r_ref, message_type, param)<0) {
88 PERROR("No socket with remote application '%s' found, this shall not happen. Closing socket shall cause release of all remote ports.\n", p_r_remote_app);
93 /* enable audio path */
94 if (message_type == MESSAGE_SETUP) {
95 union parameter newparam;
96 memset(&newparam, 0, sizeof(union parameter));
97 admin_message_from_lcr(p_r_remote_id, p_r_ref, MESSAGE_PATTERN, &newparam);
98 newparam.audiopath = 1;
99 admin_message_from_lcr(p_r_remote_id, p_r_ref, MESSAGE_AUDIOPATH, &newparam);
103 if (message_type == MESSAGE_CONNECT)
104 new_state(PORT_STATE_CONNECT);
106 if (message_type == MESSAGE_RELEASE) {
107 new_state(PORT_STATE_RELEASE);
115 void Premote::message_remote(int message_type, union parameter *param)
117 class Endpoint *epoint;
118 struct lcr_msg *message;
119 struct interface *interface;
121 switch (message_type) {
122 case MESSAGE_TRAFFIC:
123 bridge_tx(param->traffic.data, param->traffic.len);
127 interface = getinterfacebyname(p_r_interface_name);
129 PERROR("Cannot find interface %s.\n", p_r_interface_name);
133 /* enable audio path */
134 if (interface->is_tones == IS_YES) {
135 union parameter newparam;
136 memset(&newparam, 0, sizeof(union parameter));
137 admin_message_from_lcr(p_r_remote_id, p_r_ref, MESSAGE_PATTERN, &newparam);
138 newparam.audiopath = 1;
139 admin_message_from_lcr(p_r_remote_id, p_r_ref, MESSAGE_AUDIOPATH, &newparam);
142 /* set source interface */
143 param->setup.callerinfo.itype = p_callerinfo.itype;
144 SCPY(param->setup.callerinfo.interface, interface->name);
146 /* create endpoint */
148 FATAL("Incoming call but already got an endpoint.\n");
149 if (!(epoint = new Endpoint(p_serial, 0)))
150 FATAL("No memory for Endpoint instance\n");
151 epoint->ep_app = new_endpointapp(epoint, 0, interface->app); //incoming
153 epointlist_new(epoint->ep_serial);
156 if (message_type == MESSAGE_CONNECT)
157 new_state(PORT_STATE_CONNECT);
158 /* cannot just forward, because param is not of container "struct lcr_msg" */
159 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, message_type);
160 memcpy(&message->param, param, sizeof(message->param));
161 message_put(message);
163 if (message_type == MESSAGE_RELEASE) {
164 new_state(PORT_STATE_RELEASE);
171 /* receive from remote Port instance */
172 int Premote::bridge_rx(unsigned char *data, int len)
174 union parameter newparam;
177 /* don't send tones, if not enabled or not connected */
179 && p_state != PORT_STATE_CONNECT)
182 memset(&newparam, 0, sizeof(union parameter));
183 /* split, if exeeds data size */
185 l = (len > (int)sizeof(newparam.traffic.data)) ? sizeof(newparam.traffic.data) : len;
186 newparam.traffic.len = l;
188 memcpy(newparam.traffic.data, data, l);
190 admin_message_from_lcr(p_r_remote_id, p_r_ref, MESSAGE_TRAFFIC, &newparam);