1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** mISDN gsm (MS mode) **
10 \*****************************************************************************/
19 #include <arpa/inet.h>
21 #include <osmocom/core/select.h>
22 #include <osmocom/core/talloc.h>
23 #include <osmocom/core/gsmtap_util.h>
25 #include <osmocom/bb/common/osmocom_data.h>
26 #include <osmocom/bb/common/logging.h>
27 #include <osmocom/bb/common/l1l2_interface.h>
28 #include <osmocom/bb/mobile/app_mobile.h>
31 static const char *config_file = "/etc/osmocom/osmocom.cfg";
32 short vty_port = 4247;
34 struct llist_head ms_list;
35 struct log_target *stderr_target;
37 struct gsmtap_inst *gsmtap_inst;
39 static int dtmf_timeout(struct lcr_timer *timer, void *instance, int index);
44 Pgsm_ms::Pgsm_ms(int type, struct mISDNport *mISDNport, char *portname, struct port_settings *settings, int channel, int exclusive, int mode) : Pgsm(type, mISDNport, portname, settings, channel, exclusive, mode)
46 struct osmocom_ms *ms = NULL;
47 char *ms_name = mISDNport->ifport->gsm_ms_name;
49 p_m_g_instance = NULL;
51 llist_for_each_entry(ms, &ms_list, entity) {
52 if (!strcmp(ms->name, ms_name)) {
58 p_m_g_dtmf_state = DTMF_ST_IDLE;
61 memset(&p_m_g_dtmf_timer, 0, sizeof(p_m_g_dtmf_timer));
62 add_timer(&p_m_g_dtmf_timer, dtmf_timeout, this, 0);
64 PDEBUG(DEBUG_GSM, "Created new GSMMSPort(%s %s).\n", portname, ms_name);
72 PDEBUG(DEBUG_GSM, "Destroyed GSM MS process(%s).\n", p_name);
73 del_timer(&p_m_g_dtmf_timer);
77 * handles all indications
79 /* SETUP INDICATION */
80 void Pgsm_ms::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
83 class Endpoint *epoint;
84 struct lcr_msg *message;
86 struct gsm_mncc *mode, *proceeding, *frame;
88 /* process given callref */
89 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
90 add_trace("callref", "new", "0x%x", callref);
92 /* release in case the ID is already in use */
93 add_trace("error", NULL, "callref already in use");
95 mncc = create_mncc(MNCC_REJ_REQ, callref);
96 gsm_trace_header(p_m_mISDNport, this, MNCC_REJ_REQ, DIRECTION_OUT);
97 mncc->fields |= MNCC_F_CAUSE;
98 mncc->cause.coding = 3;
99 mncc->cause.location = 1;
100 mncc->cause.value = 47;
101 add_trace("cause", "coding", "%d", mncc->cause.coding);
102 add_trace("cause", "location", "%d", mncc->cause.location);
103 add_trace("cause", "value", "%d", mncc->cause.value);
104 add_trace("reason", NULL, "callref already in use");
106 send_and_free_mncc(p_m_g_instance, mncc->msg_type, mncc);
107 new_state(PORT_STATE_RELEASE);
108 trigger_work(&p_m_g_delete);
111 p_m_g_callref = callref;
114 /* if blocked, release call with MT_RELEASE_COMPLETE */
115 if (p_m_mISDNport->ifport->block) {
116 mncc = create_mncc(MNCC_REJ_REQ, p_m_g_callref);
117 gsm_trace_header(p_m_mISDNport, this, MNCC_REJ_REQ, DIRECTION_OUT);
118 mncc->fields |= MNCC_F_CAUSE;
119 mncc->cause.coding = 3;
120 mncc->cause.location = 1;
121 mncc->cause.value = 27;
122 add_trace("cause", "coding", "%d", mncc->cause.coding);
123 add_trace("cause", "location", "%d", mncc->cause.location);
124 add_trace("cause", "value", "%d", mncc->cause.value);
125 add_trace("reason", NULL, "port is blocked");
127 send_and_free_mncc(p_m_g_instance, mncc->msg_type, mncc);
128 new_state(PORT_STATE_RELEASE);
129 trigger_work(&p_m_g_delete);
133 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_IND, DIRECTION_IN);
134 /* caller information */
135 p_callerinfo.ntype = INFO_NTYPE_NOTPRESENT;
136 if (mncc->fields & MNCC_F_CALLING) {
137 switch (mncc->calling.present) {
139 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
142 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
145 p_callerinfo.present = INFO_PRESENT_ALLOWED;
148 switch (mncc->calling.screen) {
150 p_callerinfo.screen = INFO_SCREEN_USER;
153 p_callerinfo.screen = INFO_SCREEN_USER_VERIFIED_PASSED;
156 p_callerinfo.screen = INFO_SCREEN_USER_VERIFIED_FAILED;
159 p_callerinfo.screen = INFO_SCREEN_NETWORK;
162 switch (mncc->calling.type) {
164 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
167 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
170 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
173 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
176 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
179 SCPY(p_callerinfo.id, mncc->calling.number);
180 add_trace("calling", "type", "%d", mncc->calling.type);
181 add_trace("calling", "plan", "%d", mncc->calling.plan);
182 add_trace("calling", "present", "%d", mncc->calling.present);
183 add_trace("calling", "screen", "%d", mncc->calling.screen);
184 add_trace("calling", "number", "%s", mncc->calling.number);
186 p_callerinfo.isdn_port = p_m_portnum;
187 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
188 /* dialing information */
189 if (mncc->fields & MNCC_F_CALLED) {
190 SCAT(p_dialinginfo.id, mncc->called.number);
191 switch (mncc->called.type) {
193 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
196 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
199 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
202 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
205 add_trace("dialing", "type", "%d", mncc->called.type);
206 add_trace("dialing", "plan", "%d", mncc->called.plan);
207 add_trace("dialing", "number", "%s", mncc->called.number);
209 p_dialinginfo.sending_complete = 1;
211 p_redirinfo.ntype = INFO_NTYPE_NOTPRESENT;
212 if (mncc->fields & MNCC_F_REDIRECTING) {
213 switch (mncc->redirecting.present) {
215 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
218 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
221 p_redirinfo.present = INFO_PRESENT_ALLOWED;
224 switch (mncc->redirecting.screen) {
226 p_redirinfo.screen = INFO_SCREEN_USER;
229 p_redirinfo.screen = INFO_SCREEN_USER_VERIFIED_PASSED;
232 p_redirinfo.screen = INFO_SCREEN_USER_VERIFIED_FAILED;
235 p_redirinfo.screen = INFO_SCREEN_NETWORK;
238 switch (mncc->redirecting.type) {
240 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
243 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
246 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
249 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
252 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
255 SCPY(p_redirinfo.id, mncc->redirecting.number);
256 add_trace("redir", "type", "%d", mncc->redirecting.type);
257 add_trace("redir", "plan", "%d", mncc->redirecting.plan);
258 add_trace("redir", "present", "%d", mncc->redirecting.present);
259 add_trace("redir", "screen", "%d", mncc->redirecting.screen);
260 add_trace("redir", "number", "%s", mncc->redirecting.number);
261 p_redirinfo.isdn_port = p_m_portnum;
263 /* bearer capability */
264 if (mncc->fields & MNCC_F_BEARER_CAP) {
265 switch (mncc->bearer_cap.transfer) {
267 p_capainfo.bearer_capa = INFO_BC_DATAUNRESTRICTED;
271 p_capainfo.bearer_capa = INFO_BC_AUDIO;
272 p_capainfo.bearer_info1 = (options.law=='a')?3:2;
275 p_capainfo.bearer_capa = INFO_BC_SPEECH;
276 p_capainfo.bearer_info1 = (options.law=='a')?3:2;
279 switch (mncc->bearer_cap.mode) {
281 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
284 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
287 add_trace("bearer", "transfer", "%d", mncc->bearer_cap.transfer);
288 add_trace("bearer", "mode", "%d", mncc->bearer_cap.mode);
290 p_capainfo.bearer_capa = INFO_BC_SPEECH;
291 p_capainfo.bearer_info1 = (options.law=='a')?3:2;
292 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
294 /* if packet mode works some day, see dss1.cpp for conditions */
295 p_capainfo.source_mode = B_MODE_TRANSPARENT;
300 ret = channel = hunt_bchannel();
305 ret = seize_bchannel(channel, 1);
308 mncc = create_mncc(MNCC_REJ_REQ, p_m_g_callref);
309 gsm_trace_header(p_m_mISDNport, this, MNCC_REJ_REQ, DIRECTION_OUT);
310 mncc->fields |= MNCC_F_CAUSE;
311 mncc->cause.coding = 3;
312 mncc->cause.location = 1;
313 mncc->cause.value = 34;
314 add_trace("cause", "coding", "%d", mncc->cause.coding);
315 add_trace("cause", "location", "%d", mncc->cause.location);
316 add_trace("cause", "value", "%d", mncc->cause.value);
317 add_trace("reason", NULL, "no channel");
319 send_and_free_mncc(p_m_g_instance, mncc->msg_type, mncc);
320 new_state(PORT_STATE_RELEASE);
321 trigger_work(&p_m_g_delete);
324 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
325 if (bchannel_open(p_m_b_index))
328 /* create endpoint */
330 FATAL("Incoming call but already got an endpoint.\n");
331 if (!(epoint = new Endpoint(p_serial, 0)))
332 FATAL("No memory for Endpoint instance\n");
333 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 0))) //incoming
334 FATAL("No memory for Endpoint Application instance\n");
335 epointlist_new(epoint->ep_serial);
337 /* modify lchan to GSM codec V1 */
338 gsm_trace_header(p_m_mISDNport, this, MNCC_LCHAN_MODIFY, DIRECTION_OUT);
339 mode = create_mncc(MNCC_LCHAN_MODIFY, p_m_g_callref);
340 mode->lchan_mode = 0x01; /* GSM V1 */
341 add_trace("mode", NULL, "0x%02x", mode->lchan_mode);
343 send_and_free_mncc(p_m_g_instance, mode->msg_type, mode);
345 /* send call proceeding */
346 gsm_trace_header(p_m_mISDNport, this, MNCC_CALL_CONF_REQ, DIRECTION_OUT);
347 proceeding = create_mncc(MNCC_CALL_CONF_REQ, p_m_g_callref);
350 proceeding->fields |= MNCC_F_CCCAP;
351 proceeding->cccap.dtmf = 1;
353 send_and_free_mncc(p_m_g_instance, proceeding->msg_type, proceeding);
355 new_state(PORT_STATE_IN_PROCEEDING);
357 if (p_m_mISDNport->tones && !p_m_g_tch_connected) { /* only if ... */
358 gsm_trace_header(p_m_mISDNport, this, MNCC_FRAME_RECV, DIRECTION_OUT);
360 frame = create_mncc(MNCC_FRAME_RECV, p_m_g_callref);
361 send_and_free_mncc(p_m_g_instance, frame->msg_type, frame);
362 p_m_g_tch_connected = 1;
365 /* send setup message to endpoit */
366 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
367 message->param.setup.isdn_port = p_m_portnum;
368 message->param.setup.port_type = p_type;
369 // message->param.setup.dtmf = 0;
370 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
371 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
372 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
373 SCPY((char *)message->param.setup.useruser.data, (char *)mncc->useruser.info);
374 message->param.setup.useruser.len = strlen(mncc->useruser.info);
375 message->param.setup.useruser.protocol = mncc->useruser.proto;
376 message_put(message);
380 * MS sends message to port
382 static int message_ms(struct osmocom_ms *ms, int msg_type, void *arg)
384 struct gsm_mncc *mncc = (struct gsm_mncc *)arg;
385 unsigned int callref = mncc->callref;
387 class Pgsm_ms *pgsm_ms = NULL;
389 struct mISDNport *mISDNport;
391 /* Special messages */
394 PDEBUG(DEBUG_GSM, "MS %s comes available\n", ms->name);
397 PDEBUG(DEBUG_GSM, "MS %s is removed\n", ms->name);
400 if ((port->p_type & PORT_CLASS_GSM_MASK) == PORT_CLASS_GSM_MS) {
401 pgsm_ms = (class Pgsm_ms *)port;
402 if (pgsm_ms->p_m_g_instance == ms) {
403 struct lcr_msg *message;
405 pgsm_ms->p_m_g_instance = 0;
406 message = message_create(pgsm_ms->p_serial, ACTIVE_EPOINT(pgsm_ms->p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
407 message->param.disconnectinfo.cause = 27;
408 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
409 message_put(message);
410 pgsm_ms->new_state(PORT_STATE_RELEASE);
411 trigger_work(&pgsm_ms->p_m_g_delete);
420 callref = mncc->callref;
423 if ((port->p_type & PORT_CLASS_GSM_MASK) == PORT_CLASS_GSM_MS) {
424 pgsm_ms = (class Pgsm_ms *)port;
425 if (pgsm_ms->p_m_g_callref == callref) {
432 if (msg_type == GSM_TCHF_FRAME) {
434 pgsm_ms->frame_receive(arg);
439 if (msg_type != MNCC_SETUP_IND)
441 /* find gsm ms port */
442 mISDNport = mISDNport_first;
444 if (mISDNport->gsm_ms && !strcmp(mISDNport->ifport->gsm_ms_name, ms->name))
446 mISDNport = mISDNport->next;
449 struct gsm_mncc *rej;
451 rej = create_mncc(MNCC_REJ_REQ, callref);
452 rej->fields |= MNCC_F_CAUSE;
453 rej->cause.coding = 3;
454 rej->cause.location = 1;
455 rej->cause.value = 27;
456 gsm_trace_header(NULL, NULL, MNCC_REJ_REQ, DIRECTION_OUT);
457 add_trace("cause", "coding", "%d", rej->cause.coding);
458 add_trace("cause", "location", "%d", rej->cause.location);
459 add_trace("cause", "value", "%d", rej->cause.value);
461 send_and_free_mncc(ms, rej->msg_type, rej);
464 /* creating port object, transparent until setup with hdlc */
465 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
466 if (!(pgsm_ms = new Pgsm_ms(PORT_TYPE_GSM_MS_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
468 FATAL("Cannot create Port instance.\n");
473 pgsm_ms->setup_ind(msg_type, callref, mncc);
476 case MNCC_CALL_PROC_IND:
477 pgsm_ms->call_proc_ind(msg_type, callref, mncc);
481 pgsm_ms->alert_ind(msg_type, callref, mncc);
485 pgsm_ms->setup_cnf(msg_type, callref, mncc);
488 case MNCC_SETUP_COMPL_IND:
489 pgsm_ms->setup_compl_ind(msg_type, callref, mncc);
493 pgsm_ms->disc_ind(msg_type, callref, mncc);
499 pgsm_ms->rel_ind(msg_type, callref, mncc);
502 case MNCC_NOTIFY_IND:
503 pgsm_ms->notify_ind(msg_type, callref, mncc);
506 case MNCC_START_DTMF_RSP:
507 case MNCC_START_DTMF_REJ:
508 case MNCC_STOP_DTMF_RSP:
509 pgsm_ms->dtmf_statemachine(mncc);
519 void Pgsm_ms::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
521 struct lcr_msg *message;
523 struct epoint_list *epointlist;
524 struct gsm_mncc *mncc;
527 /* copy setup infos to port */
528 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
529 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
530 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
531 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
534 if (!p_m_g_instance) {
535 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
536 add_trace("failure", NULL, "MS %s instance is unavailable", p_m_mISDNport->ifport->gsm_ms_name);
538 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
539 message->param.disconnectinfo.cause = 27;
540 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
541 message_put(message);
542 new_state(PORT_STATE_RELEASE);
543 trigger_work(&p_m_g_delete);
548 if (!p_dialinginfo.id[0]) {
549 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
550 add_trace("failure", NULL, "No dialed subscriber given.");
552 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
553 message->param.disconnectinfo.cause = 28;
554 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
555 message_put(message);
556 new_state(PORT_STATE_RELEASE);
557 trigger_work(&p_m_g_delete);
561 /* release if port is blocked */
562 if (p_m_mISDNport->ifport->block) {
563 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
564 add_trace("failure", NULL, "Port blocked.");
566 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
567 message->param.disconnectinfo.cause = 27; // temp. unavail.
568 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
569 message_put(message);
570 new_state(PORT_STATE_RELEASE);
571 trigger_work(&p_m_g_delete);
576 ret = channel = hunt_bchannel();
580 ret = seize_bchannel(channel, 1);
583 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
584 add_trace("failure", NULL, "No internal audio channel available.");
586 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
587 message->param.disconnectinfo.cause = 34;
588 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
589 message_put(message);
590 new_state(PORT_STATE_RELEASE);
591 trigger_work(&p_m_g_delete);
594 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
595 if (bchannel_open(p_m_b_index))
598 /* attach only if not already */
599 epointlist = p_epointlist;
601 if (epointlist->epoint_id == epoint_id)
603 epointlist = epointlist->next;
606 epointlist_new(epoint_id);
609 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_REQ, DIRECTION_OUT);
610 p_m_g_callref = new_callref++;
611 add_trace("callref", "new", "0x%x", p_m_g_callref);
614 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
615 mncc = create_mncc(MNCC_SETUP_REQ, p_m_g_callref);
616 if (!strncasecmp(p_dialinginfo.id, "emerg", 5)) {
619 /* caller info (only clir) */
620 switch (p_callerinfo.present) {
621 case INFO_PRESENT_ALLOWED:
627 /* dialing information (mandatory) */
628 mncc->fields |= MNCC_F_CALLED;
629 mncc->called.type = 0; /* unknown */
630 mncc->called.plan = 1; /* isdn */
631 SCPY(mncc->called.number, p_dialinginfo.id);
632 add_trace("dialing", "number", "%s", mncc->called.number);
634 /* bearer capability (mandatory) */
635 mncc->fields |= MNCC_F_BEARER_CAP;
636 mncc->bearer_cap.coding = 0;
637 mncc->bearer_cap.radio = 1;
638 mncc->bearer_cap.speech_ctm = 0;
639 mncc->bearer_cap.speech_ver[0] = 0;
640 mncc->bearer_cap.speech_ver[1] = -1; /* end of list */
641 switch (p_capainfo.bearer_capa) {
642 case INFO_BC_DATAUNRESTRICTED:
643 case INFO_BC_DATARESTRICTED:
644 mncc->bearer_cap.transfer = 1;
647 mncc->bearer_cap.transfer = 0;
650 mncc->bearer_cap.transfer = 2;
653 switch (p_capainfo.bearer_mode) {
654 case INFO_BMODE_PACKET:
655 mncc->bearer_cap.mode = 1;
658 mncc->bearer_cap.mode = 0;
662 mncc->fields |= MNCC_F_CCCAP;
663 mncc->cccap.dtmf = 1;
665 /* request keypad from remote */
666 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ENABLEKEYPAD);
667 message_put(message);
671 send_and_free_mncc(p_m_g_instance, mncc->msg_type, mncc);
673 new_state(PORT_STATE_OUT_SETUP);
675 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
676 message_put(message);
678 new_state(PORT_STATE_OUT_PROCEEDING);
681 void Pgsm_ms::dtmf_statemachine(struct gsm_mncc *mncc)
683 struct gsm_mncc *dtmf;
685 switch (p_m_g_dtmf_state) {
689 if (!p_m_g_dtmf[p_m_g_dtmf_index]) {
690 PDEBUG(DEBUG_GSM, "done with DTMF\n");
691 p_m_g_dtmf_state = DTMF_ST_IDLE;
694 gsm_trace_header(p_m_mISDNport, this, MNCC_START_DTMF_REQ, DIRECTION_OUT);
695 dtmf = create_mncc(MNCC_START_DTMF_REQ, p_m_g_callref);
696 dtmf->keypad = p_m_g_dtmf[p_m_g_dtmf_index++];
697 p_m_g_dtmf_state = DTMF_ST_START;
698 PDEBUG(DEBUG_GSM, "start DTMF (keypad %c)\n",
701 send_and_free_mncc(p_m_g_instance, dtmf->msg_type, dtmf);
704 if (mncc->msg_type != MNCC_START_DTMF_RSP) {
705 PDEBUG(DEBUG_GSM, "DTMF was rejected\n");
708 schedule_timer(&p_m_g_dtmf_timer, 0, 70 * 1000);
709 p_m_g_dtmf_state = DTMF_ST_MARK;
710 PDEBUG(DEBUG_GSM, "DTMF is on\n");
713 gsm_trace_header(p_m_mISDNport, this, MNCC_STOP_DTMF_REQ, DIRECTION_OUT);
714 dtmf = create_mncc(MNCC_STOP_DTMF_REQ, p_m_g_callref);
715 p_m_g_dtmf_state = DTMF_ST_STOP;
717 send_and_free_mncc(p_m_g_instance, dtmf->msg_type, dtmf);
720 schedule_timer(&p_m_g_dtmf_timer, 0, 120 * 1000);
721 p_m_g_dtmf_state = DTMF_ST_SPACE;
722 PDEBUG(DEBUG_GSM, "DTMF is off\n");
727 static int dtmf_timeout(struct lcr_timer *timer, void *instance, int index)
729 class Pgsm_ms *pgsm_ms = (class Pgsm_ms *)instance;
731 PDEBUG(DEBUG_GSM, "DTMF timer has fired\n");
732 pgsm_ms->dtmf_statemachine(NULL);
738 void Pgsm_ms::message_dtmf(unsigned int epoint_id, int message_id, union parameter *param)
740 char digit = param->dtmf;
742 if (digit >= 'a' && digit <= 'c')
743 digit = digit - 'a' + 'A';
744 if (!strchr("01234567890*#ABC", digit))
748 if (p_m_g_dtmf_state == DTMF_ST_IDLE) {
749 p_m_g_dtmf_index = 0;
750 p_m_g_dtmf[0] = '\0';
752 SCCAT(p_m_g_dtmf, digit);
753 if (p_m_g_dtmf_state == DTMF_ST_IDLE)
754 dtmf_statemachine(NULL);
757 /* MESSAGE_INFORMATION */
758 void Pgsm_ms::message_information(unsigned int epoint_id, int message_id, union parameter *param)
763 for (i = 0; i < (int)strlen(param->information.id); i++) {
764 digit = param->information.id[i];
765 if (digit >= 'a' && digit <= 'c')
766 digit = digit - 'a' + 'A';
767 if (!strchr("01234567890*#ABC", digit))
771 if (p_m_g_dtmf_state == DTMF_ST_IDLE) {
772 p_m_g_dtmf_index = 0;
773 p_m_g_dtmf[0] = '\0';
775 SCCAT(p_m_g_dtmf, digit);
776 if (p_m_g_dtmf_state == DTMF_ST_IDLE)
777 dtmf_statemachine(NULL);
782 * endpoint sends messages to the port
784 int Pgsm_ms::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
786 struct lcr_msg *message;
788 if (message_id == MESSAGE_CONNECT) {
789 /* request keypad from remote */
790 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ENABLEKEYPAD);
791 message_put(message);
794 if (Pgsm::message_epoint(epoint_id, message_id, param))
798 case MESSAGE_SETUP: /* dial-out command received from epoint */
799 if (p_state!=PORT_STATE_IDLE)
801 message_setup(epoint_id, message_id, param);
805 message_dtmf(epoint_id, message_id, param);
808 case MESSAGE_INFORMATION:
809 message_information(epoint_id, message_id, param);
813 PDEBUG(DEBUG_GSM, "Pgsm_ms(%s) gsm port with (caller id %s) received unhandled nessage: %d\n", p_name, p_callerinfo.id, message_id);
819 int gsm_ms_exit(int rc)
826 int gsm_ms_init(void)
828 INIT_LLIST_HEAD(&ms_list);
830 stderr_target = log_target_create_stderr();
831 log_add_target(stderr_target);
832 log_set_all_filter(stderr_target, 1);
834 l23_ctx = talloc_named_const(NULL, 1, "layer2 context");
836 log_parse_category_mask(stderr_target, "DCS:DPLMN:DRR:DMM:DSIM:DCC:DMNCC:DPAG:DSUM");
837 log_set_log_level(stderr_target, LOGL_INFO);
841 rc = gsmtap_init(gsmtap_ip);
843 fprintf(stderr, "Failed during gsmtap_init()\n");
849 l23_app_init(message_ms, config_file, vty_port);
854 /* add a new GSM mobile instance */
855 int gsm_ms_new(const char *name)
857 PDEBUG(DEBUG_GSM, "GSM: interface for MS '%s' is up\n", name);
862 int gsm_ms_delete(const char *name)
864 struct osmocom_ms *ms;
867 class Pgsm_ms *pgsm_ms = NULL;
869 PDEBUG(DEBUG_GSM, "GSM: interface for MS '%s' is down\n", name);
871 llist_for_each_entry(ms, &ms_list, entity) {
872 if (!strcmp(ms->name, name)) {
883 if ((port->p_type & PORT_CLASS_GSM_MASK) == PORT_CLASS_GSM_MS) {
884 pgsm_ms = (class Pgsm_ms *)port;
885 if (pgsm_ms->p_m_g_instance == ms && pgsm_ms->p_m_g_callref) {
886 struct gsm_mncc *rej;
888 rej = create_mncc(MNCC_REL_REQ, pgsm_ms->p_m_g_callref);
889 rej->fields |= MNCC_F_CAUSE;
890 rej->cause.coding = 3;
891 rej->cause.location = 1;
892 rej->cause.value = 27;
893 gsm_trace_header(NULL, NULL, MNCC_REJ_REQ, DIRECTION_OUT);
894 add_trace("cause", "coding", "%d", rej->cause.coding);
895 add_trace("cause", "location", "%d", rej->cause.location);
896 add_trace("cause", "value", "%d", rej->cause.value);
906 * handles bsc select function within LCR's main loop
908 int handle_gsm_ms(int *_quit)
910 int work = 0, quit = 0;
912 if (l23_app_work(&quit))
914 if (quit && llist_empty(&ms_list))
916 // debug_reset_context();
917 if (osmo_select_main(1)) /* polling */