1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** mISDN gsm (MS mode) **
10 \*****************************************************************************/
19 #include <arpa/inet.h>
22 #include <osmocom/core/select.h>
23 #include <osmocom/core/talloc.h>
24 #include <osmocom/core/gsmtap_util.h>
26 #include <osmocom/bb/common/osmocom_data.h>
27 #include <osmocom/bb/common/logging.h>
28 #include <osmocom/bb/common/l1l2_interface.h>
29 #include <osmocom/bb/mobile/app_mobile.h>
32 //char *config_dir = NULL;
34 short vty_port = 4247;
36 struct llist_head ms_list;
37 struct log_target *stderr_target;
39 struct gsmtap_inst *gsmtap_inst;
41 static int dtmf_timeout(struct lcr_timer *timer, void *instance, int index);
46 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)
48 struct osmocom_ms *ms = NULL;
49 char *ms_name = mISDNport->ifport->gsm_ms_name;
51 p_m_g_instance = NULL;
53 llist_for_each_entry(ms, &ms_list, entity) {
54 if (!strcmp(ms->name, ms_name)) {
60 p_m_g_dtmf_state = DTMF_ST_IDLE;
63 memset(&p_m_g_dtmf_timer, 0, sizeof(p_m_g_dtmf_timer));
64 add_timer(&p_m_g_dtmf_timer, dtmf_timeout, this, 0);
66 PDEBUG(DEBUG_GSM, "Created new GSMMSPort(%s %s).\n", portname, ms_name);
74 PDEBUG(DEBUG_GSM, "Destroyed GSM MS process(%s).\n", p_name);
75 del_timer(&p_m_g_dtmf_timer);
79 * handles all indications
81 /* SETUP INDICATION */
82 void Pgsm_ms::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
85 class Endpoint *epoint;
86 struct lcr_msg *message;
88 struct gsm_mncc *mode, *proceeding, *frame;
90 /* process given callref */
91 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
92 add_trace("callref", "new", "0x%x", callref);
94 /* release in case the ID is already in use */
95 add_trace("error", NULL, "callref already in use");
97 mncc = create_mncc(MNCC_REJ_REQ, callref);
98 gsm_trace_header(p_m_mISDNport, this, MNCC_REJ_REQ, DIRECTION_OUT);
99 mncc->fields |= MNCC_F_CAUSE;
100 mncc->cause.coding = 3;
101 mncc->cause.location = 1;
102 mncc->cause.value = 47;
103 add_trace("cause", "coding", "%d", mncc->cause.coding);
104 add_trace("cause", "location", "%d", mncc->cause.location);
105 add_trace("cause", "value", "%d", mncc->cause.value);
106 add_trace("reason", NULL, "callref already in use");
108 send_and_free_mncc(p_m_g_instance, mncc->msg_type, mncc);
109 new_state(PORT_STATE_RELEASE);
110 trigger_work(&p_m_g_delete);
113 p_m_g_callref = callref;
116 /* if blocked, release call with MT_RELEASE_COMPLETE */
117 if (p_m_mISDNport->ifport->block) {
118 mncc = create_mncc(MNCC_REJ_REQ, p_m_g_callref);
119 gsm_trace_header(p_m_mISDNport, this, MNCC_REJ_REQ, DIRECTION_OUT);
120 mncc->fields |= MNCC_F_CAUSE;
121 mncc->cause.coding = 3;
122 mncc->cause.location = 1;
123 mncc->cause.value = 27;
124 add_trace("cause", "coding", "%d", mncc->cause.coding);
125 add_trace("cause", "location", "%d", mncc->cause.location);
126 add_trace("cause", "value", "%d", mncc->cause.value);
127 add_trace("reason", NULL, "port is blocked");
129 send_and_free_mncc(p_m_g_instance, mncc->msg_type, mncc);
130 new_state(PORT_STATE_RELEASE);
131 trigger_work(&p_m_g_delete);
135 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_IND, DIRECTION_IN);
136 /* caller information */
137 p_callerinfo.ntype = INFO_NTYPE_NOTPRESENT;
138 if (mncc->fields & MNCC_F_CALLING) {
139 switch (mncc->calling.present) {
141 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
144 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
147 p_callerinfo.present = INFO_PRESENT_ALLOWED;
150 switch (mncc->calling.screen) {
152 p_callerinfo.screen = INFO_SCREEN_USER;
155 p_callerinfo.screen = INFO_SCREEN_USER_VERIFIED_PASSED;
158 p_callerinfo.screen = INFO_SCREEN_USER_VERIFIED_FAILED;
161 p_callerinfo.screen = INFO_SCREEN_NETWORK;
164 switch (mncc->calling.type) {
166 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
169 p_callerinfo.ntype = INFO_NTYPE_INTERNATIONAL;
172 p_callerinfo.ntype = INFO_NTYPE_NATIONAL;
175 p_callerinfo.ntype = INFO_NTYPE_SUBSCRIBER;
178 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
181 SCPY(p_callerinfo.id, mncc->calling.number);
182 add_trace("calling", "type", "%d", mncc->calling.type);
183 add_trace("calling", "plan", "%d", mncc->calling.plan);
184 add_trace("calling", "present", "%d", mncc->calling.present);
185 add_trace("calling", "screen", "%d", mncc->calling.screen);
186 add_trace("calling", "number", "%s", mncc->calling.number);
188 p_callerinfo.isdn_port = p_m_portnum;
189 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
190 /* dialing information */
191 if (mncc->fields & MNCC_F_CALLED) {
192 SCAT(p_dialinginfo.id, mncc->called.number);
193 switch (mncc->called.type) {
195 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
198 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
201 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
204 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
207 add_trace("dialing", "type", "%d", mncc->called.type);
208 add_trace("dialing", "plan", "%d", mncc->called.plan);
209 add_trace("dialing", "number", "%s", mncc->called.number);
211 p_dialinginfo.sending_complete = 1;
213 p_redirinfo.ntype = INFO_NTYPE_NOTPRESENT;
214 if (mncc->fields & MNCC_F_REDIRECTING) {
215 switch (mncc->redirecting.present) {
217 p_redirinfo.present = INFO_PRESENT_RESTRICTED;
220 p_redirinfo.present = INFO_PRESENT_NOTAVAIL;
223 p_redirinfo.present = INFO_PRESENT_ALLOWED;
226 switch (mncc->redirecting.screen) {
228 p_redirinfo.screen = INFO_SCREEN_USER;
231 p_redirinfo.screen = INFO_SCREEN_USER_VERIFIED_PASSED;
234 p_redirinfo.screen = INFO_SCREEN_USER_VERIFIED_FAILED;
237 p_redirinfo.screen = INFO_SCREEN_NETWORK;
240 switch (mncc->redirecting.type) {
242 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
245 p_redirinfo.ntype = INFO_NTYPE_INTERNATIONAL;
248 p_redirinfo.ntype = INFO_NTYPE_NATIONAL;
251 p_redirinfo.ntype = INFO_NTYPE_SUBSCRIBER;
254 p_redirinfo.ntype = INFO_NTYPE_UNKNOWN;
257 SCPY(p_redirinfo.id, mncc->redirecting.number);
258 add_trace("redir", "type", "%d", mncc->redirecting.type);
259 add_trace("redir", "plan", "%d", mncc->redirecting.plan);
260 add_trace("redir", "present", "%d", mncc->redirecting.present);
261 add_trace("redir", "screen", "%d", mncc->redirecting.screen);
262 add_trace("redir", "number", "%s", mncc->redirecting.number);
263 p_redirinfo.isdn_port = p_m_portnum;
265 /* bearer capability */
266 if (mncc->fields & MNCC_F_BEARER_CAP) {
267 switch (mncc->bearer_cap.transfer) {
269 p_capainfo.bearer_capa = INFO_BC_DATAUNRESTRICTED;
273 p_capainfo.bearer_capa = INFO_BC_AUDIO;
274 p_capainfo.bearer_info1 = (options.law=='a')?3:2;
277 p_capainfo.bearer_capa = INFO_BC_SPEECH;
278 p_capainfo.bearer_info1 = (options.law=='a')?3:2;
281 switch (mncc->bearer_cap.mode) {
283 p_capainfo.bearer_mode = INFO_BMODE_PACKET;
286 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
289 add_trace("bearer", "transfer", "%d", mncc->bearer_cap.transfer);
290 add_trace("bearer", "mode", "%d", mncc->bearer_cap.mode);
292 p_capainfo.bearer_capa = INFO_BC_SPEECH;
293 p_capainfo.bearer_info1 = (options.law=='a')?3:2;
294 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
296 /* if packet mode works some day, see dss1.cpp for conditions */
297 p_capainfo.source_mode = B_MODE_TRANSPARENT;
302 ret = channel = hunt_bchannel();
307 ret = seize_bchannel(channel, 1);
310 mncc = create_mncc(MNCC_REJ_REQ, p_m_g_callref);
311 gsm_trace_header(p_m_mISDNport, this, MNCC_REJ_REQ, DIRECTION_OUT);
312 mncc->fields |= MNCC_F_CAUSE;
313 mncc->cause.coding = 3;
314 mncc->cause.location = 1;
315 mncc->cause.value = 34;
316 add_trace("cause", "coding", "%d", mncc->cause.coding);
317 add_trace("cause", "location", "%d", mncc->cause.location);
318 add_trace("cause", "value", "%d", mncc->cause.value);
319 add_trace("reason", NULL, "no channel");
321 send_and_free_mncc(p_m_g_instance, mncc->msg_type, mncc);
322 new_state(PORT_STATE_RELEASE);
323 trigger_work(&p_m_g_delete);
326 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
327 if (bchannel_open(p_m_b_index))
330 /* create endpoint */
332 FATAL("Incoming call but already got an endpoint.\n");
333 if (!(epoint = new Endpoint(p_serial, 0)))
334 FATAL("No memory for Endpoint instance\n");
335 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 0))) //incoming
336 FATAL("No memory for Endpoint Application instance\n");
337 epointlist_new(epoint->ep_serial);
339 /* modify lchan to GSM codec V1 */
340 gsm_trace_header(p_m_mISDNport, this, MNCC_LCHAN_MODIFY, DIRECTION_OUT);
341 mode = create_mncc(MNCC_LCHAN_MODIFY, p_m_g_callref);
342 mode->lchan_mode = 0x01; /* GSM V1 */
343 add_trace("mode", NULL, "0x%02x", mode->lchan_mode);
345 send_and_free_mncc(p_m_g_instance, mode->msg_type, mode);
347 /* send call proceeding */
348 gsm_trace_header(p_m_mISDNport, this, MNCC_CALL_CONF_REQ, DIRECTION_OUT);
349 proceeding = create_mncc(MNCC_CALL_CONF_REQ, p_m_g_callref);
352 proceeding->fields |= MNCC_F_CCCAP;
353 proceeding->cccap.dtmf = 1;
355 send_and_free_mncc(p_m_g_instance, proceeding->msg_type, proceeding);
357 new_state(PORT_STATE_IN_PROCEEDING);
359 if (p_m_mISDNport->tones && !p_m_g_tch_connected) { /* only if ... */
360 gsm_trace_header(p_m_mISDNport, this, MNCC_FRAME_RECV, DIRECTION_OUT);
362 frame = create_mncc(MNCC_FRAME_RECV, p_m_g_callref);
363 send_and_free_mncc(p_m_g_instance, frame->msg_type, frame);
364 p_m_g_tch_connected = 1;
367 /* send setup message to endpoit */
368 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
369 message->param.setup.isdn_port = p_m_portnum;
370 message->param.setup.port_type = p_type;
371 // message->param.setup.dtmf = 0;
372 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
373 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
374 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
375 SCPY((char *)message->param.setup.useruser.data, (char *)mncc->useruser.info);
376 message->param.setup.useruser.len = strlen(mncc->useruser.info);
377 message->param.setup.useruser.protocol = mncc->useruser.proto;
378 message_put(message);
382 * MS sends message to port
384 static int message_ms(struct osmocom_ms *ms, int msg_type, void *arg)
386 struct gsm_mncc *mncc = (struct gsm_mncc *)arg;
387 unsigned int callref = mncc->callref;
389 class Pgsm_ms *pgsm_ms = NULL;
391 struct mISDNport *mISDNport;
393 /* Special messages */
396 PDEBUG(DEBUG_GSM, "MS %s comes available\n", ms->name);
399 PDEBUG(DEBUG_GSM, "MS %s is removed\n", ms->name);
402 if ((port->p_type & PORT_CLASS_GSM_MASK) == PORT_CLASS_GSM_MS) {
403 pgsm_ms = (class Pgsm_ms *)port;
404 if (pgsm_ms->p_m_g_instance == ms) {
405 struct lcr_msg *message;
407 pgsm_ms->p_m_g_instance = 0;
408 message = message_create(pgsm_ms->p_serial, ACTIVE_EPOINT(pgsm_ms->p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
409 message->param.disconnectinfo.cause = 27;
410 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
411 message_put(message);
412 pgsm_ms->new_state(PORT_STATE_RELEASE);
413 trigger_work(&pgsm_ms->p_m_g_delete);
422 callref = mncc->callref;
425 if ((port->p_type & PORT_CLASS_GSM_MASK) == PORT_CLASS_GSM_MS) {
426 pgsm_ms = (class Pgsm_ms *)port;
427 if (pgsm_ms->p_m_g_callref == callref) {
434 if (msg_type == GSM_TCHF_FRAME) {
436 pgsm_ms->frame_receive(arg);
441 if (msg_type != MNCC_SETUP_IND)
443 /* find gsm ms port */
444 mISDNport = mISDNport_first;
446 if (mISDNport->gsm_ms && !strcmp(mISDNport->ifport->gsm_ms_name, ms->name))
448 mISDNport = mISDNport->next;
451 struct gsm_mncc *rej;
453 rej = create_mncc(MNCC_REJ_REQ, callref);
454 rej->fields |= MNCC_F_CAUSE;
455 rej->cause.coding = 3;
456 rej->cause.location = 1;
457 rej->cause.value = 27;
458 gsm_trace_header(NULL, NULL, MNCC_REJ_REQ, DIRECTION_OUT);
459 add_trace("cause", "coding", "%d", rej->cause.coding);
460 add_trace("cause", "location", "%d", rej->cause.location);
461 add_trace("cause", "value", "%d", rej->cause.value);
463 send_and_free_mncc(ms, rej->msg_type, rej);
466 /* creating port object, transparent until setup with hdlc */
467 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
468 if (!(pgsm_ms = new Pgsm_ms(PORT_TYPE_GSM_MS_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
470 FATAL("Cannot create Port instance.\n");
475 pgsm_ms->setup_ind(msg_type, callref, mncc);
478 case MNCC_CALL_PROC_IND:
479 pgsm_ms->call_proc_ind(msg_type, callref, mncc);
483 pgsm_ms->alert_ind(msg_type, callref, mncc);
487 pgsm_ms->setup_cnf(msg_type, callref, mncc);
490 case MNCC_SETUP_COMPL_IND:
491 pgsm_ms->setup_compl_ind(msg_type, callref, mncc);
495 pgsm_ms->disc_ind(msg_type, callref, mncc);
501 pgsm_ms->rel_ind(msg_type, callref, mncc);
504 case MNCC_NOTIFY_IND:
505 pgsm_ms->notify_ind(msg_type, callref, mncc);
508 case MNCC_START_DTMF_RSP:
509 case MNCC_START_DTMF_REJ:
510 case MNCC_STOP_DTMF_RSP:
511 pgsm_ms->dtmf_statemachine(mncc);
521 void Pgsm_ms::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
523 struct lcr_msg *message;
525 struct epoint_list *epointlist;
526 struct gsm_mncc *mncc;
529 /* copy setup infos to port */
530 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
531 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
532 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
533 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
536 if (!p_m_g_instance) {
537 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
538 add_trace("failure", NULL, "MS %s instance is unavailable", p_m_mISDNport->ifport->gsm_ms_name);
540 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
541 message->param.disconnectinfo.cause = 27;
542 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
543 message_put(message);
544 new_state(PORT_STATE_RELEASE);
545 trigger_work(&p_m_g_delete);
550 if (!p_dialinginfo.id[0]) {
551 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
552 add_trace("failure", NULL, "No dialed subscriber given.");
554 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
555 message->param.disconnectinfo.cause = 28;
556 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
557 message_put(message);
558 new_state(PORT_STATE_RELEASE);
559 trigger_work(&p_m_g_delete);
563 /* release if port is blocked */
564 if (p_m_mISDNport->ifport->block) {
565 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
566 add_trace("failure", NULL, "Port blocked.");
568 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
569 message->param.disconnectinfo.cause = 27; // temp. unavail.
570 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
571 message_put(message);
572 new_state(PORT_STATE_RELEASE);
573 trigger_work(&p_m_g_delete);
578 ret = channel = hunt_bchannel();
582 ret = seize_bchannel(channel, 1);
585 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
586 add_trace("failure", NULL, "No internal audio channel available.");
588 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
589 message->param.disconnectinfo.cause = 34;
590 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
591 message_put(message);
592 new_state(PORT_STATE_RELEASE);
593 trigger_work(&p_m_g_delete);
596 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
597 if (bchannel_open(p_m_b_index))
600 /* attach only if not already */
601 epointlist = p_epointlist;
603 if (epointlist->epoint_id == epoint_id)
605 epointlist = epointlist->next;
608 epointlist_new(epoint_id);
611 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_REQ, DIRECTION_OUT);
612 p_m_g_callref = new_callref++;
613 add_trace("callref", "new", "0x%x", p_m_g_callref);
616 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
617 mncc = create_mncc(MNCC_SETUP_REQ, p_m_g_callref);
618 if (!strncasecmp(p_dialinginfo.id, "emerg", 5)) {
621 /* caller info (only clir) */
622 switch (p_callerinfo.present) {
623 case INFO_PRESENT_ALLOWED:
629 /* dialing information (mandatory) */
630 mncc->fields |= MNCC_F_CALLED;
631 mncc->called.type = 0; /* unknown */
632 mncc->called.plan = 1; /* isdn */
633 SCPY(mncc->called.number, p_dialinginfo.id);
634 add_trace("dialing", "number", "%s", mncc->called.number);
636 /* bearer capability (mandatory) */
637 mncc->fields |= MNCC_F_BEARER_CAP;
638 mncc->bearer_cap.coding = 0;
639 mncc->bearer_cap.radio = 1;
640 mncc->bearer_cap.speech_ctm = 0;
641 mncc->bearer_cap.speech_ver[0] = 0;
642 mncc->bearer_cap.speech_ver[1] = -1; /* end of list */
643 switch (p_capainfo.bearer_capa) {
644 case INFO_BC_DATAUNRESTRICTED:
645 case INFO_BC_DATARESTRICTED:
646 mncc->bearer_cap.transfer = 1;
649 mncc->bearer_cap.transfer = 0;
652 mncc->bearer_cap.transfer = 2;
655 switch (p_capainfo.bearer_mode) {
656 case INFO_BMODE_PACKET:
657 mncc->bearer_cap.mode = 1;
660 mncc->bearer_cap.mode = 0;
664 mncc->fields |= MNCC_F_CCCAP;
665 mncc->cccap.dtmf = 1;
667 /* request keypad from remote */
668 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ENABLEKEYPAD);
669 message_put(message);
673 send_and_free_mncc(p_m_g_instance, mncc->msg_type, mncc);
675 new_state(PORT_STATE_OUT_SETUP);
677 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
678 message_put(message);
680 new_state(PORT_STATE_OUT_PROCEEDING);
683 void Pgsm_ms::dtmf_statemachine(struct gsm_mncc *mncc)
685 struct gsm_mncc *dtmf;
687 switch (p_m_g_dtmf_state) {
691 if (!p_m_g_dtmf[p_m_g_dtmf_index]) {
692 PDEBUG(DEBUG_GSM, "done with DTMF\n");
693 p_m_g_dtmf_state = DTMF_ST_IDLE;
696 gsm_trace_header(p_m_mISDNport, this, MNCC_START_DTMF_REQ, DIRECTION_OUT);
697 dtmf = create_mncc(MNCC_START_DTMF_REQ, p_m_g_callref);
698 dtmf->keypad = p_m_g_dtmf[p_m_g_dtmf_index++];
699 p_m_g_dtmf_state = DTMF_ST_START;
700 PDEBUG(DEBUG_GSM, "start DTMF (keypad %c)\n",
703 send_and_free_mncc(p_m_g_instance, dtmf->msg_type, dtmf);
706 if (mncc->msg_type != MNCC_START_DTMF_RSP) {
707 PDEBUG(DEBUG_GSM, "DTMF was rejected\n");
710 schedule_timer(&p_m_g_dtmf_timer, 0, 70 * 1000);
711 p_m_g_dtmf_state = DTMF_ST_MARK;
712 PDEBUG(DEBUG_GSM, "DTMF is on\n");
715 gsm_trace_header(p_m_mISDNport, this, MNCC_STOP_DTMF_REQ, DIRECTION_OUT);
716 dtmf = create_mncc(MNCC_STOP_DTMF_REQ, p_m_g_callref);
717 p_m_g_dtmf_state = DTMF_ST_STOP;
719 send_and_free_mncc(p_m_g_instance, dtmf->msg_type, dtmf);
722 schedule_timer(&p_m_g_dtmf_timer, 0, 120 * 1000);
723 p_m_g_dtmf_state = DTMF_ST_SPACE;
724 PDEBUG(DEBUG_GSM, "DTMF is off\n");
729 static int dtmf_timeout(struct lcr_timer *timer, void *instance, int index)
731 class Pgsm_ms *pgsm_ms = (class Pgsm_ms *)instance;
733 PDEBUG(DEBUG_GSM, "DTMF timer has fired\n");
734 pgsm_ms->dtmf_statemachine(NULL);
740 void Pgsm_ms::message_dtmf(unsigned int epoint_id, int message_id, union parameter *param)
742 char digit = param->dtmf;
744 if (digit >= 'a' && digit <= 'c')
745 digit = digit - 'a' + 'A';
746 if (!strchr("01234567890*#ABC", digit))
750 if (p_m_g_dtmf_state == DTMF_ST_IDLE) {
751 p_m_g_dtmf_index = 0;
752 p_m_g_dtmf[0] = '\0';
754 SCCAT(p_m_g_dtmf, digit);
755 if (p_m_g_dtmf_state == DTMF_ST_IDLE)
756 dtmf_statemachine(NULL);
759 /* MESSAGE_INFORMATION */
760 void Pgsm_ms::message_information(unsigned int epoint_id, int message_id, union parameter *param)
765 for (i = 0; i < (int)strlen(param->information.id); i++) {
766 digit = param->information.id[i];
767 if (digit >= 'a' && digit <= 'c')
768 digit = digit - 'a' + 'A';
769 if (!strchr("01234567890*#ABC", digit))
773 if (p_m_g_dtmf_state == DTMF_ST_IDLE) {
774 p_m_g_dtmf_index = 0;
775 p_m_g_dtmf[0] = '\0';
777 SCCAT(p_m_g_dtmf, digit);
778 if (p_m_g_dtmf_state == DTMF_ST_IDLE)
779 dtmf_statemachine(NULL);
784 * endpoint sends messages to the port
786 int Pgsm_ms::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
788 struct lcr_msg *message;
790 if (message_id == MESSAGE_CONNECT) {
791 /* request keypad from remote */
792 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ENABLEKEYPAD);
793 message_put(message);
796 if (Pgsm::message_epoint(epoint_id, message_id, param))
800 case MESSAGE_SETUP: /* dial-out command received from epoint */
801 if (p_state!=PORT_STATE_IDLE)
803 message_setup(epoint_id, message_id, param);
807 message_dtmf(epoint_id, message_id, param);
810 case MESSAGE_INFORMATION:
811 message_information(epoint_id, message_id, param);
815 PDEBUG(DEBUG_GSM, "Pgsm_ms(%s) gsm port with (caller id %s) received unhandled nessage: %d\n", p_name, p_callerinfo.id, message_id);
821 int gsm_ms_exit(int rc)
828 int gsm_ms_init(void)
832 const char osmocomcfg[] = ".osmocom/bb/mobile.cfg";
833 char *config_file = NULL;
835 INIT_LLIST_HEAD(&ms_list);
836 log_init(&log_info, NULL);
837 stderr_target = log_target_create_stderr();
838 log_add_target(stderr_target);
839 log_set_all_filter(stderr_target, 1);
841 l23_ctx = talloc_named_const(NULL, 1, "layer2 context");
843 log_parse_category_mask(stderr_target, "DNB:DCS:DPLMN:DRR:DMM:DSIM:DCC:DMNCC:DPAG:DSUM");
844 log_set_log_level(stderr_target, LOGL_INFO);
848 rc = gsmtap_init(gsmtap_ip);
850 fprintf(stderr, "Failed during gsmtap_init()\n");
856 home = getenv("HOME");
858 len = strlen(home) + 1 + sizeof(osmocomcfg);
859 config_file = (char *)talloc_size(l23_ctx, len);
860 if (config_file != NULL)
861 UNPRINT(config_file, len, "%s/%s", home, osmocomcfg);
863 /* save the config file directory name */
864 config_dir = talloc_strdup(l23_ctx, config_file);
865 config_dir = dirname(config_dir);
867 l23_app_init(message_ms, config_file, vty_port);
872 /* add a new GSM mobile instance */
873 int gsm_ms_new(const char *name)
875 PDEBUG(DEBUG_GSM, "GSM: interface for MS '%s' is up\n", name);
880 int gsm_ms_delete(const char *name)
882 struct osmocom_ms *ms;
885 class Pgsm_ms *pgsm_ms = NULL;
887 PDEBUG(DEBUG_GSM, "GSM: interface for MS '%s' is down\n", name);
889 llist_for_each_entry(ms, &ms_list, entity) {
890 if (!strcmp(ms->name, name)) {
901 if ((port->p_type & PORT_CLASS_GSM_MASK) == PORT_CLASS_GSM_MS) {
902 pgsm_ms = (class Pgsm_ms *)port;
903 if (pgsm_ms->p_m_g_instance == ms && pgsm_ms->p_m_g_callref) {
904 struct gsm_mncc *rej;
906 rej = create_mncc(MNCC_REL_REQ, pgsm_ms->p_m_g_callref);
907 rej->fields |= MNCC_F_CAUSE;
908 rej->cause.coding = 3;
909 rej->cause.location = 1;
910 rej->cause.value = 27;
911 gsm_trace_header(NULL, NULL, MNCC_REJ_REQ, DIRECTION_OUT);
912 add_trace("cause", "coding", "%d", rej->cause.coding);
913 add_trace("cause", "location", "%d", rej->cause.location);
914 add_trace("cause", "value", "%d", rej->cause.value);
924 * handles bsc select function within LCR's main loop
926 int handle_gsm_ms(int *_quit)
928 int work = 0, quit = 0;
930 if (l23_app_work(&quit))
932 if (quit && llist_empty(&ms_list))
934 // debug_reset_context();
935 if (osmo_select_main(1)) /* polling */