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];
289 switch (frame->msg_type) {
291 if (p_g_media_type != MEDIA_TYPE_GSM) {
292 PERROR("FR frame, but current media type mismatches.\n");
295 if (!p_g_fr_decoder) {
296 PERROR("FR frame, but decoder not created.\n");
299 if ((frame->data[0]>>4) != 0xd) {
300 PDEBUG(DEBUG_GSM, "received GSM frame with wrong magig 0x%x\n", frame->data[0]>>4);
305 gsm_fr_decode(p_g_fr_decoder, frame->data, p_g_samples);
306 for (i = 0; i < 160; i++) {
307 data[i] = audio_s16_to_law[p_g_samples[i] & 0xffff];
312 if (p_g_media_type != MEDIA_TYPE_GSM_HR) {
313 PERROR("HR frame, but current media type mismatches.\n");
316 if (!p_g_hr_decoder) {
317 PERROR("HR frame, but decoder not created.\n");
320 if ((frame->data[0]>>4) != 0x0)
324 if (gsm_hr_decode(p_g_hr_decoder, frame->data, p_g_samples))
326 for (i = 0; i < 160; i++) {
327 data[i] = audio_s16_to_law[p_g_samples[i] & 0xffff];
331 case GSM_TCHF_FRAME_EFR:
332 if (p_g_media_type != MEDIA_TYPE_GSM_EFR) {
333 PERROR("EFR frame, but current media type mismatches.\n");
336 if (!p_g_amr_decoder) {
337 PERROR("EFR frame, but decoder not created.\n");
340 if ((frame->data[0]>>4) != 0xc)
344 gsm_efr_decode(p_g_amr_decoder, frame->data, p_g_samples);
345 for (i = 0; i < 160; i++) {
346 data[i] = audio_s16_to_law[p_g_samples[i] & 0xffff];
350 case GSM_TCH_FRAME_AMR:
351 if (p_g_media_type != MEDIA_TYPE_AMR) {
352 PERROR("AMR frame, but current media type mismatches.\n");
355 if (!p_g_amr_decoder) {
356 PERROR("AMR frame, but decoder not created.\n");
359 cmr = (frame->data[1] >> 4);
362 p_g_amr_cmr_valid = 1;
364 if (!(frame->data[2] & 0x04))
367 /* decode (skip length byte in front) */
368 gsm_amr_decode(p_g_amr_decoder, frame->data + 1, p_g_samples);
369 for (i = 0; i < 160; i++) {
370 data[i] = audio_s16_to_law[p_g_samples[i] & 0xffff];
378 /* beep on bad frame */
379 for (i = 0; i < 160; i++) {
381 p_g_samples[i] = 15000;
383 p_g_samples[i] = -15000;
384 data[i] = audio_s16_to_law[p_g_samples[i] & 0xffff];
387 /* repeat on bad frame */
388 for (i = 0; i < 160; i++) {
389 p_g_samples[i] = (p_g_samples[i] * 14) >> 4;
390 data[i] = audio_s16_to_law[p_g_samples[i] & 0xffff];
397 record(data, 160, 0); // from down
399 tap(data, 160, 0); // from down
403 bridge_rx(data, 160);
406 bridge_tx(data, 160);
409 /* send traffic to gsm */
410 int Pgsm::bridge_rx(unsigned char *data, int len)
414 if ((ret = Port::bridge_rx(data, len)))
420 return audio_send(data, len);
423 int Pgsm::audio_send(unsigned char *data, int len)
425 unsigned char frame[33];
430 record(data, len, 1); // from up
432 tap(data, len, 1); // from up
434 /* (currently) not connected, so don't flood tch! */
435 if (!p_g_tch_connected)
438 /* write to rx buffer */
440 p_g_rxdata[p_g_rxpos++] = audio_law_to_s32[*data++];
441 if (p_g_rxpos != 160)
445 switch (p_g_media_type) {
447 if (!p_g_fr_encoder) {
448 PERROR("FR frame, but encoder not created.\n");
453 gsm_fr_encode(p_g_fr_encoder, p_g_rxdata, frame);
454 frame_send(frame, 33, GSM_TCHF_FRAME);
457 case MEDIA_TYPE_GSM_HR:
458 if (!p_g_hr_encoder) {
459 PERROR("HR frame, but encoder not created.\n");
464 gsm_hr_encode(p_g_hr_encoder, p_g_rxdata, frame);
465 frame_send(frame, 15, GSM_TCHH_FRAME);
468 case MEDIA_TYPE_GSM_EFR:
469 if (!p_g_amr_encoder) {
470 PERROR("EFR frame, but encoder not created.\n");
475 gsm_efr_encode(p_g_amr_encoder, p_g_rxdata, frame);
476 frame_send(frame, 31, GSM_TCHF_FRAME_EFR);
480 if (!p_g_amr_encoder) {
481 PERROR("AMR frame, but encoder not created.\n");
484 if (!p_g_amr_cmr_valid) {
485 PDEBUG(DEBUG_GSM, "no valid CMR yet.\n");
489 /* encode data (prefix a length byte) */
490 ret = gsm_amr_encode(p_g_amr_encoder, p_g_rxdata, frame + 1, p_g_amr_cmr);
492 frame_send(frame, ret + 1, GSM_TCH_FRAME_AMR);
501 void Pgsm::frame_send(void *_frame, int len, int msg_type)
503 unsigned char buffer[sizeof(struct gsm_data_frame) + len];
504 struct gsm_data_frame *frame = (struct gsm_data_frame *)buffer;
506 frame->msg_type = msg_type;
507 frame->callref = p_g_callref;
508 memcpy(frame->data, _frame, len);
511 mncc_send(p_g_lcr_gsm, frame->msg_type, frame);
518 void gsm_trace_header(const char *interface_name, class Pgsm *port, unsigned int msg_type, int direction)
521 struct interface *interface = interface_first;
523 interface = getinterfacebyname(interface_name);
527 /* select message and primitive text */
528 SCPY(msgtext, mncc_name(msg_type));
532 switch(port->p_type) {
533 case PORT_TYPE_GSM_BS_OUT:
534 case PORT_TYPE_GSM_BS_IN:
535 SCAT(msgtext, " LCR<->BSC");
537 case PORT_TYPE_GSM_MS_OUT:
538 case PORT_TYPE_GSM_MS_IN:
539 SCAT(msgtext, " LCR<->MS");
543 SCAT(msgtext, " ----");
545 /* init trace with given values */
548 port?numberrize_callerinfo(port->p_callerinfo.id, port->p_callerinfo.ntype, options.national, options.international):NULL,
549 port?port->p_dialinginfo.id:NULL,
552 port?port->p_serial:0,
556 /* modify lchan to given payload type */
557 void Pgsm::modify_lchan(int media_type)
559 struct gsm_mncc *mode;
561 /* already modified to that media type */
562 if (p_g_media_type == media_type)
565 p_g_media_type = media_type;
566 gsm_trace_header(p_interface_name, this, MNCC_LCHAN_MODIFY, DIRECTION_OUT);
567 mode = create_mncc(MNCC_LCHAN_MODIFY, p_g_callref);
568 switch (media_type) {
569 case MEDIA_TYPE_GSM_EFR:
570 add_trace("speech", "version", "EFR given");
571 mode->lchan_mode = 0x21; /* GSM V2 */
572 mode->lchan_type = 0x02; /* TCH/F */
575 add_trace("speech", "version", "AMR given");
576 mode->lchan_mode = 0x41; /* GSM V3 */
577 /* as we don't know the available channels, this type will be set by openbsc automatically */
578 mode->lchan_type = 0x02; /* TCH/F */
580 case MEDIA_TYPE_GSM_HR:
581 add_trace("speech", "version", "Half Rate given");
582 mode->lchan_mode = 0x01; /* GSM V1 */
583 mode->lchan_type = 0x03; /* TCH/H */
586 add_trace("speech", "version", "Full Rate given");
587 mode->lchan_mode = 0x01; /* GSM V1 */
588 mode->lchan_type = 0x02; /* TCH/F */
590 add_trace("mode", NULL, "0x%02x", mode->lchan_mode);
592 send_and_free_mncc(p_g_lcr_gsm, mode->msg_type, mode);
595 /* CALL PROCEEDING INDICATION (from network) */
596 void Pgsm::call_proc_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
598 struct lcr_msg *message;
599 struct gsm_mncc *frame;
601 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
604 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
605 message_put(message);
607 new_state(PORT_STATE_OUT_PROCEEDING);
609 if (p_g_earlyb && !p_g_tch_connected) { /* only if ... */
610 gsm_trace_header(p_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
612 frame = create_mncc(MNCC_FRAME_RECV, p_g_callref);
613 send_and_free_mncc(p_g_lcr_gsm, frame->msg_type, frame);
614 p_g_tch_connected = 1;
617 /* modify to GSM FR (this is GSM user side only, so there is FR supported only) */
618 modify_lchan(MEDIA_TYPE_GSM);
621 /* ALERTING INDICATION */
622 void Pgsm::alert_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
624 struct lcr_msg *message;
625 struct gsm_mncc *frame;
627 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
630 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ALERTING);
631 message_put(message);
633 new_state(PORT_STATE_OUT_ALERTING);
635 if (p_g_earlyb && !p_g_tch_connected) { /* only if ... */
636 gsm_trace_header(p_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
638 frame = create_mncc(MNCC_FRAME_RECV, p_g_callref);
639 send_and_free_mncc(p_g_lcr_gsm, frame->msg_type, frame);
640 p_g_tch_connected = 1;
643 /* modify to GSM FR, if not already */
644 if (!p_g_media_type) {
645 modify_lchan(MEDIA_TYPE_GSM);
649 /* CONNECT INDICATION */
650 void Pgsm::setup_cnf(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
652 struct gsm_mncc *resp, *frame;
653 struct lcr_msg *message;
655 SCPY(p_connectinfo.id, mncc->connected.number);
656 SCPY(p_connectinfo.imsi, mncc->imsi);
657 p_connectinfo.present = INFO_PRESENT_ALLOWED;
658 p_connectinfo.screen = INFO_SCREEN_NETWORK;
659 p_connectinfo.ntype = INFO_NTYPE_UNKNOWN;
660 SCPY(p_connectinfo.interface, p_interface_name);
662 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
663 if (p_connectinfo.id[0])
664 add_trace("connect", "number", "%s", p_connectinfo.id);
665 else if (mncc->imsi[0])
666 SPRINT(p_connectinfo.id, "imsi-%s", p_connectinfo.imsi);
668 add_trace("connect", "imsi", "%s", p_connectinfo.imsi);
672 gsm_trace_header(p_interface_name, this, MNCC_SETUP_COMPL_REQ, DIRECTION_OUT);
673 resp = create_mncc(MNCC_SETUP_COMPL_REQ, p_g_callref);
675 send_and_free_mncc(p_g_lcr_gsm, resp->msg_type, resp);
677 new_state(PORT_STATE_CONNECT);
679 if (!p_g_tch_connected) { /* only if ... */
680 gsm_trace_header(p_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
682 frame = create_mncc(MNCC_FRAME_RECV, p_g_callref);
683 send_and_free_mncc(p_g_lcr_gsm, frame->msg_type, frame);
684 p_g_tch_connected = 1;
687 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_CONNECT);
688 memcpy(&message->param.connectinfo, &p_connectinfo, sizeof(struct connect_info));
690 /* if we have a bridge, but not yet modified, the phone accepts out requested payload.
691 * we force the first in list */
692 if (p_g_rtp_bridge) {
693 if (!p_g_media_type) {
694 /* modify to first given type */
695 modify_lchan(p_g_rtp_media_types[0]);
696 /* also set payload type */
697 p_g_payload_type = p_g_rtp_payload_types[0];
699 message->param.connectinfo.rtpinfo.media_types[0] = p_g_media_type;
700 message->param.connectinfo.rtpinfo.payload_types[0] = p_g_payload_type;
701 message->param.connectinfo.rtpinfo.payloads = 1;
703 /* modify to GSM FR, if not already
704 * for network side, this should have been already happened */
706 modify_lchan(MEDIA_TYPE_GSM);
710 if (p_g_rtp_bridge) {
711 struct gsm_mncc_rtp *rtp;
713 PDEBUG(DEBUG_GSM, "Request RTP peer info, before forwarding connect msg\n");
714 p_g_connect_pending = message;
715 rtp = (struct gsm_mncc_rtp *) create_mncc(MNCC_RTP_CREATE, p_g_callref);
716 send_and_free_mncc(p_g_lcr_gsm, rtp->msg_type, rtp);
718 message_put(message);
721 /* CONNECT ACK INDICATION */
722 void Pgsm::setup_compl_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
724 struct gsm_mncc *frame;
726 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
729 new_state(PORT_STATE_CONNECT);
731 if (!p_g_tch_connected) { /* only if ... */
732 gsm_trace_header(p_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
734 frame = create_mncc(MNCC_FRAME_RECV, p_g_callref);
735 send_and_free_mncc(p_g_lcr_gsm, frame->msg_type, frame);
736 p_g_tch_connected = 1;
739 /* modify to GSM FR, if not already */
740 if (!p_g_media_type) {
741 modify_lchan(MEDIA_TYPE_GSM);
745 /* DISCONNECT INDICATION */
746 void Pgsm::disc_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
748 struct lcr_msg *message;
749 int cause = 16, location = 0;
750 struct gsm_mncc *resp;
752 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
753 if (mncc->fields & MNCC_F_CAUSE) {
754 location = mncc->cause.location;
755 cause = mncc->cause.value;
756 add_trace("cause", "coding", "%d", mncc->cause.coding);
757 add_trace("cause", "location", "%d", location);
758 add_trace("cause", "value", "%d", cause);
763 resp = create_mncc(MNCC_REL_REQ, p_g_callref);
764 gsm_trace_header(p_interface_name, this, MNCC_REL_REQ, DIRECTION_OUT);
766 resp->fields |= MNCC_F_CAUSE;
767 resp->cause.coding = 3;
768 resp->cause.location = 1;
769 resp->cause.value = cause;
770 add_trace("cause", "coding", "%d", resp->cause.coding);
771 add_trace("cause", "location", "%d", resp->cause.location);
772 add_trace("cause", "value", "%d", resp->cause.value);
775 send_and_free_mncc(p_g_lcr_gsm, resp->msg_type, resp);
777 /* sending release to endpoint */
778 while(p_epointlist) {
779 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
780 message->param.disconnectinfo.cause = cause;
781 message->param.disconnectinfo.location = location;
782 message_put(message);
784 free_epointlist(p_epointlist);
786 new_state(PORT_STATE_RELEASE);
787 trigger_work(&p_g_delete);
790 /* CC_RELEASE INDICATION */
791 void Pgsm::rel_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
793 int location = 0, cause = 16;
794 struct lcr_msg *message;
796 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
797 if (mncc->fields & MNCC_F_CAUSE) {
798 location = mncc->cause.location;
799 cause = mncc->cause.value;
800 add_trace("cause", "coding", "%d", mncc->cause.coding);
801 add_trace("cause", "location", "%d", mncc->cause.location);
802 add_trace("cause", "value", "%d", mncc->cause.value);
806 /* sending release to endpoint */
807 while(p_epointlist) {
808 message = message_create(p_serial, p_epointlist->epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
809 message->param.disconnectinfo.cause = cause;
810 message->param.disconnectinfo.location = location;
811 message_put(message);
813 free_epointlist(p_epointlist);
815 new_state(PORT_STATE_RELEASE);
816 trigger_work(&p_g_delete);
819 /* NOTIFY INDICATION */
820 void Pgsm::notify_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
822 struct lcr_msg *message;
824 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
825 add_trace("notify", NULL, "%d", mncc->notify);
828 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
829 message->param.notifyinfo.notify = mncc->notify;
830 message_put(message);
834 void Pgsm::message_notify(unsigned int epoint_id, int message_id, union parameter *param)
836 struct gsm_mncc *mncc;
839 // printf("if = %d\n", param->notifyinfo.notify);
840 if (param->notifyinfo.notify>INFO_NOTIFY_NONE) {
841 notify = param->notifyinfo.notify & 0x7f;
842 /* skip all notifiy ids that are not 0, 1, 2 */
845 if (p_state!=PORT_STATE_CONNECT /*&& p_state!=PORT_STATE_IN_PROCEEDING*/ && p_state!=PORT_STATE_IN_ALERTING) {
846 /* queue notification */
847 if (p_g_notify_pending)
848 message_free(p_g_notify_pending);
849 p_g_notify_pending = message_create(ACTIVE_EPOINT(p_epointlist), p_serial, EPOINT_TO_PORT, message_id);
850 memcpy(&p_g_notify_pending->param, param, sizeof(union parameter));
852 /* sending notification */
853 gsm_trace_header(p_interface_name, this, MNCC_NOTIFY_REQ, DIRECTION_OUT);
854 add_trace("notify", NULL, "%d", notify);
856 mncc = create_mncc(MNCC_NOTIFY_REQ, p_g_callref);
857 mncc->notify = notify;
858 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
863 /* RTP create indication */
864 void Pgsm::rtp_create_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
866 struct gsm_mncc_rtp *rtp = (struct gsm_mncc_rtp *) mncc;
868 /* send queued setup, as we received remote RTP info */
869 if (p_g_setup_pending) {
870 struct lcr_msg *message;
872 message = p_g_setup_pending;
873 PDEBUG(DEBUG_GSM, "Got RTP peer info (%08x,%d) forwarding setup\n", rtp->ip, rtp->port);
874 message->param.setup.rtpinfo.ip = rtp->ip;
875 message->param.setup.rtpinfo.port = rtp->port;
876 message_put(message);
877 p_g_setup_pending = NULL;
879 if (p_g_connect_pending) {
880 PDEBUG(DEBUG_GSM, "Got RTP peer info (%08x,%d) connecting RTP... \n", rtp->ip, rtp->port);
881 send_mncc_rtp_connect();
885 /* RTP connect indication */
886 void Pgsm::rtp_connect_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
888 struct lcr_msg *message;
889 struct gsm_mncc_rtp *rtp = (struct gsm_mncc_rtp *) mncc;
891 if (p_g_connect_pending) {
892 message = p_g_connect_pending;
893 PDEBUG(DEBUG_GSM, "Got RTP peer info (%08x,%d) forwarding connect\n", rtp->ip, rtp->port);
894 message->param.connectinfo.rtpinfo.ip = rtp->ip;
895 message->param.connectinfo.rtpinfo.port = rtp->port;
896 message_put(message);
897 p_g_connect_pending = NULL;
901 /* MESSAGE_PROGRESS */
902 void Pgsm::message_progress(unsigned int epoint_id, int message_id, union parameter *param)
904 if (param->progressinfo.progress == 8) {
905 PDEBUG(DEBUG_GSM, "Remote provides tones for us\n");
909 if (param->progressinfo.rtpinfo.port) {
910 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]);
912 /* modify channel to givne type, also sets media type */
913 modify_lchan(param->progressinfo.rtpinfo.media_types[0]);
916 p_g_rtp_ip_remote = param->progressinfo.rtpinfo.ip;
917 p_g_rtp_port_remote = param->progressinfo.rtpinfo.port;
918 /* p_g_media_type is already set by modify_lchan() */
919 p_g_payload_type = param->progressinfo.rtpinfo.payload_types[0];
920 send_mncc_rtp_connect();
924 /* MESSAGE_ALERTING */
925 void Pgsm::message_alerting(unsigned int epoint_id, int message_id, union parameter *param)
927 struct gsm_mncc *mncc;
930 gsm_trace_header(p_interface_name, this, MNCC_ALERT_REQ, DIRECTION_OUT);
931 mncc = create_mncc(MNCC_ALERT_REQ, p_g_callref);
933 mncc->fields |= MNCC_F_PROGRESS;
934 mncc->progress.coding = 3; /* GSM */
935 mncc->progress.location = 1;
936 mncc->progress.descr = 8;
937 add_trace("progress", "coding", "%d", mncc->progress.coding);
938 add_trace("progress", "location", "%d", mncc->progress.location);
939 add_trace("progress", "descr", "%d", mncc->progress.descr);
942 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
944 new_state(PORT_STATE_IN_ALERTING);
946 if (p_g_tones && !p_g_tch_connected) { /* only if ... */
947 gsm_trace_header(p_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
949 mncc = create_mncc(MNCC_FRAME_RECV, p_g_callref);
950 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
951 p_g_tch_connected = 1;
954 /* modify to GSM FR, if not already */
955 if (!p_g_media_type) {
956 modify_lchan(MEDIA_TYPE_GSM);
960 /* MESSAGE_CONNECT */
961 void Pgsm::message_connect(unsigned int epoint_id, int message_id, union parameter *param)
963 struct gsm_mncc *mncc;
965 /* copy connected information */
966 memcpy(&p_connectinfo, ¶m->connectinfo, sizeof(p_connectinfo));
967 /* screen outgoing caller id */
968 do_screen(1, p_connectinfo.id, sizeof(p_connectinfo.id), &p_connectinfo.ntype, &p_connectinfo.present, p_interface_name);
971 mncc = create_mncc(MNCC_SETUP_RSP, p_g_callref);
972 gsm_trace_header(p_interface_name, this, MNCC_SETUP_RSP, DIRECTION_OUT);
973 /* caller information */
974 mncc->fields |= MNCC_F_CONNECTED;
975 mncc->connected.plan = 1;
976 switch (p_callerinfo.ntype) {
977 case INFO_NTYPE_UNKNOWN:
978 mncc->connected.type = 0x0;
980 case INFO_NTYPE_INTERNATIONAL:
981 mncc->connected.type = 0x1;
983 case INFO_NTYPE_NATIONAL:
984 mncc->connected.type = 0x2;
986 case INFO_NTYPE_SUBSCRIBER:
987 mncc->connected.type = 0x4;
989 default: /* INFO_NTYPE_NOTPRESENT */
990 mncc->fields &= ~MNCC_F_CONNECTED;
993 switch (p_callerinfo.screen) {
994 case INFO_SCREEN_USER:
995 mncc->connected.screen = 0;
997 default: /* INFO_SCREEN_NETWORK */
998 mncc->connected.screen = 3;
1001 switch (p_callerinfo.present) {
1002 case INFO_PRESENT_ALLOWED:
1003 mncc->connected.present = 0;
1005 case INFO_PRESENT_RESTRICTED:
1006 mncc->connected.present = 1;
1008 default: /* INFO_PRESENT_NOTAVAIL */
1009 mncc->connected.present = 2;
1012 if (mncc->fields & MNCC_F_CONNECTED) {
1013 SCPY(mncc->connected.number, p_connectinfo.id);
1014 add_trace("connected", "type", "%d", mncc->connected.type);
1015 add_trace("connected", "plan", "%d", mncc->connected.plan);
1016 add_trace("connected", "present", "%d", mncc->connected.present);
1017 add_trace("connected", "screen", "%d", mncc->connected.screen);
1018 add_trace("connected", "number", "%s", mncc->connected.number);
1021 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
1023 new_state(PORT_STATE_CONNECT_WAITING);
1025 if (param->connectinfo.rtpinfo.port) {
1026 PDEBUG(DEBUG_GSM, "CONNECT with RTP peer info, sent to BSC (%08x,%d)\n", param->connectinfo.rtpinfo.ip, param->connectinfo.rtpinfo.port);
1028 /* modify channel to givne type, also sets media type */
1029 modify_lchan(param->connectinfo.rtpinfo.media_types[0]);
1032 p_g_rtp_ip_remote = param->connectinfo.rtpinfo.ip;
1033 p_g_rtp_port_remote = param->connectinfo.rtpinfo.port;
1034 /* p_g_media_type is already set by modify_lchan() */
1035 p_g_payload_type = param->connectinfo.rtpinfo.payload_types[0];
1036 send_mncc_rtp_connect();
1040 /* MESSAGE_DISCONNECT */
1041 void Pgsm::message_disconnect(unsigned int epoint_id, int message_id, union parameter *param)
1043 struct gsm_mncc *mncc;
1045 /* send disconnect */
1046 mncc = create_mncc(MNCC_DISC_REQ, p_g_callref);
1047 gsm_trace_header(p_interface_name, this, MNCC_DISC_REQ, DIRECTION_OUT);
1049 mncc->fields |= MNCC_F_PROGRESS;
1050 mncc->progress.coding = 3; /* GSM */
1051 mncc->progress.location = 1;
1052 mncc->progress.descr = 8;
1053 add_trace("progress", "coding", "%d", mncc->progress.coding);
1054 add_trace("progress", "location", "%d", mncc->progress.location);
1055 add_trace("progress", "descr", "%d", mncc->progress.descr);
1057 mncc->fields |= MNCC_F_CAUSE;
1058 mncc->cause.coding = 3;
1059 mncc->cause.location = param->disconnectinfo.location;
1060 mncc->cause.value = param->disconnectinfo.cause;
1061 add_trace("cause", "coding", "%d", mncc->cause.coding);
1062 add_trace("cause", "location", "%d", mncc->cause.location);
1063 add_trace("cause", "value", "%d", mncc->cause.value);
1065 /* special case for BS mode */
1066 if (param->disconnectinfo.transfer.result && (p_type & PORT_CLASS_GSM_MASK) == PORT_CLASS_GSM_BS) {
1067 ((class Pgsm_bs *)this)->enc_ie_facility_ect(mncc, ¶m->disconnectinfo.transfer);
1068 gsm_trace_facility((unsigned char *)mncc->facility.info, mncc->facility.len);
1072 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
1074 new_state(PORT_STATE_OUT_DISCONNECT);
1076 if (p_g_tones && !p_g_tch_connected) { /* only if ... */
1077 gsm_trace_header(p_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
1079 mncc = create_mncc(MNCC_FRAME_RECV, p_g_callref);
1080 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
1081 p_g_tch_connected = 1;
1086 /* MESSAGE_RELEASE */
1087 void Pgsm::message_release(unsigned int epoint_id, int message_id, union parameter *param)
1089 struct gsm_mncc *mncc;
1092 mncc = create_mncc(MNCC_REL_REQ, p_g_callref);
1093 gsm_trace_header(p_interface_name, this, MNCC_REL_REQ, DIRECTION_OUT);
1094 mncc->fields |= MNCC_F_CAUSE;
1095 mncc->cause.coding = 3;
1096 mncc->cause.location = param->disconnectinfo.location;
1097 mncc->cause.value = param->disconnectinfo.cause;
1098 add_trace("cause", "coding", "%d", mncc->cause.coding);
1099 add_trace("cause", "location", "%d", mncc->cause.location);
1100 add_trace("cause", "value", "%d", mncc->cause.value);
1102 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
1104 new_state(PORT_STATE_RELEASE);
1105 trigger_work(&p_g_delete);
1110 * endpoint sends messages to the port
1112 int Pgsm::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
1116 if (Port::message_epoint(epoint_id, message_id, param))
1119 switch(message_id) {
1120 case MESSAGE_NOTIFY: /* display and notifications */
1122 message_notify(epoint_id, message_id, param);
1125 // case MESSAGE_FACILITY: /* facility message */
1126 // message_facility(epoint_id, message_id, param);
1129 case MESSAGE_PROCEEDING: /* message not handles */
1133 case MESSAGE_PROGRESS:
1135 message_progress(epoint_id, message_id, param);
1138 case MESSAGE_ALERTING: /* call of endpoint is ringing */
1140 if (p_state!=PORT_STATE_IN_PROCEEDING)
1142 message_alerting(epoint_id, message_id, param);
1143 if (p_g_notify_pending) {
1144 /* send pending notify message during connect */
1145 message_notify(ACTIVE_EPOINT(p_epointlist), p_g_notify_pending->type, &p_g_notify_pending->param);
1146 message_free(p_g_notify_pending);
1147 p_g_notify_pending = NULL;
1151 case MESSAGE_CONNECT: /* call of endpoint is connected */
1153 if (p_state!=PORT_STATE_IN_PROCEEDING
1154 && p_state!=PORT_STATE_IN_ALERTING)
1156 message_connect(epoint_id, message_id, param);
1157 if (p_g_notify_pending) {
1158 /* send pending notify message during connect */
1159 message_notify(ACTIVE_EPOINT(p_epointlist), p_g_notify_pending->type, &p_g_notify_pending->param);
1160 message_free(p_g_notify_pending);
1161 p_g_notify_pending = NULL;
1165 case MESSAGE_DISCONNECT: /* call has been disconnected */
1167 if (p_state!=PORT_STATE_IN_PROCEEDING
1168 && p_state!=PORT_STATE_IN_ALERTING
1169 && p_state!=PORT_STATE_OUT_SETUP
1170 && p_state!=PORT_STATE_OUT_OVERLAP
1171 && p_state!=PORT_STATE_OUT_PROCEEDING
1172 && p_state!=PORT_STATE_OUT_ALERTING
1173 && p_state!=PORT_STATE_CONNECT
1174 && p_state!=PORT_STATE_CONNECT_WAITING)
1176 message_disconnect(epoint_id, message_id, param);
1179 case MESSAGE_RELEASE: /* release isdn port */
1181 if (p_state==PORT_STATE_RELEASE)
1183 message_release(epoint_id, message_id, param);
1191 /* deletes only if l3id is release, otherwhise it will be triggered then */
1192 static int delete_event(struct lcr_work *work, void *instance, int index)
1194 class Pgsm *gsmport = (class Pgsm *)instance;
1201 int gsm_exit(int rc)
1218 static int mncc_q_enqueue(struct lcr_gsm *lcr_gsm, struct gsm_mncc *mncc, unsigned int len)
1220 struct mncc_q_entry *qe;
1222 qe = (struct mncc_q_entry *) MALLOC(sizeof(*qe)+sizeof(*mncc)+len);
1228 memcpy(qe->data, mncc, len);
1230 /* in case of empty list ... */
1231 if (!lcr_gsm->mncc_q_hd && !lcr_gsm->mncc_q_tail) {
1232 /* the list head and tail both point to the new qe */
1233 lcr_gsm->mncc_q_hd = lcr_gsm->mncc_q_tail = qe;
1235 /* append to tail of list */
1236 lcr_gsm->mncc_q_tail->next = qe;
1237 lcr_gsm->mncc_q_tail = qe;
1240 lcr_gsm->mncc_lfd.when |= LCR_FD_WRITE;
1245 static struct mncc_q_entry *mncc_q_dequeue(struct lcr_gsm *lcr_gsm)
1247 struct mncc_q_entry *qe = lcr_gsm->mncc_q_hd;
1251 /* dequeue the successfully sent message */
1252 lcr_gsm->mncc_q_hd = qe->next;
1255 if (qe == lcr_gsm->mncc_q_tail)
1256 lcr_gsm->mncc_q_tail = NULL;
1261 /* routine called by LCR code if it wants to send a message to OpenBSC */
1262 static int mncc_send(struct lcr_gsm *lcr_gsm, int msg_type, void *data)
1266 /* FIXME: the caller should provide this */
1268 case GSM_TCHF_FRAME:
1269 len = sizeof(struct gsm_data_frame) + 33;
1272 len = sizeof(struct gsm_mncc);
1276 return mncc_q_enqueue(lcr_gsm, (struct gsm_mncc *)data, len);
1279 /* close MNCC socket */
1280 static int mncc_fd_close(struct lcr_gsm *lcr_gsm, struct lcr_fd *lfd)
1283 class Pgsm *pgsm = NULL;
1284 struct lcr_msg *message;
1286 PERROR("Lost MNCC socket, retrying in %u seconds\n", SOCKET_RETRY_TIMER);
1291 /* free all the calls that were running through the MNCC interface */
1294 if ((port->p_type & PORT_CLASS_MASK) == PORT_CLASS_GSM) {
1295 pgsm = (class Pgsm *)port;
1296 if (pgsm->p_g_lcr_gsm == lcr_gsm) {
1297 message = message_create(pgsm->p_serial, ACTIVE_EPOINT(pgsm->p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
1298 message->param.disconnectinfo.cause = 27; // temp. unavail.
1299 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
1300 message_put(message);
1301 pgsm->new_state(PORT_STATE_RELEASE);
1302 trigger_work(&pgsm->p_g_delete);
1308 /* flush the queue */
1309 while (mncc_q_dequeue(lcr_gsm))
1312 /* start the re-connect timer */
1313 schedule_timer(&lcr_gsm->socket_retry, SOCKET_RETRY_TIMER, 0);
1318 /* write to OpenBSC via MNCC socket */
1319 static int mncc_fd_write(struct lcr_fd *lfd, void *inst, int idx)
1321 struct lcr_gsm *lcr_gsm = (struct lcr_gsm *) inst;
1322 struct mncc_q_entry *qe, *qe2;
1326 qe = lcr_gsm->mncc_q_hd;
1328 lfd->when &= ~LCR_FD_WRITE;
1331 rc = write(lfd->fd, qe->data, qe->len);
1333 return mncc_fd_close(lcr_gsm, lfd);
1336 if (rc < (int)qe->len)
1338 /* dequeue the successfully sent message */
1339 qe2 = mncc_q_dequeue(lcr_gsm);
1346 /* read from OpenBSC via MNCC socket */
1347 static int mncc_fd_read(struct lcr_fd *lfd, void *inst, int idx)
1349 struct lcr_gsm *lcr_gsm = (struct lcr_gsm *) inst;
1351 static char buf[sizeof(struct gsm_mncc)+1024];
1352 struct gsm_mncc *mncc_prim = (struct gsm_mncc *) buf;
1353 struct gsm_mncc_hello *hello = (struct gsm_mncc_hello *) buf;
1355 memset(buf, 0, sizeof(buf));
1356 rc = recv(lfd->fd, buf, sizeof(buf), 0);
1358 return mncc_fd_close(lcr_gsm, lfd);
1362 /* TODO: size check? */
1363 switch (mncc_prim->msg_type) {
1364 case MNCC_SOCKET_HELLO:
1365 if (hello->version != MNCC_SOCK_VERSION) {
1366 PERROR("MNCC version different. BSC version is %u\n", hello->version);
1367 mncc_fd_close(lcr_gsm, lfd);
1370 if (hello->mncc_size != sizeof(struct gsm_mncc)) {
1371 PERROR("MNCC gsm_mncc size differs: %u %u\n",
1372 hello->mncc_size, sizeof(struct gsm_mncc));
1373 mncc_fd_close(lcr_gsm, lfd);
1376 if (hello->data_frame_size != sizeof(struct gsm_data_frame)) {
1377 PERROR("MNCC gsm_mncc size differs: %u %u\n",
1378 hello->data_frame_size, sizeof(struct gsm_data_frame));
1379 mncc_fd_close(lcr_gsm, lfd);
1383 #define CHECK_OFFSET(hello, field, lcr_gsm, lfd) \
1384 if (hello->field ##_offset != __builtin_offsetof(struct gsm_mncc, field)) { \
1385 PERROR("MNCC gsm_mncc offset of %s is %u %u\n", \
1386 #field, hello->field ##_offset, \
1387 __builtin_offsetof(struct gsm_mncc, field)); \
1388 mncc_fd_close(lcr_gsm, lfd); \
1392 CHECK_OFFSET(hello, called, lcr_gsm, lfd);
1393 CHECK_OFFSET(hello, signal, lcr_gsm, lfd);
1394 CHECK_OFFSET(hello, emergency, lcr_gsm, lfd);
1395 CHECK_OFFSET(hello, lchan_type, lcr_gsm, lfd);
1401 /* Hand the MNCC message into LCR */
1402 switch (lcr_gsm->type) {
1404 case LCR_GSM_TYPE_NETWORK:
1405 return message_bsc(lcr_gsm, mncc_prim->msg_type, mncc_prim);
1408 case LCR_GSM_TYPE_MS:
1409 return message_ms(lcr_gsm, mncc_prim->msg_type, mncc_prim);
1416 /* file descriptor callback if we can read or write form MNCC socket */
1417 static int mncc_fd_cb(struct lcr_fd *lfd, unsigned int what, void *inst, int idx)
1421 if (what & LCR_FD_READ)
1422 rc = mncc_fd_read(lfd, inst, idx);
1426 if (what & LCR_FD_WRITE)
1427 rc = mncc_fd_write(lfd, inst, idx);
1432 int mncc_socket_retry_cb(struct lcr_timer *timer, void *inst, int index)
1434 struct lcr_gsm *lcr_gsm = (struct lcr_gsm *) inst;
1437 lcr_gsm->mncc_lfd.fd = -1;
1439 fd = socket(PF_UNIX, SOCK_SEQPACKET, 0);
1441 PERROR("Cannot create SEQPACKET socket, giving up!\n");
1445 rc = connect(fd, (struct sockaddr *) &lcr_gsm->sun,
1446 sizeof(lcr_gsm->sun));
1448 PERROR("Could not connect to MNCC socket %s, "
1449 "retrying in %u seconds\n", lcr_gsm->sun.sun_path,
1450 SOCKET_RETRY_TIMER);
1452 schedule_timer(&lcr_gsm->socket_retry, SOCKET_RETRY_TIMER, 0);
1454 PDEBUG(DEBUG_GSM, "Connected to MNCC socket %s!\n", lcr_gsm->sun.sun_path);
1455 lcr_gsm->mncc_lfd.fd = fd;
1456 register_fd(&lcr_gsm->mncc_lfd, LCR_FD_READ, &mncc_fd_cb, lcr_gsm, 0);