1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
7 ** MNCC-Interface: Harald Welte **
11 \*****************************************************************************/
20 #include "gsm_audio.h"
25 #define SOCKET_RETRY_TIMER 5
27 //struct lcr_gsm *gsm = NULL;
31 /* names of MNCC-SAP */
32 static const struct _value_string {
36 { 0, "New call ref" },
37 { 1, "Codec negotiation" },
38 { MNCC_SETUP_REQ, "MNCC_SETUP_REQ" },
39 { MNCC_SETUP_IND, "MNCC_SETUP_IND" },
40 { MNCC_SETUP_RSP, "MNCC_SETUP_RSP" },
41 { MNCC_SETUP_CNF, "MNCC_SETUP_CNF" },
42 { MNCC_SETUP_COMPL_REQ, "MNCC_SETUP_COMPL_REQ" },
43 { MNCC_SETUP_COMPL_IND, "MNCC_SETUP_COMPL_IND" },
44 { MNCC_CALL_CONF_IND, "MNCC_CALL_CONF_IND" },
45 { MNCC_CALL_PROC_REQ, "MNCC_CALL_PROC_REQ" },
46 { MNCC_PROGRESS_REQ, "MNCC_PROGRESS_REQ" },
47 { MNCC_ALERT_REQ, "MNCC_ALERT_REQ" },
48 { MNCC_ALERT_IND, "MNCC_ALERT_IND" },
49 { MNCC_NOTIFY_REQ, "MNCC_NOTIFY_REQ" },
50 { MNCC_NOTIFY_IND, "MNCC_NOTIFY_IND" },
51 { MNCC_DISC_REQ, "MNCC_DISC_REQ" },
52 { MNCC_DISC_IND, "MNCC_DISC_IND" },
53 { MNCC_REL_REQ, "MNCC_REL_REQ" },
54 { MNCC_REL_IND, "MNCC_REL_IND" },
55 { MNCC_REL_CNF, "MNCC_REL_CNF" },
56 { MNCC_FACILITY_REQ, "MNCC_FACILITY_REQ" },
57 { MNCC_FACILITY_IND, "MNCC_FACILITY_IND" },
58 { MNCC_START_DTMF_IND, "MNCC_START_DTMF_IND" },
59 { MNCC_START_DTMF_RSP, "MNCC_START_DTMF_RSP" },
60 { MNCC_START_DTMF_REJ, "MNCC_START_DTMF_REJ" },
61 { MNCC_STOP_DTMF_IND, "MNCC_STOP_DTMF_IND" },
62 { MNCC_STOP_DTMF_RSP, "MNCC_STOP_DTMF_RSP" },
63 { MNCC_MODIFY_REQ, "MNCC_MODIFY_REQ" },
64 { MNCC_MODIFY_IND, "MNCC_MODIFY_IND" },
65 { MNCC_MODIFY_RSP, "MNCC_MODIFY_RSP" },
66 { MNCC_MODIFY_CNF, "MNCC_MODIFY_CNF" },
67 { MNCC_MODIFY_REJ, "MNCC_MODIFY_REJ" },
68 { MNCC_HOLD_IND, "MNCC_HOLD_IND" },
69 { MNCC_HOLD_CNF, "MNCC_HOLD_CNF" },
70 { MNCC_HOLD_REJ, "MNCC_HOLD_REJ" },
71 { MNCC_RETRIEVE_IND, "MNCC_RETRIEVE_IND" },
72 { MNCC_RETRIEVE_CNF, "MNCC_RETRIEVE_CNF" },
73 { MNCC_RETRIEVE_REJ, "MNCC_RETRIEVE_REJ" },
74 { MNCC_USERINFO_REQ, "MNCC_USERINFO_REQ" },
75 { MNCC_USERINFO_IND, "MNCC_USERINFO_IND" },
76 { MNCC_REJ_REQ, "MNCC_REJ_REQ" },
77 { MNCC_REJ_IND, "MNCC_REJ_IND" },
78 { MNCC_PROGRESS_IND, "MNCC_PROGRESS_IND" },
79 { MNCC_CALL_PROC_IND, "MNCC_CALL_PROC_IND" },
80 { MNCC_CALL_CONF_REQ, "MNCC_CALL_CONF_REQ" },
81 { MNCC_START_DTMF_REQ, "MNCC_START_DTMF_REQ" },
82 { MNCC_STOP_DTMF_REQ, "MNCC_STOP_DTMF_REQ" },
83 { MNCC_HOLD_REQ, "MNCC_HOLD_REQ " },
84 { MNCC_RETRIEVE_REQ, "MNCC_RETRIEVE_REQ" },
86 { MNCC_LCHAN_MODIFY, "MNCC_LCHAN_MODIFY" },
88 { MNCC_BRIDGE, "MNCC_BRIDGE" },
89 { MNCC_FRAME_RECV, "MNCC_FRAME_RECV" },
90 { MNCC_FRAME_DROP, "MNCC_FRAME_DROP" },
91 { MNCC_RTP_CREATE, "MNCC_RTP_CREATE" },
92 { MNCC_RTP_CONNECT, "MNCC_RTP_CONNECT" },
93 { MNCC_RTP_FREE, "MNCC_RTP_FREE" },
98 const char *mncc_name(int value)
103 while (mncc_names[i].name) {
104 if (mncc_names[i].msg_type == value)
105 return mncc_names[i].name;
108 SPRINT(ukn, "unknown(0x%x)", value);
112 static int mncc_send(struct lcr_gsm *lcr_gsm, int msg_type, void *data);
115 * create and send mncc message
117 struct gsm_mncc *create_mncc(int msg_type, unsigned int callref)
119 struct gsm_mncc *mncc;
121 mncc = (struct gsm_mncc *)MALLOC(sizeof(struct gsm_mncc));
122 mncc->msg_type = msg_type;
123 mncc->callref = callref;
126 int send_and_free_mncc(struct lcr_gsm *lcr_gsm, unsigned int msg_type, void *data)
131 ret = mncc_send(lcr_gsm, msg_type, data);
138 void Pgsm::send_mncc_rtp_connect(void)
140 struct gsm_mncc_rtp *nrtp;
142 nrtp = (struct gsm_mncc_rtp *) create_mncc(MNCC_RTP_CONNECT, p_g_callref);
143 nrtp->ip = p_g_rtp_ip_remote;
144 nrtp->port = p_g_rtp_port_remote;
145 switch (p_g_media_type) {
147 nrtp->payload_msg_type = GSM_TCHF_FRAME;
149 case MEDIA_TYPE_GSM_EFR:
150 nrtp->payload_msg_type = GSM_TCHF_FRAME_EFR;
153 nrtp->payload_msg_type = GSM_TCH_FRAME_AMR;
155 case MEDIA_TYPE_GSM_HR:
156 nrtp->payload_msg_type = GSM_TCHH_FRAME;
159 nrtp->payload_type = p_g_payload_type;
160 PDEBUG(DEBUG_GSM, "sending MNCC RTP connect with payload_msg_type=%x, payload_type=%d\n", nrtp->payload_msg_type, nrtp->payload_type);
161 send_and_free_mncc(p_g_lcr_gsm, nrtp->msg_type, nrtp);
164 static int delete_event(struct lcr_work *work, void *instance, int index);
169 Pgsm::Pgsm(int type, char *portname, struct port_settings *settings, struct interface *interface) : Port(type, portname, settings, interface)
172 signed short homing[160];
177 if (interface->is_tones == IS_YES)
180 if (interface->is_earlyb == IS_YES)
183 if (interface->rtp_bridge)
185 p_g_rtp_payloads = 0;
186 memset(&p_g_samples, 0, sizeof(p_g_samples));
187 p_callerinfo.itype = (interface->extension)?INFO_ITYPE_ISDN_EXTENSION:INFO_ITYPE_ISDN;
188 memset(&p_g_delete, 0, sizeof(p_g_delete));
189 add_work(&p_g_delete, delete_event, this, 0);
194 p_g_gsm_b_index = -1;
195 p_g_gsm_b_active = 0;
196 p_g_notify_pending = NULL;
197 p_g_setup_pending = NULL;
198 p_g_connect_pending = NULL;
199 p_g_fr_decoder = NULL;
200 p_g_fr_encoder = NULL;
201 p_g_hr_decoder = NULL;
202 p_g_hr_encoder = NULL;
203 p_g_amr_decoder = NULL;
204 p_g_amr_encoder = NULL;
206 p_g_amr_cmr_valid = 0;
208 p_g_fr_decoder = gsm_fr_create();
209 p_g_fr_encoder = gsm_fr_create();
210 if (!p_g_fr_encoder || !p_g_fr_decoder) {
211 PERROR("Failed to create GSM FR codec instance\n");
212 trigger_work(&p_g_delete);
216 p_g_hr_decoder = gsm_hr_create();
217 p_g_hr_encoder = gsm_hr_create();
218 if (!p_g_hr_encoder || !p_g_hr_decoder) {
219 PERROR("Failed to create GSM HR codec instance\n");
220 trigger_work(&p_g_delete);
223 for (i = 0; i < 160; i++)
225 gsm_hr_encode(p_g_hr_encoder, homing, NULL);
228 p_g_amr_decoder = gsm_amr_create();
229 p_g_amr_encoder = gsm_amr_create();
230 if (!p_g_amr_encoder || !p_g_amr_decoder) {
231 PERROR("Failed to create GSM AMR codec instance\n");
232 trigger_work(&p_g_delete);
236 p_g_tch_connected = 0;
239 PDEBUG(DEBUG_GSM, "Created new GSMPort(%s).\n", portname);
247 PDEBUG(DEBUG_GSM, "Destroyed GSM process(%s).\n", p_name);
249 del_work(&p_g_delete);
251 /* remove queued message */
252 if (p_g_notify_pending)
253 message_free(p_g_notify_pending);
254 if (p_g_setup_pending)
255 message_free(p_g_setup_pending);
256 if (p_g_connect_pending)
257 message_free(p_g_connect_pending);
262 gsm_fr_destroy(p_g_fr_encoder);
264 gsm_fr_destroy(p_g_fr_decoder);
268 gsm_hr_destroy(p_g_hr_encoder);
270 gsm_hr_destroy(p_g_hr_decoder);
275 gsm_amr_destroy(p_g_amr_encoder);
277 gsm_amr_destroy(p_g_amr_decoder);
282 /* receive encoded frame from gsm */
283 void Pgsm::frame_receive(void *arg)
285 struct gsm_data_frame *frame = (struct gsm_data_frame *)arg;
286 unsigned char data[160];
292 switch (frame->msg_type) {
294 if (p_g_media_type != MEDIA_TYPE_GSM) {
295 PERROR("FR frame, but current media type mismatches.\n");
298 if (!p_g_fr_decoder) {
299 PERROR("FR frame, but decoder not created.\n");
302 if ((frame->data[0]>>4) != 0xd) {
303 PDEBUG(DEBUG_GSM, "received GSM frame with wrong magig 0x%x\n", frame->data[0]>>4);
308 gsm_fr_decode(p_g_fr_decoder, frame->data, p_g_samples);
309 for (i = 0; i < 160; i++) {
310 data[i] = audio_s16_to_law[p_g_samples[i] & 0xffff];
315 if (p_g_media_type != MEDIA_TYPE_GSM_HR) {
316 PERROR("HR frame, but current media type mismatches.\n");
319 if (!p_g_hr_decoder) {
320 PERROR("HR frame, but decoder not created.\n");
323 if ((frame->data[0]>>4) != 0x0)
327 if (gsm_hr_decode(p_g_hr_decoder, frame->data, p_g_samples))
329 for (i = 0; i < 160; i++) {
330 data[i] = audio_s16_to_law[p_g_samples[i] & 0xffff];
334 case GSM_TCHF_FRAME_EFR:
335 if (p_g_media_type != MEDIA_TYPE_GSM_EFR) {
336 PERROR("EFR frame, but current media type mismatches.\n");
339 if (!p_g_amr_decoder) {
340 PERROR("EFR frame, but decoder not created.\n");
343 if ((frame->data[0]>>4) != 0xc)
347 gsm_efr_decode(p_g_amr_decoder, frame->data, p_g_samples);
348 for (i = 0; i < 160; i++) {
349 data[i] = audio_s16_to_law[p_g_samples[i] & 0xffff];
353 case GSM_TCH_FRAME_AMR:
354 if (p_g_media_type != MEDIA_TYPE_AMR) {
355 PERROR("AMR frame, but current media type mismatches.\n");
358 if (!p_g_amr_decoder) {
359 PERROR("AMR frame, but decoder not created.\n");
362 cmr = (frame->data[1] >> 4);
365 p_g_amr_cmr_valid = 1;
367 if (!(frame->data[2] & 0x04))
370 /* decode (skip length byte in front) */
371 gsm_amr_decode(p_g_amr_decoder, frame->data + 1, p_g_samples);
372 for (i = 0; i < 160; i++) {
373 data[i] = audio_s16_to_law[p_g_samples[i] & 0xffff];
381 /* beep on bad frame */
382 for (i = 0; i < 160; i++) {
384 p_g_samples[i] = 15000;
386 p_g_samples[i] = -15000;
387 data[i] = audio_s16_to_law[p_g_samples[i] & 0xffff];
390 /* repeat on bad frame */
391 for (i = 0; i < 160; i++) {
392 p_g_samples[i] = (p_g_samples[i] * 14) >> 4;
393 data[i] = audio_s16_to_law[p_g_samples[i] & 0xffff];
400 record(data, 160, 0); // from down
402 tap(data, 160, 0); // from down
406 bridge_rx(data, 160);
409 bridge_tx(data, 160);
412 /* send traffic to gsm */
413 int Pgsm::bridge_rx(unsigned char *data, int len)
417 if ((ret = Port::bridge_rx(data, len)))
423 return audio_send(data, len);
426 int Pgsm::audio_send(unsigned char *data, int len)
428 unsigned char frame[33];
433 record(data, len, 1); // from up
435 tap(data, len, 1); // from up
437 /* (currently) not connected, so don't flood tch! */
438 if (!p_g_tch_connected)
441 /* write to rx buffer */
443 p_g_rxdata[p_g_rxpos++] = audio_law_to_s32[*data++];
444 if (p_g_rxpos != 160)
448 switch (p_g_media_type) {
450 if (!p_g_fr_encoder) {
451 PERROR("FR frame, but encoder not created.\n");
456 gsm_fr_encode(p_g_fr_encoder, p_g_rxdata, frame);
457 frame_send(frame, 33, GSM_TCHF_FRAME);
460 case MEDIA_TYPE_GSM_HR:
461 if (!p_g_hr_encoder) {
462 PERROR("HR frame, but encoder not created.\n");
467 gsm_hr_encode(p_g_hr_encoder, p_g_rxdata, frame);
468 frame_send(frame, 15, GSM_TCHH_FRAME);
471 case MEDIA_TYPE_GSM_EFR:
472 if (!p_g_amr_encoder) {
473 PERROR("EFR frame, but encoder not created.\n");
478 gsm_efr_encode(p_g_amr_encoder, p_g_rxdata, frame);
479 frame_send(frame, 31, GSM_TCHF_FRAME_EFR);
483 if (!p_g_amr_encoder) {
484 PERROR("AMR frame, but encoder not created.\n");
487 if (!p_g_amr_cmr_valid) {
488 PDEBUG(DEBUG_GSM, "no valid CMR yet.\n");
492 /* encode data (prefix a length byte) */
493 ret = gsm_amr_encode(p_g_amr_encoder, p_g_rxdata, frame + 1, p_g_amr_cmr);
495 frame_send(frame, ret + 1, GSM_TCH_FRAME_AMR);
504 void Pgsm::frame_send(void *_frame, int len, int msg_type)
506 unsigned char buffer[sizeof(struct gsm_data_frame) + len];
507 struct gsm_data_frame *frame = (struct gsm_data_frame *)buffer;
509 frame->msg_type = msg_type;
510 frame->callref = p_g_callref;
511 memcpy(frame->data, _frame, len);
514 mncc_send(p_g_lcr_gsm, frame->msg_type, frame);
521 void gsm_trace_header(const char *interface_name, class Pgsm *port, unsigned int msg_type, int direction)
524 struct interface *interface = interface_first;
526 interface = getinterfacebyname(interface_name);
530 /* select message and primitive text */
531 SCPY(msgtext, mncc_name(msg_type));
535 switch(port->p_type) {
536 case PORT_TYPE_GSM_BS_OUT:
537 case PORT_TYPE_GSM_BS_IN:
538 SCAT(msgtext, " LCR<->BSC");
540 case PORT_TYPE_GSM_MS_OUT:
541 case PORT_TYPE_GSM_MS_IN:
542 SCAT(msgtext, " LCR<->MS");
546 SCAT(msgtext, " ----");
548 /* init trace with given values */
551 port?numberrize_callerinfo(port->p_callerinfo.id, port->p_callerinfo.ntype, options.national, options.international):NULL,
552 port?port->p_dialinginfo.id:NULL,
555 port?port->p_serial:0,
559 /* modify lchan to given payload type */
560 void Pgsm::modify_lchan(int media_type)
562 struct gsm_mncc *mode;
564 /* already modified to that media type */
565 if (p_g_media_type == media_type)
568 p_g_media_type = media_type;
569 gsm_trace_header(p_interface_name, this, MNCC_LCHAN_MODIFY, DIRECTION_OUT);
570 mode = create_mncc(MNCC_LCHAN_MODIFY, p_g_callref);
571 switch (media_type) {
572 case MEDIA_TYPE_GSM_EFR:
573 add_trace("speech", "version", "EFR given");
574 mode->lchan_mode = 0x21; /* GSM V2 */
575 mode->lchan_type = 0x02; /* TCH/F */
578 add_trace("speech", "version", "AMR given");
579 mode->lchan_mode = 0x41; /* GSM V3 */
580 /* as we don't know the available channels, this type will be set by openbsc automatically */
581 mode->lchan_type = 0x02; /* TCH/F */
583 case MEDIA_TYPE_GSM_HR:
584 add_trace("speech", "version", "Half Rate given");
585 mode->lchan_mode = 0x01; /* GSM V1 */
586 mode->lchan_type = 0x03; /* TCH/H */
588 add_trace("speech", "version", "Full Rate given");
589 mode->lchan_mode = 0x01; /* GSM V1 */
590 mode->lchan_type = 0x02; /* TCH/F */
592 add_trace("mode", NULL, "0x%02x", mode->lchan_mode);
594 send_and_free_mncc(p_g_lcr_gsm, mode->msg_type, mode);
597 /* CALL PROCEEDING INDICATION (from network) */
598 void Pgsm::call_proc_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
600 struct lcr_msg *message;
601 struct gsm_mncc *frame;
603 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
606 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
607 message_put(message);
609 new_state(PORT_STATE_OUT_PROCEEDING);
611 if (p_g_earlyb && !p_g_tch_connected) { /* only if ... */
612 gsm_trace_header(p_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
614 frame = create_mncc(MNCC_FRAME_RECV, p_g_callref);
615 send_and_free_mncc(p_g_lcr_gsm, frame->msg_type, frame);
616 p_g_tch_connected = 1;
619 /* modify to GSM FR (this is GSM user side only, so there is FR supported only) */
620 modify_lchan(MEDIA_TYPE_GSM);
623 /* ALERTING INDICATION */
624 void Pgsm::alert_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
626 struct lcr_msg *message;
627 struct gsm_mncc *frame;
629 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
632 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
633 message_put(message);
635 new_state(PORT_STATE_OUT_ALERTING);
637 if (p_g_earlyb && !p_g_tch_connected) { /* only if ... */
638 gsm_trace_header(p_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
640 frame = create_mncc(MNCC_FRAME_RECV, p_g_callref);
641 send_and_free_mncc(p_g_lcr_gsm, frame->msg_type, frame);
642 p_g_tch_connected = 1;
645 /* modify to GSM FR, if not already */
646 if (!p_g_media_type) {
647 modify_lchan(MEDIA_TYPE_GSM);
651 /* CONNECT INDICATION */
652 void Pgsm::setup_cnf(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
654 struct gsm_mncc *resp, *frame;
655 struct lcr_msg *message;
657 SCPY(p_connectinfo.id, mncc->connected.number);
658 SCPY(p_connectinfo.imsi, mncc->imsi);
659 p_connectinfo.present = INFO_PRESENT_ALLOWED;
660 p_connectinfo.screen = INFO_SCREEN_NETWORK;
661 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
662 SCPY(p_connectinfo.interface, p_interface_name);
664 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
665 if (p_connectinfo.id[0])
666 add_trace("connect", "number", "%s", p_connectinfo.id);
667 else if (mncc->imsi[0])
668 SPRINT(p_connectinfo.id, "imsi-%s", p_connectinfo.imsi);
670 add_trace("connect", "imsi", "%s", p_connectinfo.imsi);
674 gsm_trace_header(p_interface_name, this, MNCC_SETUP_COMPL_REQ, DIRECTION_OUT);
675 resp = create_mncc(MNCC_SETUP_COMPL_REQ, p_g_callref);
677 send_and_free_mncc(p_g_lcr_gsm, resp->msg_type, resp);
679 new_state(PORT_STATE_CONNECT);
681 if (!p_g_tch_connected) { /* only if ... */
682 gsm_trace_header(p_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
684 frame = create_mncc(MNCC_FRAME_RECV, p_g_callref);
685 send_and_free_mncc(p_g_lcr_gsm, frame->msg_type, frame);
686 p_g_tch_connected = 1;
689 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
690 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
692 /* if we have a bridge, but not yet modified, the phone accepts out requested payload.
693 * we force the first in list */
694 if (p_g_rtp_bridge) {
695 if (!p_g_media_type) {
696 /* modify to first given type */
697 modify_lchan(p_g_rtp_media_types[0]);
698 /* also set payload type */
699 p_g_payload_type = p_g_rtp_payload_types[0];
701 message->param.connectinfo.rtpinfo.media_types[0] = p_g_media_type;
702 message->param.connectinfo.rtpinfo.payload_types[0] = p_g_payload_type;
703 message->param.connectinfo.rtpinfo.payloads = 1;
705 /* modify to GSM FR, if not already
706 * for network side, this should have been already happened */
708 modify_lchan(MEDIA_TYPE_GSM);
712 if (p_g_rtp_bridge) {
713 struct gsm_mncc_rtp *rtp;
715 PDEBUG(DEBUG_GSM, "Request RTP peer info, before forwarding connect msg\n");
716 p_g_connect_pending = message;
717 rtp = (struct gsm_mncc_rtp *) create_mncc(MNCC_RTP_CREATE, p_g_callref);
718 send_and_free_mncc(p_g_lcr_gsm, rtp->msg_type, rtp);
720 message_put(message);
723 /* CONNECT ACK INDICATION */
724 void Pgsm::setup_compl_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
726 struct gsm_mncc *frame;
728 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
731 new_state(PORT_STATE_CONNECT);
733 if (!p_g_tch_connected) { /* only if ... */
734 gsm_trace_header(p_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
736 frame = create_mncc(MNCC_FRAME_RECV, p_g_callref);
737 send_and_free_mncc(p_g_lcr_gsm, frame->msg_type, frame);
738 p_g_tch_connected = 1;
741 /* modify to GSM FR, if not already */
742 if (!p_g_media_type) {
743 modify_lchan(MEDIA_TYPE_GSM);
747 /* DISCONNECT INDICATION */
748 void Pgsm::disc_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
750 struct lcr_msg *message;
751 int cause = 16, location = 0;
752 struct gsm_mncc *resp;
754 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
755 if (mncc->fields & MNCC_F_CAUSE) {
756 location = mncc->cause.location;
757 cause = mncc->cause.value;
758 add_trace("cause", "coding", "%d", mncc->cause.coding);
759 add_trace("cause", "location", "%d", location);
760 add_trace("cause", "value", "%d", cause);
765 resp = create_mncc(MNCC_REL_REQ, p_g_callref);
766 gsm_trace_header(p_interface_name, this, MNCC_REL_REQ, DIRECTION_OUT);
768 resp->fields |= MNCC_F_CAUSE;
769 resp->cause.coding = 3;
770 resp->cause.location = 1;
771 resp->cause.value = cause;
772 add_trace("cause", "coding", "%d", resp->cause.coding);
773 add_trace("cause", "location", "%d", resp->cause.location);
774 add_trace("cause", "value", "%d", resp->cause.value);
777 send_and_free_mncc(p_g_lcr_gsm, resp->msg_type, resp);
779 /* sending release to endpoint */
780 while(p_epointlist) {
781 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
782 message->param.disconnectinfo.cause = cause;
783 message->param.disconnectinfo.location = location;
784 message_put(message);
786 free_epointlist(p_epointlist);
788 new_state(PORT_STATE_RELEASE);
789 trigger_work(&p_g_delete);
792 /* CC_RELEASE INDICATION */
793 void Pgsm::rel_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
795 int location = 0, cause = 16;
796 struct lcr_msg *message;
798 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
799 if (mncc->fields & MNCC_F_CAUSE) {
800 location = mncc->cause.location;
801 cause = mncc->cause.value;
802 add_trace("cause", "coding", "%d", mncc->cause.coding);
803 add_trace("cause", "location", "%d", mncc->cause.location);
804 add_trace("cause", "value", "%d", mncc->cause.value);
808 /* sending release to endpoint */
809 while(p_epointlist) {
810 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
811 message->param.disconnectinfo.cause = cause;
812 message->param.disconnectinfo.location = location;
813 message_put(message);
815 free_epointlist(p_epointlist);
817 new_state(PORT_STATE_RELEASE);
818 trigger_work(&p_g_delete);
821 /* NOTIFY INDICATION */
822 void Pgsm::notify_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
824 struct lcr_msg *message;
826 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
827 add_trace("notify", NULL, "%d", mncc->notify);
830 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
831 message->param.notifyinfo.notify = mncc->notify;
832 message_put(message);
836 void Pgsm::message_notify(unsigned int epoint_id, int message_id, union parameter *param)
838 struct gsm_mncc *mncc;
841 // printf("if = %d\n", param->notifyinfo.notify);
842 if (param->notifyinfo.notify>INFO_NOTIFY_NONE) {
843 notify = param->notifyinfo.notify & 0x7f;
844 if (p_state!=PORT_STATE_CONNECT /*&& p_state!=PORT_STATE_IN_PROCEEDING*/ && p_state!=PORT_STATE_IN_ALERTING) {
845 /* queue notification */
846 if (p_g_notify_pending)
847 message_free(p_g_notify_pending);
848 p_g_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
849 memcpy(&p_g_notify_pending->param, param, sizeof(union parameter));
851 /* sending notification */
852 gsm_trace_header(p_interface_name, this, MNCC_NOTIFY_REQ, DIRECTION_OUT);
853 add_trace("notify", NULL, "%d", notify);
855 mncc = create_mncc(MNCC_NOTIFY_REQ, p_g_callref);
856 mncc->notify = notify;
857 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
862 /* RTP create indication */
863 void Pgsm::rtp_create_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
865 struct gsm_mncc_rtp *rtp = (struct gsm_mncc_rtp *) mncc;
867 /* send queued setup, as we received remote RTP info */
868 if (p_g_setup_pending) {
869 struct lcr_msg *message;
871 message = p_g_setup_pending;
872 PDEBUG(DEBUG_GSM, "Got RTP peer info (%08x,%d) forwarding setup\n", rtp->ip, rtp->port);
873 message->param.setup.rtpinfo.ip = rtp->ip;
874 message->param.setup.rtpinfo.port = rtp->port;
875 message_put(message);
876 p_g_setup_pending = NULL;
878 if (p_g_connect_pending) {
879 PDEBUG(DEBUG_GSM, "Got RTP peer info (%08x,%d) connecting RTP... \n", rtp->ip, rtp->port);
880 send_mncc_rtp_connect();
884 /* RTP connect indication */
885 void Pgsm::rtp_connect_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
887 struct lcr_msg *message;
888 struct gsm_mncc_rtp *rtp = (struct gsm_mncc_rtp *) mncc;
890 if (p_g_connect_pending) {
891 message = p_g_connect_pending;
892 PDEBUG(DEBUG_GSM, "Got RTP peer info (%08x,%d) forwarding connect\n", rtp->ip, rtp->port);
893 message->param.connectinfo.rtpinfo.ip = rtp->ip;
894 message->param.connectinfo.rtpinfo.port = rtp->port;
895 message_put(message);
896 p_g_connect_pending = NULL;
900 /* MESSAGE_PROGRESS */
901 void Pgsm::message_progress(unsigned int epoint_id, int message_id, union parameter *param)
903 if (param->progressinfo.progress == 8) {
904 PDEBUG(DEBUG_GSM, "Remote provides tones for us\n");
908 if (param->progressinfo.rtpinfo.port) {
909 PDEBUG(DEBUG_GSM, "PROGRESS with RTP peer info, sent to BSC (%08x,%d) with media %d, pt %d\n", param->progressinfo.rtpinfo.ip, param->progressinfo.rtpinfo.port, param->progressinfo.rtpinfo.media_types[0], param->progressinfo.rtpinfo.payload_types[0]);
911 /* modify channel to givne type, also sets media type */
912 modify_lchan(param->progressinfo.rtpinfo.media_types[0]);
915 p_g_rtp_ip_remote = param->progressinfo.rtpinfo.ip;
916 p_g_rtp_port_remote = param->progressinfo.rtpinfo.port;
917 /* p_g_media_type is already set by modify_lchan() */
918 p_g_payload_type = param->progressinfo.rtpinfo.payload_types[0];
919 send_mncc_rtp_connect();
923 /* MESSAGE_ALERTING */
924 void Pgsm::message_alerting(unsigned int epoint_id, int message_id, union parameter *param)
926 struct gsm_mncc *mncc;
929 gsm_trace_header(p_interface_name, this, MNCC_ALERT_REQ, DIRECTION_OUT);
930 mncc = create_mncc(MNCC_ALERT_REQ, p_g_callref);
932 mncc->fields |= MNCC_F_PROGRESS;
933 mncc->progress.coding = 3; /* GSM */
934 mncc->progress.location = 1;
935 mncc->progress.descr = 8;
936 add_trace("progress", "coding", "%d", mncc->progress.coding);
937 add_trace("progress", "location", "%d", mncc->progress.location);
938 add_trace("progress", "descr", "%d", mncc->progress.descr);
941 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
943 new_state(PORT_STATE_IN_ALERTING);
945 if (p_g_tones && !p_g_tch_connected) { /* only if ... */
946 gsm_trace_header(p_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
948 mncc = create_mncc(MNCC_FRAME_RECV, p_g_callref);
949 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
950 p_g_tch_connected = 1;
953 /* modify to GSM FR, if not already */
954 if (!p_g_media_type) {
955 modify_lchan(MEDIA_TYPE_GSM);
959 /* MESSAGE_CONNECT */
960 void Pgsm::message_connect(unsigned int epoint_id, int message_id, union parameter *param)
962 struct gsm_mncc *mncc;
964 /* copy connected information */
965 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
966 /* screen outgoing caller id */
967 do_screen(1, p_connectinfo.id, sizeof(p_connectinfo.id), &p_connectinfo.ntype, &p_connectinfo.present, p_interface_name);
970 mncc = create_mncc(MNCC_SETUP_RSP, p_g_callref);
971 gsm_trace_header(p_interface_name, this, MNCC_SETUP_RSP, DIRECTION_OUT);
972 /* caller information */
973 mncc->fields |= MNCC_F_CONNECTED;
974 mncc->connected.plan = 1;
975 switch (p_callerinfo.ntype) {
976 case INFO_NTYPE_UNKNOWN:
977 mncc->connected.type = 0x0;
979 case INFO_NTYPE_INTERNATIONAL:
980 mncc->connected.type = 0x1;
982 case INFO_NTYPE_NATIONAL:
983 mncc->connected.type = 0x2;
985 case INFO_NTYPE_SUBSCRIBER:
986 mncc->connected.type = 0x4;
988 default: /* INFO_NTYPE_NOTPRESENT */
989 mncc->fields &= ~MNCC_F_CONNECTED;
992 switch (p_callerinfo.screen) {
993 case INFO_SCREEN_USER:
994 mncc->connected.screen = 0;
996 default: /* INFO_SCREEN_NETWORK */
997 mncc->connected.screen = 3;
1000 switch (p_callerinfo.present) {
1001 case INFO_PRESENT_ALLOWED:
1002 mncc->connected.present = 0;
1004 case INFO_PRESENT_RESTRICTED:
1005 mncc->connected.present = 1;
1007 default: /* INFO_PRESENT_NOTAVAIL */
1008 mncc->connected.present = 2;
1011 if (mncc->fields & MNCC_F_CONNECTED) {
1012 SCPY(mncc->connected.number, p_connectinfo.id);
1013 add_trace("connected", "type", "%d", mncc->connected.type);
1014 add_trace("connected", "plan", "%d", mncc->connected.plan);
1015 add_trace("connected", "present", "%d", mncc->connected.present);
1016 add_trace("connected", "screen", "%d", mncc->connected.screen);
1017 add_trace("connected", "number", "%s", mncc->connected.number);
1020 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
1022 new_state(PORT_STATE_CONNECT_WAITING);
1024 if (param->connectinfo.rtpinfo.port) {
1025 PDEBUG(DEBUG_GSM, "CONNECT with RTP peer info, sent to BSC (%08x,%d)\n", param->connectinfo.rtpinfo.ip, param->connectinfo.rtpinfo.port);
1027 /* modify channel to givne type, also sets media type */
1028 modify_lchan(param->connectinfo.rtpinfo.media_types[0]);
1031 p_g_rtp_ip_remote = param->connectinfo.rtpinfo.ip;
1032 p_g_rtp_port_remote = param->connectinfo.rtpinfo.port;
1033 /* p_g_media_type is already set by modify_lchan() */
1034 p_g_payload_type = param->connectinfo.rtpinfo.payload_types[0];
1035 send_mncc_rtp_connect();
1039 /* MESSAGE_DISCONNECT */
1040 void Pgsm::message_disconnect(unsigned int epoint_id, int message_id, union parameter *param)
1042 struct gsm_mncc *mncc;
1044 /* send disconnect */
1045 mncc = create_mncc(MNCC_DISC_REQ, p_g_callref);
1046 gsm_trace_header(p_interface_name, this, MNCC_DISC_REQ, DIRECTION_OUT);
1048 mncc->fields |= MNCC_F_PROGRESS;
1049 mncc->progress.coding = 3; /* GSM */
1050 mncc->progress.location = 1;
1051 mncc->progress.descr = 8;
1052 add_trace("progress", "coding", "%d", mncc->progress.coding);
1053 add_trace("progress", "location", "%d", mncc->progress.location);
1054 add_trace("progress", "descr", "%d", mncc->progress.descr);
1056 mncc->fields |= MNCC_F_CAUSE;
1057 mncc->cause.coding = 3;
1058 mncc->cause.location = param->disconnectinfo.location;
1059 mncc->cause.value = param->disconnectinfo.cause;
1060 add_trace("cause", "coding", "%d", mncc->cause.coding);
1061 add_trace("cause", "location", "%d", mncc->cause.location);
1062 add_trace("cause", "value", "%d", mncc->cause.value);
1064 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
1066 new_state(PORT_STATE_OUT_DISCONNECT);
1068 if (p_g_tones && !p_g_tch_connected) { /* only if ... */
1069 gsm_trace_header(p_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
1071 mncc = create_mncc(MNCC_FRAME_RECV, p_g_callref);
1072 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
1073 p_g_tch_connected = 1;
1078 /* MESSAGE_RELEASE */
1079 void Pgsm::message_release(unsigned int epoint_id, int message_id, union parameter *param)
1081 struct gsm_mncc *mncc;
1084 mncc = create_mncc(MNCC_REL_REQ, p_g_callref);
1085 gsm_trace_header(p_interface_name, this, MNCC_REL_REQ, DIRECTION_OUT);
1086 mncc->fields |= MNCC_F_CAUSE;
1087 mncc->cause.coding = 3;
1088 mncc->cause.location = param->disconnectinfo.location;
1089 mncc->cause.value = param->disconnectinfo.cause;
1090 add_trace("cause", "coding", "%d", mncc->cause.coding);
1091 add_trace("cause", "location", "%d", mncc->cause.location);
1092 add_trace("cause", "value", "%d", mncc->cause.value);
1094 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
1096 new_state(PORT_STATE_RELEASE);
1097 trigger_work(&p_g_delete);
1102 * endpoint sends messages to the port
1104 int Pgsm::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
1108 if (Port::message_epoint(epoint_id, message_id, param))
1111 switch(message_id) {
1112 case MESSAGE_NOTIFY: /* display and notifications */
1114 message_notify(epoint_id, message_id, param);
1117 // case MESSAGE_FACILITY: /* facility message */
1118 // message_facility(epoint_id, message_id, param);
1121 case MESSAGE_PROCEEDING: /* message not handles */
1125 case MESSAGE_PROGRESS:
1127 message_progress(epoint_id, message_id, param);
1130 case MESSAGE_ALERTING: /* call of endpoint is ringing */
1132 if (p_state!=PORT_STATE_IN_PROCEEDING)
1134 message_alerting(epoint_id, message_id, param);
1135 if (p_g_notify_pending) {
1136 /* send pending notify message during connect */
1137 message_notify(ACTIVE_EPOINT(p_epointlist), p_g_notify_pending->type, &p_g_notify_pending->param);
1138 message_free(p_g_notify_pending);
1139 p_g_notify_pending = NULL;
1143 case MESSAGE_CONNECT: /* call of endpoint is connected */
1145 if (p_state!=PORT_STATE_IN_PROCEEDING
1146 && p_state!=PORT_STATE_IN_ALERTING)
1148 message_connect(epoint_id, message_id, param);
1149 if (p_g_notify_pending) {
1150 /* send pending notify message during connect */
1151 message_notify(ACTIVE_EPOINT(p_epointlist), p_g_notify_pending->type, &p_g_notify_pending->param);
1152 message_free(p_g_notify_pending);
1153 p_g_notify_pending = NULL;
1157 case MESSAGE_DISCONNECT: /* call has been disconnected */
1159 if (p_state!=PORT_STATE_IN_PROCEEDING
1160 && p_state!=PORT_STATE_IN_ALERTING
1161 && p_state!=PORT_STATE_OUT_SETUP
1162 && p_state!=PORT_STATE_OUT_OVERLAP
1163 && p_state!=PORT_STATE_OUT_PROCEEDING
1164 && p_state!=PORT_STATE_OUT_ALERTING
1165 && p_state!=PORT_STATE_CONNECT
1166 && p_state!=PORT_STATE_CONNECT_WAITING)
1168 message_disconnect(epoint_id, message_id, param);
1171 case MESSAGE_RELEASE: /* release isdn port */
1173 if (p_state==PORT_STATE_RELEASE)
1175 message_release(epoint_id, message_id, param);
1183 /* deletes only if l3id is release, otherwhise it will be triggered then */
1184 static int delete_event(struct lcr_work *work, void *instance, int index)
1186 class Pgsm *gsmport = (class Pgsm *)instance;
1193 int gsm_exit(int rc)
1210 static int mncc_q_enqueue(struct lcr_gsm *lcr_gsm, struct gsm_mncc *mncc, unsigned int len)
1212 struct mncc_q_entry *qe;
1214 qe = (struct mncc_q_entry *) MALLOC(sizeof(*qe)+sizeof(*mncc)+len);
1220 memcpy(qe->data, mncc, len);
1222 /* in case of empty list ... */
1223 if (!lcr_gsm->mncc_q_hd && !lcr_gsm->mncc_q_tail) {
1224 /* the list head and tail both point to the new qe */
1225 lcr_gsm->mncc_q_hd = lcr_gsm->mncc_q_tail = qe;
1227 /* append to tail of list */
1228 lcr_gsm->mncc_q_tail->next = qe;
1229 lcr_gsm->mncc_q_tail = qe;
1232 lcr_gsm->mncc_lfd.when |= LCR_FD_WRITE;
1237 static struct mncc_q_entry *mncc_q_dequeue(struct lcr_gsm *lcr_gsm)
1239 struct mncc_q_entry *qe = lcr_gsm->mncc_q_hd;
1243 /* dequeue the successfully sent message */
1244 lcr_gsm->mncc_q_hd = qe->next;
1247 if (qe == lcr_gsm->mncc_q_tail)
1248 lcr_gsm->mncc_q_tail = NULL;
1253 /* routine called by LCR code if it wants to send a message to OpenBSC */
1254 static int mncc_send(struct lcr_gsm *lcr_gsm, int msg_type, void *data)
1258 /* FIXME: the caller should provide this */
1260 case GSM_TCHF_FRAME:
1261 len = sizeof(struct gsm_data_frame) + 33;
1264 len = sizeof(struct gsm_mncc);
1268 return mncc_q_enqueue(lcr_gsm, (struct gsm_mncc *)data, len);
1271 /* close MNCC socket */
1272 static int mncc_fd_close(struct lcr_gsm *lcr_gsm, struct lcr_fd *lfd)
1275 class Pgsm *pgsm = NULL;
1276 struct lcr_msg *message;
1278 PERROR("Lost MNCC socket, retrying in %u seconds\n", SOCKET_RETRY_TIMER);
1283 /* free all the calls that were running through the MNCC interface */
1286 if ((port->p_type & PORT_CLASS_mISDN_MASK) == PORT_CLASS_GSM) {
1287 pgsm = (class Pgsm *)port;
1288 if (pgsm->p_g_lcr_gsm == lcr_gsm) {
1289 message = message_create(pgsm->p_serial, ACTIVE_EPOINT(pgsm->p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1290 message->param.disconnectinfo.cause = 27; // temp. unavail.
1291 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1292 message_put(message);
1293 pgsm->new_state(PORT_STATE_RELEASE);
1294 trigger_work(&pgsm->p_g_delete);
1300 /* flush the queue */
1301 while (mncc_q_dequeue(lcr_gsm))
1304 /* start the re-connect timer */
1305 schedule_timer(&lcr_gsm->socket_retry, SOCKET_RETRY_TIMER, 0);
1310 /* write to OpenBSC via MNCC socket */
1311 static int mncc_fd_write(struct lcr_fd *lfd, void *inst, int idx)
1313 struct lcr_gsm *lcr_gsm = (struct lcr_gsm *) inst;
1314 struct mncc_q_entry *qe, *qe2;
1318 qe = lcr_gsm->mncc_q_hd;
1320 lfd->when &= ~LCR_FD_WRITE;
1323 rc = write(lfd->fd, qe->data, qe->len);
1325 return mncc_fd_close(lcr_gsm, lfd);
1328 if (rc < (int)qe->len)
1330 /* dequeue the successfully sent message */
1331 qe2 = mncc_q_dequeue(lcr_gsm);
1338 /* read from OpenBSC via MNCC socket */
1339 static int mncc_fd_read(struct lcr_fd *lfd, void *inst, int idx)
1341 struct lcr_gsm *lcr_gsm = (struct lcr_gsm *) inst;
1343 static char buf[sizeof(struct gsm_mncc)+1024];
1344 struct gsm_mncc *mncc_prim = (struct gsm_mncc *) buf;
1345 struct gsm_mncc_hello *hello = (struct gsm_mncc_hello *) buf;
1347 memset(buf, 0, sizeof(buf));
1348 rc = recv(lfd->fd, buf, sizeof(buf), 0);
1350 return mncc_fd_close(lcr_gsm, lfd);
1354 /* TODO: size check? */
1355 switch (mncc_prim->msg_type) {
1356 case MNCC_SOCKET_HELLO:
1357 if (hello->version != MNCC_SOCK_VERSION) {
1358 PERROR("MNCC version different. BSC version is %u\n", hello->version);
1359 mncc_fd_close(lcr_gsm, lfd);
1362 if (hello->mncc_size != sizeof(struct gsm_mncc)) {
1363 PERROR("MNCC gsm_mncc size differs: %u %u\n",
1364 hello->mncc_size, sizeof(struct gsm_mncc));
1365 mncc_fd_close(lcr_gsm, lfd);
1368 if (hello->data_frame_size != sizeof(struct gsm_data_frame)) {
1369 PERROR("MNCC gsm_mncc size differs: %u %u\n",
1370 hello->data_frame_size, sizeof(struct gsm_data_frame));
1371 mncc_fd_close(lcr_gsm, lfd);
1375 #define CHECK_OFFSET(hello, field, lcr_gsm, lfd) \
1376 if (hello->field ##_offset != __builtin_offsetof(struct gsm_mncc, field)) { \
1377 PERROR("MNCC gsm_mncc offset of %s is %u %u\n", \
1378 #field, hello->field ##_offset, \
1379 __builtin_offsetof(struct gsm_mncc, field)); \
1380 mncc_fd_close(lcr_gsm, lfd); \
1384 CHECK_OFFSET(hello, called, lcr_gsm, lfd);
1385 CHECK_OFFSET(hello, signal, lcr_gsm, lfd);
1386 CHECK_OFFSET(hello, emergency, lcr_gsm, lfd);
1387 CHECK_OFFSET(hello, lchan_type, lcr_gsm, lfd);
1393 /* Hand the MNCC message into LCR */
1394 switch (lcr_gsm->type) {
1396 case LCR_GSM_TYPE_NETWORK:
1397 return message_bsc(lcr_gsm, mncc_prim->msg_type, mncc_prim);
1400 case LCR_GSM_TYPE_MS:
1401 return message_ms(lcr_gsm, mncc_prim->msg_type, mncc_prim);
1408 /* file descriptor callback if we can read or write form MNCC socket */
1409 static int mncc_fd_cb(struct lcr_fd *lfd, unsigned int what, void *inst, int idx)
1413 if (what & LCR_FD_READ)
1414 rc = mncc_fd_read(lfd, inst, idx);
1418 if (what & LCR_FD_WRITE)
1419 rc = mncc_fd_write(lfd, inst, idx);
1424 int mncc_socket_retry_cb(struct lcr_timer *timer, void *inst, int index)
1426 struct lcr_gsm *lcr_gsm = (struct lcr_gsm *) inst;
1429 lcr_gsm->mncc_lfd.fd = -1;
1431 fd = socket(PF_UNIX, SOCK_SEQPACKET, 0);
1433 PERROR("Cannot create SEQPACKET socket, giving up!\n");
1437 rc = connect(fd, (struct sockaddr *) &lcr_gsm->sun,
1438 sizeof(lcr_gsm->sun));
1440 PERROR("Could not connect to MNCC socket %s, "
1441 "retrying in %u seconds\n", lcr_gsm->sun.sun_path,
1442 SOCKET_RETRY_TIMER);
1444 schedule_timer(&lcr_gsm->socket_retry, SOCKET_RETRY_TIMER, 0);
1446 PDEBUG(DEBUG_GSM, "Connected to MNCC socket %s!\n", lcr_gsm->sun.sun_path);
1447 lcr_gsm->mncc_lfd.fd = fd;
1448 register_fd(&lcr_gsm->mncc_lfd, LCR_FD_READ, &mncc_fd_cb, lcr_gsm, 0);