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, interface)
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 p_r_tones = (interface->is_tones == IS_YES);
28 /* send new ref to remote socket */
29 memset(¶m, 0, sizeof(union parameter));
30 if (type == PORT_TYPE_REMOTE_OUT)
31 param.newref.direction = 1; /* new ref from lcr */
32 p_r_remote_id = remote_id;
33 if (admin_message_from_lcr(p_r_remote_id, p_r_ref, MESSAGE_NEWREF, ¶m) < 0)
34 FATAL("No socket with remote application '%s' found, this shall not happen. because we already created one.\n", p_r_remote_app);
36 PDEBUG(DEBUG_PORT, "Created new RemotePort(%s).\n", portname);
45 PDEBUG(DEBUG_PORT, "Destroyed Remote process(%s).\n", p_name);
49 * endpoint sends messages to the port
51 int Premote::message_epoint(unsigned int epoint_id, int message_type, union parameter *param)
53 struct epoint_list *epointlist;
55 if (Port::message_epoint(epoint_id, message_type, param))
58 switch (message_type) {
60 struct interface *interface;
61 interface = getinterfacebyname(p_interface_name);
63 PERROR("Cannot find interface %s.\n", p_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");
84 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
85 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
86 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_interface_name);
87 do_screen(1, p_callerinfo.id2, sizeof(p_callerinfo.id2), &p_callerinfo.ntype2, &p_callerinfo.present2, p_interface_name);
88 do_screen(1, p_redirinfo.id, sizeof(p_redirinfo.id), &p_redirinfo.ntype, &p_redirinfo.present, p_interface_name);
89 memcpy(¶m->setup.callerinfo, &p_callerinfo, sizeof(p_callerinfo));
90 memcpy(¶m->setup.redirinfo, &p_redirinfo, sizeof(p_redirinfo));
92 new_state(PORT_STATE_OUT_SETUP);
95 case MESSAGE_PROCEEDING:
96 new_state(PORT_STATE_IN_PROCEEDING);
99 case MESSAGE_ALERTING:
100 new_state(PORT_STATE_IN_ALERTING);
103 case MESSAGE_CONNECT:
104 new_state(PORT_STATE_CONNECT);
107 case MESSAGE_DISCONNECT:
108 new_state(PORT_STATE_OUT_DISCONNECT);
111 case MESSAGE_RELEASE:
112 new_state(PORT_STATE_RELEASE);
116 /* look for Remote's interface */
117 if (admin_message_from_lcr(p_r_remote_id, p_r_ref, message_type, param)<0) {
118 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);
122 if (message_type == MESSAGE_RELEASE) {
123 new_state(PORT_STATE_RELEASE);
131 void Premote::message_remote(int message_type, union parameter *param)
133 class Endpoint *epoint;
134 struct lcr_msg *message;
135 struct interface *interface;
137 switch (message_type) {
138 case MESSAGE_TRAFFIC:
139 bridge_tx(param->traffic.data, param->traffic.len);
143 interface = getinterfacebyname(p_interface_name);
145 PERROR("Cannot find interface %s.\n", p_interface_name);
149 /* enable audio path */
150 if (interface->is_tones == IS_YES) {
151 union parameter newparam;
152 memset(&newparam, 0, sizeof(union parameter));
153 admin_message_from_lcr(p_r_remote_id, p_r_ref, MESSAGE_PATTERN, &newparam);
154 newparam.audiopath = 1;
155 admin_message_from_lcr(p_r_remote_id, p_r_ref, MESSAGE_AUDIOPATH, &newparam);
158 /* set source interface */
159 param->setup.callerinfo.itype = p_callerinfo.itype;
160 SCPY(param->setup.callerinfo.interface, interface->name);
162 /* create endpoint */
164 FATAL("Incoming call but already got an endpoint.\n");
165 if (!(epoint = new Endpoint(p_serial, 0)))
166 FATAL("No memory for Endpoint instance\n");
167 epoint->ep_app = new_endpointapp(epoint, 0, interface->app); //incoming
169 epointlist_new(epoint->ep_serial);
171 new_state(PORT_STATE_IN_SETUP);
174 case MESSAGE_PROCEEDING:
175 new_state(PORT_STATE_OUT_PROCEEDING);
178 case MESSAGE_ALERTING:
179 new_state(PORT_STATE_OUT_ALERTING);
182 case MESSAGE_CONNECT:
183 new_state(PORT_STATE_CONNECT);
186 case MESSAGE_DISCONNECT:
187 new_state(PORT_STATE_IN_DISCONNECT);
190 case MESSAGE_RELEASE:
191 new_state(PORT_STATE_RELEASE);
195 /* cannot just forward, because param is not of container "struct lcr_msg" */
196 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, message_type);
197 memcpy(&message->param, param, sizeof(message->param));
198 message_put(message);
200 if (message_type == MESSAGE_RELEASE) {
201 new_state(PORT_STATE_RELEASE);
207 /* receive from remote Port instance */
208 int Premote::bridge_rx(unsigned char *data, int len)
210 union parameter newparam;
213 /* don't send tones, if not enabled or not connected */
215 && p_state != PORT_STATE_CONNECT)
218 memset(&newparam, 0, sizeof(union parameter));
219 /* split, if exeeds data size */
221 l = (len > (int)sizeof(newparam.traffic.data)) ? sizeof(newparam.traffic.data) : len;
222 newparam.traffic.len = l;
224 memcpy(newparam.traffic.data, data, l);
226 admin_message_from_lcr(p_r_remote_id, p_r_ref, MESSAGE_TRAFFIC, &newparam);