1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** mISDN gsm (BS mode) **
10 \*****************************************************************************/
15 struct lcr_gsm *gsm_bs = NULL;
20 unsigned char dtmf_samples[16][8000];
21 static int dtmf_x[4] = { 1209, 1336, 1477, 1633 };
22 static int dtmf_y[4] = { 697, 770, 852, 941 };
24 void generate_dtmf(void)
26 double fx, fy, sample;
30 for (y = 0; y < 4; y++) {
31 fy = 2 * 3.1415927 * ((double)dtmf_y[y]) / 8000.0;
32 for (x = 0; x < 4; x++) {
33 fx = 2 * 3.1415927 * ((double)dtmf_x[x]) / 8000.0;
34 law = dtmf_samples[y << 2 | x];
35 for (i = 0; i < 8000; i++) {
36 sample = sin(fy * ((double)i)) * 0.251 * 32767.0; /* -6 dB */
37 sample += sin(fx * ((double)i)) * 0.158 * 32767.0; /* -8 dB */
38 *law++ = audio_s16_to_law[(int)sample & 0xffff];
48 Pgsm_bs::Pgsm_bs(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)
50 p_m_g_lcr_gsm = gsm_bs;
54 PDEBUG(DEBUG_GSM, "Created new GSMBSPort(%s).\n", portname);
62 PDEBUG(DEBUG_GSM, "Destroyed GSM BS process(%s).\n", p_name);
66 void Pgsm_bs::start_dtmf_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
68 // struct lcr_msg *message;
69 struct gsm_mncc *resp;
71 gsm_trace_header(p_m_mISDNport, this, msg_type, DIRECTION_IN);
72 add_trace("keypad", NULL, "%c", mncc->keypad);
74 SPRINT(p_dialinginfo.id, "%c", mncc->keypad);
75 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
78 gsm_trace_header(p_m_mISDNport, this, MNCC_START_DTMF_RSP, DIRECTION_OUT);
79 add_trace("keypad", NULL, "%c", mncc->keypad);
81 resp = create_mncc(MNCC_START_DTMF_RSP, p_m_g_callref);
82 resp->fields |= MNCC_F_KEYPAD;
83 resp->keypad = mncc->keypad;
84 send_and_free_mncc(p_m_g_lcr_gsm, resp->msg_type, resp);
87 /* send dialing information */
88 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_INFORMATION);
89 memcpy(&message->param.information, &p_dialinginfo, sizeof(struct dialing_info));
93 /* generate DTMF tones */
94 switch (mncc->keypad) {
95 case '1': p_m_g_dtmf = dtmf_samples[0]; break;
96 case '2': p_m_g_dtmf = dtmf_samples[1]; break;
97 case '3': p_m_g_dtmf = dtmf_samples[2]; break;
99 case 'A': p_m_g_dtmf = dtmf_samples[3]; break;
100 case '4': p_m_g_dtmf = dtmf_samples[4]; break;
101 case '5': p_m_g_dtmf = dtmf_samples[5]; break;
102 case '6': p_m_g_dtmf = dtmf_samples[6]; break;
104 case 'B': p_m_g_dtmf = dtmf_samples[7]; break;
105 case '7': p_m_g_dtmf = dtmf_samples[8]; break;
106 case '8': p_m_g_dtmf = dtmf_samples[9]; break;
107 case '9': p_m_g_dtmf = dtmf_samples[10]; break;
109 case 'C': p_m_g_dtmf = dtmf_samples[11]; break;
110 case '*': p_m_g_dtmf = dtmf_samples[12]; break;
111 case '0': p_m_g_dtmf = dtmf_samples[13]; break;
112 case '#': p_m_g_dtmf = dtmf_samples[14]; break;
114 case 'D': p_m_g_dtmf = dtmf_samples[15]; break;
116 p_m_g_dtmf_index = 0;
118 void Pgsm_bs::stop_dtmf_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
120 struct gsm_mncc *resp;
122 gsm_trace_header(p_m_mISDNport, this, msg_type, DIRECTION_IN);
123 add_trace("keypad", NULL, "%c", mncc->keypad);
127 gsm_trace_header(p_m_mISDNport, this, MNCC_STOP_DTMF_RSP, DIRECTION_OUT);
128 add_trace("keypad", NULL, "%c", mncc->keypad);
130 resp = create_mncc(MNCC_STOP_DTMF_RSP, p_m_g_callref);
131 resp->keypad = mncc->keypad;
132 send_and_free_mncc(p_m_g_lcr_gsm, resp->msg_type, resp);
138 /* HOLD INDICATION */
139 void Pgsm_bs::hold_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
141 struct lcr_msg *message;
142 struct gsm_mncc *resp, *frame;
144 gsm_trace_header(p_m_mISDNport, this, msg_type, DIRECTION_IN);
147 /* notify the hold of call */
148 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
149 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
150 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
151 message_put(message);
153 /* acknowledge hold */
154 gsm_trace_header(p_m_mISDNport, this, MNCC_HOLD_CNF, DIRECTION_OUT);
156 resp = create_mncc(MNCC_HOLD_CNF, p_m_g_callref);
157 send_and_free_mncc(p_m_g_lcr_gsm, resp->msg_type, resp);
160 if (p_m_g_tch_connected) { /* it should be true */
161 gsm_trace_header(p_m_mISDNport, this, MNCC_FRAME_DROP, DIRECTION_OUT);
163 frame = create_mncc(MNCC_FRAME_DROP, p_m_g_callref);
164 send_and_free_mncc(p_m_g_lcr_gsm, frame->msg_type, frame);
165 p_m_g_tch_connected = 0;
170 /* RETRIEVE INDICATION */
171 void Pgsm_bs::retr_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
173 struct lcr_msg *message;
174 struct gsm_mncc *resp, *frame;
176 gsm_trace_header(p_m_mISDNport, this, msg_type, DIRECTION_IN);
179 /* notify the retrieve of call */
180 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
181 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
182 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
183 message_put(message);
185 /* acknowledge retr */
186 gsm_trace_header(p_m_mISDNport, this, MNCC_RETRIEVE_CNF, DIRECTION_OUT);
188 resp = create_mncc(MNCC_RETRIEVE_CNF, p_m_g_callref);
189 send_and_free_mncc(p_m_g_lcr_gsm, resp->msg_type, resp);
192 if (!p_m_g_tch_connected) { /* it should be true */
193 gsm_trace_header(p_m_mISDNport, this, MNCC_FRAME_RECV, DIRECTION_OUT);
195 frame = create_mncc(MNCC_FRAME_RECV, p_m_g_callref);
196 send_and_free_mncc(p_m_g_lcr_gsm, frame->msg_type, frame);
197 p_m_g_tch_connected = 1;
202 * handles all indications
204 /* SETUP INDICATION */
205 void Pgsm_bs::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
208 class Endpoint *epoint;
209 struct lcr_msg *message;
211 struct gsm_mncc *mode, *proceeding, *frame;
213 /* process given callref */
214 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_IND, DIRECTION_IN);
215 add_trace("callref", "new", "0x%x", callref);
217 /* release in case the ID is already in use */
218 add_trace("error", NULL, "callref already in use");
220 mncc = create_mncc(MNCC_REJ_REQ, callref);
221 gsm_trace_header(p_m_mISDNport, this, MNCC_REJ_REQ, DIRECTION_OUT);
222 mncc->fields |= MNCC_F_CAUSE;
223 mncc->cause.coding = 3;
224 mncc->cause.location = 1;
225 mncc->cause.value = 47;
226 add_trace("cause", "coding", "%d", mncc->cause.coding);
227 add_trace("cause", "location", "%d", mncc->cause.location);
228 add_trace("cause", "value", "%d", mncc->cause.value);
229 add_trace("reason", NULL, "callref already in use");
231 send_and_free_mncc(p_m_g_lcr_gsm, mncc->msg_type, mncc);
232 new_state(PORT_STATE_RELEASE);
233 trigger_work(&p_m_g_delete);
236 p_m_g_callref = callref;
239 /* if blocked, release call with MT_RELEASE_COMPLETE */
240 if (p_m_mISDNport->ifport->block) {
241 mncc = create_mncc(MNCC_REJ_REQ, p_m_g_callref);
242 gsm_trace_header(p_m_mISDNport, this, MNCC_REJ_REQ, DIRECTION_OUT);
243 mncc->fields |= MNCC_F_CAUSE;
244 mncc->cause.coding = 3;
245 mncc->cause.location = 1;
246 mncc->cause.value = 27;
247 add_trace("cause", "coding", "%d", mncc->cause.coding);
248 add_trace("cause", "location", "%d", mncc->cause.location);
249 add_trace("cause", "value", "%d", mncc->cause.value);
250 add_trace("reason", NULL, "port is blocked");
252 send_and_free_mncc(p_m_g_lcr_gsm, mncc->msg_type, mncc);
253 new_state(PORT_STATE_RELEASE);
254 trigger_work(&p_m_g_delete);
260 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
262 p_callerinfo.present = INFO_PRESENT_ALLOWED;
263 if (mncc->calling.number[0])
264 SCPY(p_callerinfo.id, mncc->calling.number);
266 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
267 SCPY(p_callerinfo.imsi, mncc->imsi);
268 p_callerinfo.screen = INFO_SCREEN_NETWORK;
269 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
270 p_callerinfo.isdn_port = p_m_portnum;
271 SCPY(p_callerinfo.interface, p_m_mISDNport->ifport->interface->name);
273 /* dialing information */
274 SCAT(p_dialinginfo.id, mncc->called.number);
275 switch (mncc->called.type) {
277 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
280 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
283 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
286 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
289 if (mncc->emergency) {
290 SCPY(p_dialinginfo.id, "emergency");
292 p_dialinginfo.sending_complete = 1;
294 /* bearer capability */
296 p_capainfo.bearer_capa = INFO_BC_SPEECH;
297 p_capainfo.bearer_info1 = (options.law=='a')?3:2;
298 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
299 p_capainfo.source_mode = B_MODE_TRANSPARENT;
300 p_m_g_mode = p_capainfo.source_mode;
305 ret = channel = hunt_bchannel();
310 ret = seize_bchannel(channel, 1);
313 mncc = create_mncc(MNCC_REJ_REQ, p_m_g_callref);
314 gsm_trace_header(p_m_mISDNport, this, MNCC_REJ_REQ, DIRECTION_OUT);
315 mncc->fields |= MNCC_F_CAUSE;
316 mncc->cause.coding = 3;
317 mncc->cause.location = 1;
318 mncc->cause.value = 34;
319 add_trace("cause", "coding", "%d", mncc->cause.coding);
320 add_trace("cause", "location", "%d", mncc->cause.location);
321 add_trace("cause", "value", "%d", mncc->cause.value);
322 add_trace("reason", NULL, "no channel");
324 send_and_free_mncc(p_m_g_lcr_gsm, mncc->msg_type, mncc);
325 new_state(PORT_STATE_RELEASE);
326 trigger_work(&p_m_g_delete);
329 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
330 if (bchannel_open(p_m_b_index))
333 /* what infos did we got ... */
334 gsm_trace_header(p_m_mISDNport, this, msg_type, DIRECTION_IN);
335 if (p_callerinfo.id[0])
336 add_trace("calling", "number", "%s", p_callerinfo.id);
338 SPRINT(p_callerinfo.id, "imsi-%s", p_callerinfo.imsi);
339 add_trace("calling", "imsi", "%s", p_callerinfo.imsi);
340 add_trace("dialing", "number", "%s", p_dialinginfo.id);
343 /* create endpoint */
345 FATAL("Incoming call but already got an endpoint.\n");
346 if (!(epoint = new Endpoint(p_serial, 0)))
347 FATAL("No memory for Endpoint instance\n");
348 if (!(epoint->ep_app = new DEFAULT_ENDPOINT_APP(epoint, 0))) //incoming
349 FATAL("No memory for Endpoint Application instance\n");
350 epointlist_new(epoint->ep_serial);
352 /* modify lchan to GSM codec V1 */
353 gsm_trace_header(p_m_mISDNport, this, MNCC_LCHAN_MODIFY, DIRECTION_OUT);
354 mode = create_mncc(MNCC_LCHAN_MODIFY, p_m_g_callref);
355 mode->lchan_mode = 0x01; /* GSM V1 */
356 mode->lchan_type = 0x02;
357 add_trace("mode", NULL, "0x%02x", mode->lchan_mode);
359 send_and_free_mncc(p_m_g_lcr_gsm, mode->msg_type, mode);
361 /* send call proceeding */
362 gsm_trace_header(p_m_mISDNport, this, MNCC_CALL_PROC_REQ, DIRECTION_OUT);
363 proceeding = create_mncc(MNCC_CALL_PROC_REQ, p_m_g_callref);
364 if (p_m_mISDNport->tones) {
365 proceeding->fields |= MNCC_F_PROGRESS;
366 proceeding->progress.coding = 3; /* GSM */
367 proceeding->progress.location = 1;
368 proceeding->progress.descr = 8;
369 add_trace("progress", "coding", "%d", proceeding->progress.coding);
370 add_trace("progress", "location", "%d", proceeding->progress.location);
371 add_trace("progress", "descr", "%d", proceeding->progress.descr);
374 send_and_free_mncc(p_m_g_lcr_gsm, proceeding->msg_type, proceeding);
376 new_state(PORT_STATE_IN_PROCEEDING);
378 if (p_m_mISDNport->tones && !p_m_g_tch_connected) { /* only if ... */
379 gsm_trace_header(p_m_mISDNport, this, MNCC_FRAME_RECV, DIRECTION_OUT);
381 frame = create_mncc(MNCC_FRAME_RECV, p_m_g_callref);
382 send_and_free_mncc(p_m_g_lcr_gsm, frame->msg_type, frame);
383 p_m_g_tch_connected = 1;
386 /* send setup message to endpoit */
387 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
388 message->param.setup.isdn_port = p_m_portnum;
389 message->param.setup.port_type = p_type;
390 // message->param.setup.dtmf = 0;
391 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
392 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
393 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
394 SCPY((char *)message->param.setup.useruser.data, (char *)mncc->useruser.info);
395 message->param.setup.useruser.len = strlen(mncc->useruser.info);
396 message->param.setup.useruser.protocol = mncc->useruser.proto;
397 message_put(message);
401 * BSC sends message to port
403 int message_bsc(struct lcr_gsm *lcr_gsm, int msg_type, void *arg)
405 struct gsm_mncc *mncc = (struct gsm_mncc *)arg;
406 unsigned int callref = mncc->callref;
408 class Pgsm_bs *pgsm_bs = NULL;
410 struct mISDNport *mISDNport;
412 /* Special messages */
417 callref = mncc->callref;
420 if ((port->p_type & PORT_CLASS_GSM_MASK) == PORT_CLASS_GSM_BS) {
421 pgsm_bs = (class Pgsm_bs *)port;
422 if (pgsm_bs->p_m_g_callref == callref) {
429 if (msg_type == GSM_TCHF_FRAME) {
431 /* inject DTMF, if enabled */
432 if (pgsm_bs->p_m_g_dtmf) {
433 unsigned char data[160];
436 for (i = 0; i < 160; i++) {
437 data[i] = pgsm_bs->p_m_g_dtmf[pgsm_bs->p_m_g_dtmf_index++];
438 if (pgsm_bs->p_m_g_dtmf_index == 8000)
439 pgsm_bs->p_m_g_dtmf_index = 0;
442 pgsm_bs->bchannel_send(PH_DATA_REQ, 0, data, 160);
444 pgsm_bs->frame_receive(arg);
450 if (msg_type != MNCC_SETUP_IND)
453 mISDNport = mISDNport_first;
455 if (mISDNport->gsm_bs)
457 mISDNport = mISDNport->next;
460 struct gsm_mncc *rej;
462 rej = create_mncc(MNCC_REJ_REQ, callref);
463 rej->fields |= MNCC_F_CAUSE;
464 rej->cause.coding = 3;
465 rej->cause.location = 1;
466 rej->cause.value = 27;
467 gsm_trace_header(NULL, NULL, MNCC_REJ_REQ, DIRECTION_OUT);
468 add_trace("cause", "coding", "%d", rej->cause.coding);
469 add_trace("cause", "location", "%d", rej->cause.location);
470 add_trace("cause", "value", "%d", rej->cause.value);
472 send_and_free_mncc(lcr_gsm, rej->msg_type, rej);
475 /* creating port object, transparent until setup with hdlc */
476 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
477 if (!(pgsm_bs = new Pgsm_bs(PORT_TYPE_GSM_BS_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
479 FATAL("Cannot create Port instance.\n");
484 pgsm_bs->setup_ind(msg_type, callref, mncc);
487 case MNCC_START_DTMF_IND:
488 pgsm_bs->start_dtmf_ind(msg_type, callref, mncc);
491 case MNCC_STOP_DTMF_IND:
492 pgsm_bs->stop_dtmf_ind(msg_type, callref, mncc);
495 case MNCC_CALL_CONF_IND:
496 pgsm_bs->call_conf_ind(msg_type, callref, mncc);
500 pgsm_bs->alert_ind(msg_type, callref, mncc);
504 pgsm_bs->setup_cnf(msg_type, callref, mncc);
507 case MNCC_SETUP_COMPL_IND:
508 pgsm_bs->setup_compl_ind(msg_type, callref, mncc);
512 pgsm_bs->disc_ind(msg_type, callref, mncc);
518 pgsm_bs->rel_ind(msg_type, callref, mncc);
521 case MNCC_NOTIFY_IND:
522 pgsm_bs->notify_ind(msg_type, callref, mncc);
526 pgsm_bs->hold_ind(msg_type, callref, mncc);
529 case MNCC_RETRIEVE_IND:
530 pgsm_bs->retr_ind(msg_type, callref, mncc);
534 PDEBUG(DEBUG_GSM, "Pgsm_bs(%s) gsm port with (caller id %s) received unhandled nessage: 0x%x\n", pgsm_bs->p_name, pgsm_bs->p_callerinfo.id, msg_type);
540 void Pgsm_bs::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
542 struct lcr_msg *message;
544 struct epoint_list *epointlist;
545 struct gsm_mncc *mncc;
548 /* copy setup infos to port */
549 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
550 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
551 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
552 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
554 /* no GSM MNCC connection */
555 if (p_m_g_lcr_gsm->mncc_lfd.fd < 0) {
556 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
557 add_trace("failure", NULL, "No MNCC connection.");
559 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
560 message->param.disconnectinfo.cause = 41; // temp. failure.
561 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
562 message_put(message);
563 new_state(PORT_STATE_RELEASE);
564 trigger_work(&p_m_g_delete);
569 if (!p_dialinginfo.id[0]) {
570 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
571 add_trace("failure", NULL, "No dialed subscriber given.");
573 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
574 message->param.disconnectinfo.cause = 28;
575 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
576 message_put(message);
577 new_state(PORT_STATE_RELEASE);
578 trigger_work(&p_m_g_delete);
582 /* release if port is blocked */
583 if (p_m_mISDNport->ifport->block) {
584 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
585 add_trace("failure", NULL, "Port blocked.");
587 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
588 message->param.disconnectinfo.cause = 27; // temp. unavail.
589 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
590 message_put(message);
591 new_state(PORT_STATE_RELEASE);
592 trigger_work(&p_m_g_delete);
597 ret = channel = hunt_bchannel();
601 ret = seize_bchannel(channel, 1);
604 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
605 add_trace("failure", NULL, "No internal audio channel available.");
607 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
608 message->param.disconnectinfo.cause = 34;
609 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
610 message_put(message);
611 new_state(PORT_STATE_RELEASE);
612 trigger_work(&p_m_g_delete);
615 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
616 if (bchannel_open(p_m_b_index))
619 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
620 /* screen outgoing caller id */
621 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_m_mISDNport->ifport->interface);
623 /* attach only if not already */
624 epointlist = p_epointlist;
626 if (epointlist->epoint_id == epoint_id)
628 epointlist = epointlist->next;
631 epointlist_new(epoint_id);
634 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_REQ, DIRECTION_OUT);
635 p_m_g_callref = new_callref++;
636 add_trace("callref", "new", "0x%x", p_m_g_callref);
639 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
640 mncc = create_mncc(MNCC_SETUP_REQ, p_m_g_callref);
641 /* caller information */
642 mncc->fields |= MNCC_F_CALLING;
643 mncc->calling.plan = 1;
644 switch (p_callerinfo.ntype) {
645 case INFO_NTYPE_UNKNOWN:
646 mncc->calling.type = 0x0;
648 case INFO_NTYPE_INTERNATIONAL:
649 mncc->calling.type = 0x1;
651 case INFO_NTYPE_NATIONAL:
652 mncc->calling.type = 0x2;
654 case INFO_NTYPE_SUBSCRIBER:
655 mncc->calling.type = 0x4;
657 default: /* INFO_NTYPE_NOTPRESENT */
658 mncc->fields &= ~MNCC_F_CALLING;
661 switch (p_callerinfo.screen) {
662 case INFO_SCREEN_USER:
663 mncc->calling.screen = 0;
665 default: /* INFO_SCREEN_NETWORK */
666 mncc->calling.screen = 3;
669 switch (p_callerinfo.present) {
670 case INFO_PRESENT_ALLOWED:
671 mncc->calling.present = 0;
673 case INFO_PRESENT_RESTRICTED:
674 mncc->calling.present = 1;
676 default: /* INFO_PRESENT_NOTAVAIL */
677 mncc->calling.present = 2;
680 if (mncc->fields & MNCC_F_CALLING) {
681 SCPY(mncc->calling.number, p_callerinfo.id);
682 add_trace("calling", "type", "%d", mncc->calling.type);
683 add_trace("calling", "plan", "%d", mncc->calling.plan);
684 add_trace("calling", "present", "%d", mncc->calling.present);
685 add_trace("calling", "screen", "%d", mncc->calling.screen);
686 add_trace("calling", "number", "%s", mncc->calling.number);
688 /* dialing information */
689 mncc->fields |= MNCC_F_CALLED;
690 if (!strncmp(p_dialinginfo.id, "imsi-", 5)) {
691 SCPY(mncc->imsi, p_dialinginfo.id+5);
692 add_trace("dialing", "imsi", "%s", mncc->imsi);
694 SCPY(mncc->called.number, p_dialinginfo.id);
695 add_trace("dialing", "number", "%s", mncc->called.number);
698 /* sending user-user */
700 /* redirecting number */
701 mncc->fields |= MNCC_F_REDIRECTING;
702 mncc->redirecting.plan = 1;
703 switch (p_redirinfo.ntype) {
704 case INFO_NTYPE_UNKNOWN:
705 mncc->redirecting.type = 0x0;
707 case INFO_NTYPE_INTERNATIONAL:
708 mncc->redirecting.type = 0x1;
710 case INFO_NTYPE_NATIONAL:
711 mncc->redirecting.type = 0x2;
713 case INFO_NTYPE_SUBSCRIBER:
714 mncc->redirecting.type = 0x4;
716 default: /* INFO_NTYPE_NOTPRESENT */
717 mncc->fields &= ~MNCC_F_REDIRECTING;
720 switch (p_redirinfo.screen) {
721 case INFO_SCREEN_USER:
722 mncc->redirecting.screen = 0;
724 default: /* INFO_SCREE_NETWORK */
725 mncc->redirecting.screen = 3;
728 switch (p_redirinfo.present) {
729 case INFO_PRESENT_ALLOWED:
730 mncc->redirecting.present = 0;
732 case INFO_PRESENT_RESTRICTED:
733 mncc->redirecting.present = 1;
735 default: /* INFO_PRESENT_NOTAVAIL */
736 mncc->redirecting.present = 2;
739 /* sending redirecting number only in ntmode */
740 if (mncc->fields & MNCC_F_REDIRECTING) {
741 SCPY(mncc->redirecting.number, p_redirinfo.id);
742 add_trace("redir", "type", "%d", mncc->redirecting.type);
743 add_trace("redir", "plan", "%d", mncc->redirecting.plan);
744 add_trace("redir", "present", "%d", mncc->redirecting.present);
745 add_trace("redir", "screen", "%d", mncc->redirecting.screen);
746 add_trace("redir", "number", "%s", mncc->redirecting.number);
748 /* bearer capability */
752 send_and_free_mncc(p_m_g_lcr_gsm, mncc->msg_type, mncc);
754 new_state(PORT_STATE_OUT_SETUP);
756 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
757 message_put(message);
759 new_state(PORT_STATE_OUT_PROCEEDING);
763 * endpoint sends messages to the port
765 int Pgsm_bs::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
767 if (Pgsm::message_epoint(epoint_id, message_id, param))
771 case MESSAGE_SETUP: /* dial-out command received from epoint */
772 if (p_state!=PORT_STATE_IDLE)
774 message_setup(epoint_id, message_id, param);
778 PDEBUG(DEBUG_GSM, "Pgsm_bs(%s) gsm port with (caller id %s) received unhandled nessage: %d\n", p_name, p_callerinfo.id, message_id);
784 int gsm_bs_exit(int rc)
786 /* free gsm instance */
788 if (gsm_bs->mncc_lfd.fd > -1) {
789 close(gsm_bs->mncc_lfd.fd);
790 unregister_fd(&gsm_bs->mncc_lfd);
793 del_timer(&gsm_bs->socket_retry);
802 int gsm_bs_init(void)
804 /* create gsm instance */
805 gsm_bs = (struct lcr_gsm *)MALLOC(sizeof(struct lcr_gsm));
807 gsm_bs->type = LCR_GSM_TYPE_NETWORK;
808 gsm_bs->sun.sun_family = AF_UNIX;
809 SCPY(gsm_bs->sun.sun_path, "/tmp/bsc_mncc");
811 memset(&gsm_bs->socket_retry, 0, sizeof(gsm_bs->socket_retry));
812 add_timer(&gsm_bs->socket_retry, mncc_socket_retry_cb, gsm_bs, 0);
814 /* do the initial connect */
815 mncc_socket_retry_cb(&gsm_bs->socket_retry, gsm_bs, 0);