1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** mISDN gsm (MS mode) **
10 \*****************************************************************************/
20 #include <osmocore/select.h>
21 #include <osmocore/talloc.h>
23 #include <osmocom/bb/common/osmocom_data.h>
24 #include <osmocom/bb/common/logging.h>
25 #include <osmocom/bb/common/l1l2_interface.h>
26 #include <osmocom/bb/common/l23_app.h>
29 const char *openbsc_copyright = "";
30 short vty_port = 4247;
32 struct llist_head ms_list;
33 struct log_target *stderr_target;
35 int (*l23_app_work) (struct osmocom_ms *ms) = NULL;
36 int (*l23_app_exit) (struct osmocom_ms *ms) = NULL;
38 static int dtmf_timeout(struct lcr_timer *timer, void *instance, int index);
43 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)
45 struct osmocom_ms *ms = NULL;
46 char *ms_name = mISDNport->ifport->gsm_ms_name;
48 p_m_g_instance = NULL;
50 llist_for_each_entry(ms, &ms_list, entity) {
51 if (!strcmp(ms->name, ms_name)) {
58 FATAL("MS name %s does not exists. Please fix!");
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 */
398 callref = mncc->callref;
401 if ((port->p_type & PORT_CLASS_GSM_MASK) == PORT_CLASS_GSM_MS) {
402 pgsm_ms = (class Pgsm_ms *)port;
403 if (pgsm_ms->p_m_g_callref == callref) {
410 if (msg_type == GSM_TCHF_FRAME) {
412 pgsm_ms->frame_receive(arg);
417 if (msg_type != MNCC_SETUP_IND)
419 /* find gsm ms port */
420 mISDNport = mISDNport_first;
422 if (mISDNport->gsm_ms && !strcmp(mISDNport->ifport->gsm_ms_name, ms->name))
424 mISDNport = mISDNport->next;
427 struct gsm_mncc *rej;
429 rej = create_mncc(MNCC_REJ_REQ, callref);
430 rej->fields |= MNCC_F_CAUSE;
431 rej->cause.coding = 3;
432 rej->cause.location = 1;
433 rej->cause.value = 27;
434 gsm_trace_header(NULL, NULL, MNCC_REJ_REQ, DIRECTION_OUT);
435 add_trace("cause", "coding", "%d", rej->cause.coding);
436 add_trace("cause", "location", "%d", rej->cause.location);
437 add_trace("cause", "value", "%d", rej->cause.value);
439 send_and_free_mncc(ms, rej->msg_type, rej);
442 /* creating port object, transparent until setup with hdlc */
443 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
444 if (!(pgsm_ms = new Pgsm_ms(PORT_TYPE_GSM_MS_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
446 FATAL("Cannot create Port instance.\n");
451 pgsm_ms->setup_ind(msg_type, callref, mncc);
454 case MNCC_CALL_PROC_IND:
455 pgsm_ms->call_proc_ind(msg_type, callref, mncc);
459 pgsm_ms->alert_ind(msg_type, callref, mncc);
463 pgsm_ms->setup_cnf(msg_type, callref, mncc);
466 case MNCC_SETUP_COMPL_IND:
467 pgsm_ms->setup_compl_ind(msg_type, callref, mncc);
471 pgsm_ms->disc_ind(msg_type, callref, mncc);
477 pgsm_ms->rel_ind(msg_type, callref, mncc);
480 case MNCC_NOTIFY_IND:
481 pgsm_ms->notify_ind(msg_type, callref, mncc);
484 case MNCC_START_DTMF_RSP:
485 case MNCC_START_DTMF_REJ:
486 case MNCC_STOP_DTMF_RSP:
487 pgsm_ms->dtmf_statemachine(mncc);
497 void Pgsm_ms::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
499 struct lcr_msg *message;
501 struct epoint_list *epointlist;
502 struct gsm_mncc *mncc;
505 /* copy setup infos to port */
506 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
507 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
508 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
509 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
512 if (!p_dialinginfo.id[0]) {
513 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
514 add_trace("failure", NULL, "No dialed subscriber given.");
516 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
517 message->param.disconnectinfo.cause = 28;
518 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
519 message_put(message);
520 new_state(PORT_STATE_RELEASE);
521 trigger_work(&p_m_g_delete);
525 /* release if port is blocked */
526 if (p_m_mISDNport->ifport->block) {
527 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
528 add_trace("failure", NULL, "Port blocked.");
530 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
531 message->param.disconnectinfo.cause = 27; // temp. unavail.
532 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
533 message_put(message);
534 new_state(PORT_STATE_RELEASE);
535 trigger_work(&p_m_g_delete);
540 ret = channel = hunt_bchannel();
544 ret = seize_bchannel(channel, 1);
547 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
548 add_trace("failure", NULL, "No internal audio channel available.");
550 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
551 message->param.disconnectinfo.cause = 34;
552 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
553 message_put(message);
554 new_state(PORT_STATE_RELEASE);
555 trigger_work(&p_m_g_delete);
558 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
559 if (bchannel_open(p_m_b_index))
562 /* attach only if not already */
563 epointlist = p_epointlist;
565 if (epointlist->epoint_id == epoint_id)
567 epointlist = epointlist->next;
570 epointlist_new(epoint_id);
573 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_REQ, DIRECTION_OUT);
574 p_m_g_callref = new_callref++;
575 add_trace("callref", "new", "0x%x", p_m_g_callref);
578 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
579 mncc = create_mncc(MNCC_SETUP_REQ, p_m_g_callref);
580 if (!strncasecmp(p_dialinginfo.id, "emerg", 5)) {
583 /* caller info (only clir) */
584 switch (p_callerinfo.present) {
585 case INFO_PRESENT_ALLOWED:
591 /* dialing information (mandatory) */
592 mncc->fields |= MNCC_F_CALLED;
593 mncc->called.type = 0; /* unknown */
594 mncc->called.plan = 1; /* isdn */
595 SCPY(mncc->called.number, p_dialinginfo.id);
596 add_trace("dialing", "number", "%s", mncc->called.number);
598 /* bearer capability (mandatory) */
599 mncc->fields |= MNCC_F_BEARER_CAP;
600 mncc->bearer_cap.coding = 0;
601 mncc->bearer_cap.radio = 1;
602 mncc->bearer_cap.speech_ctm = 0;
603 mncc->bearer_cap.speech_ver[0] = 0;
604 mncc->bearer_cap.speech_ver[1] = -1; /* end of list */
605 switch (p_capainfo.bearer_capa) {
606 case INFO_BC_DATAUNRESTRICTED:
607 case INFO_BC_DATARESTRICTED:
608 mncc->bearer_cap.transfer = 1;
611 mncc->bearer_cap.transfer = 0;
614 mncc->bearer_cap.transfer = 2;
617 switch (p_capainfo.bearer_mode) {
618 case INFO_BMODE_PACKET:
619 mncc->bearer_cap.mode = 1;
622 mncc->bearer_cap.mode = 0;
626 mncc->fields |= MNCC_F_CCCAP;
627 mncc->cccap.dtmf = 1;
629 /* request keypad from remote */
630 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ENABLEKEYPAD);
631 message_put(message);
635 send_and_free_mncc(p_m_g_instance, mncc->msg_type, mncc);
637 new_state(PORT_STATE_OUT_SETUP);
639 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
640 message_put(message);
642 new_state(PORT_STATE_OUT_PROCEEDING);
645 void Pgsm_ms::dtmf_statemachine(struct gsm_mncc *mncc)
647 struct gsm_mncc *dtmf;
649 switch (p_m_g_dtmf_state) {
653 if (!p_m_g_dtmf[p_m_g_dtmf_index]) {
654 PDEBUG(DEBUG_GSM, "done with DTMF\n");
655 p_m_g_dtmf_state = DTMF_ST_IDLE;
658 gsm_trace_header(p_m_mISDNport, this, MNCC_START_DTMF_REQ, DIRECTION_OUT);
659 dtmf = create_mncc(MNCC_START_DTMF_REQ, p_m_g_callref);
660 dtmf->keypad = p_m_g_dtmf[p_m_g_dtmf_index++];
661 p_m_g_dtmf_state = DTMF_ST_START;
662 PDEBUG(DEBUG_GSM, "start DTMF (keypad %c)\n",
665 send_and_free_mncc(p_m_g_instance, dtmf->msg_type, dtmf);
668 if (mncc->msg_type != MNCC_START_DTMF_RSP) {
669 PDEBUG(DEBUG_GSM, "DTMF was rejected\n");
672 schedule_timer(&p_m_g_dtmf_timer, 0, 70 * 1000);
673 p_m_g_dtmf_state = DTMF_ST_MARK;
674 PDEBUG(DEBUG_GSM, "DTMF is on\n");
677 gsm_trace_header(p_m_mISDNport, this, MNCC_STOP_DTMF_REQ, DIRECTION_OUT);
678 dtmf = create_mncc(MNCC_STOP_DTMF_REQ, p_m_g_callref);
679 p_m_g_dtmf_state = DTMF_ST_STOP;
681 send_and_free_mncc(p_m_g_instance, dtmf->msg_type, dtmf);
684 schedule_timer(&p_m_g_dtmf_timer, 0, 120 * 1000);
685 p_m_g_dtmf_state = DTMF_ST_SPACE;
686 PDEBUG(DEBUG_GSM, "DTMF is off\n");
691 static int dtmf_timeout(struct lcr_timer *timer, void *instance, int index)
693 class Pgsm_ms *pgsm_ms = (class Pgsm_ms *)instance;
695 PDEBUG(DEBUG_GSM, "DTMF timer has fired\n");
696 pgsm_ms->dtmf_statemachine(NULL);
702 void Pgsm_ms::message_dtmf(unsigned int epoint_id, int message_id, union parameter *param)
704 char digit = param->dtmf;
706 if (digit >= 'a' && digit <= 'c')
707 digit = digit - 'a' + 'A';
708 if (!strchr("01234567890*#ABC", digit))
712 if (p_m_g_dtmf_state == DTMF_ST_IDLE) {
713 p_m_g_dtmf_index = 0;
714 p_m_g_dtmf[0] = '\0';
716 SCCAT(p_m_g_dtmf, digit);
717 if (p_m_g_dtmf_state == DTMF_ST_IDLE)
718 dtmf_statemachine(NULL);
721 /* MESSAGE_INFORMATION */
722 void Pgsm_ms::message_information(unsigned int epoint_id, int message_id, union parameter *param)
727 for (i = 0; i < (int)strlen(param->information.id); i++) {
728 digit = param->information.id[i];
729 if (digit >= 'a' && digit <= 'c')
730 digit = digit - 'a' + 'A';
731 if (!strchr("01234567890*#ABC", digit))
735 if (p_m_g_dtmf_state == DTMF_ST_IDLE) {
736 p_m_g_dtmf_index = 0;
737 p_m_g_dtmf[0] = '\0';
739 SCCAT(p_m_g_dtmf, digit);
740 if (p_m_g_dtmf_state == DTMF_ST_IDLE)
741 dtmf_statemachine(NULL);
746 * endpoint sends messages to the port
748 int Pgsm_ms::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
750 struct lcr_msg *message;
752 if (message_id == MESSAGE_CONNECT) {
753 /* request keypad from remote */
754 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_ENABLEKEYPAD);
755 message_put(message);
758 if (Pgsm::message_epoint(epoint_id, message_id, param))
762 case MESSAGE_SETUP: /* dial-out command received from epoint */
763 if (p_state!=PORT_STATE_IDLE)
765 message_setup(epoint_id, message_id, param);
769 message_dtmf(epoint_id, message_id, param);
772 case MESSAGE_INFORMATION:
773 message_information(epoint_id, message_id, param);
777 PDEBUG(DEBUG_GSM, "Pgsm_ms(%s) gsm port with (caller id %s) received unhandled nessage: %d\n", p_name, p_callerinfo.id, message_id);
783 int gsm_ms_exit(int rc)
789 int gsm_ms_init(void)
791 INIT_LLIST_HEAD(&ms_list);
793 stderr_target = log_target_create_stderr();
794 log_add_target(stderr_target);
795 log_set_all_filter(stderr_target, 1);
797 l23_ctx = talloc_named_const(NULL, 1, "layer2 context");
802 /* add a new GSM mobile instance */
803 int gsm_ms_new(const char *name, const char *socket_path)
805 struct osmocom_ms *ms = NULL;
808 PDEBUG(DEBUG_GSM, "GSM: creating new instance '%s' on '%s'\n", name, socket_path);
810 ms = talloc_zero(l23_ctx, struct osmocom_ms);
812 FATAL("Failed to allocate MS\n");
814 /* must add here, because other init processes may search in the list */
815 llist_add_tail(&ms->entity, &ms_list);
818 SPRINT(ms->name, name);
820 rc = layer2_open(ms, socket_path);
822 FATAL("Failed during layer2_open()\n");
825 lapdm_init(&ms->l2_entity.lapdm_dcch, ms);
826 lapdm_init(&ms->l2_entity.lapdm_acch, ms);
828 rc = l23_app_init(ms);
830 FATAL("Failed to init layer23\n");
832 ms->mncc_entity.mncc_recv = message_ms;
837 int gsm_ms_delete(const char *name)
839 struct osmocom_ms *ms = NULL;
842 PDEBUG(DEBUG_GSM, "GSM: destroying instance '%s'\n", name);
844 llist_for_each_entry(ms, &ms_list, entity) {
845 if (!strcmp(ms->name, name)) {
852 FATAL("Failed delete layer23, instance '%s' not found\n", name);
856 lapdm_exit(&ms->l2_entity.lapdm_dcch);
857 lapdm_exit(&ms->l2_entity.lapdm_acch);
859 llist_del(&ms->entity);
865 * handles bsc select function within LCR's main loop
867 int handle_gsm_ms(void)
869 struct osmocom_ms *ms = NULL;
872 llist_for_each_entry(ms, &ms_list, entity) {
873 if (l23_app_work(ms))
875 // debug_reset_context();
876 if (bsc_select_main(1)) /* polling */