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 add_trace("mode", NULL, "0x%02x", mode->lchan_mode);
358 send_and_free_mncc(p_m_g_lcr_gsm, mode->msg_type, mode);
360 /* send call proceeding */
361 gsm_trace_header(p_m_mISDNport, this, MNCC_CALL_PROC_REQ, DIRECTION_OUT);
362 proceeding = create_mncc(MNCC_CALL_PROC_REQ, p_m_g_callref);
363 if (p_m_mISDNport->tones) {
364 proceeding->fields |= MNCC_F_PROGRESS;
365 proceeding->progress.coding = 3; /* GSM */
366 proceeding->progress.location = 1;
367 proceeding->progress.descr = 8;
368 add_trace("progress", "coding", "%d", proceeding->progress.coding);
369 add_trace("progress", "location", "%d", proceeding->progress.location);
370 add_trace("progress", "descr", "%d", proceeding->progress.descr);
373 send_and_free_mncc(p_m_g_lcr_gsm, proceeding->msg_type, proceeding);
375 new_state(PORT_STATE_IN_PROCEEDING);
377 if (p_m_mISDNport->tones && !p_m_g_tch_connected) { /* only if ... */
378 gsm_trace_header(p_m_mISDNport, this, MNCC_FRAME_RECV, DIRECTION_OUT);
380 frame = create_mncc(MNCC_FRAME_RECV, p_m_g_callref);
381 send_and_free_mncc(p_m_g_lcr_gsm, frame->msg_type, frame);
382 p_m_g_tch_connected = 1;
385 /* send setup message to endpoit */
386 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
387 message->param.setup.isdn_port = p_m_portnum;
388 message->param.setup.port_type = p_type;
389 // message->param.setup.dtmf = 0;
390 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
391 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
392 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
393 SCPY((char *)message->param.setup.useruser.data, (char *)mncc->useruser.info);
394 message->param.setup.useruser.len = strlen(mncc->useruser.info);
395 message->param.setup.useruser.protocol = mncc->useruser.proto;
396 message_put(message);
400 * BSC sends message to port
402 int message_bsc(struct lcr_gsm *lcr_gsm, int msg_type, void *arg)
404 struct gsm_mncc *mncc = (struct gsm_mncc *)arg;
405 unsigned int callref = mncc->callref;
407 class Pgsm_bs *pgsm_bs = NULL;
409 struct mISDNport *mISDNport;
411 /* Special messages */
416 callref = mncc->callref;
419 if ((port->p_type & PORT_CLASS_GSM_MASK) == PORT_CLASS_GSM_BS) {
420 pgsm_bs = (class Pgsm_bs *)port;
421 if (pgsm_bs->p_m_g_callref == callref) {
428 if (msg_type == GSM_TCHF_FRAME) {
430 /* inject DTMF, if enabled */
431 if (pgsm_bs->p_m_g_dtmf) {
432 unsigned char data[160];
435 for (i = 0; i < 160; i++) {
436 data[i] = pgsm_bs->p_m_g_dtmf[pgsm_bs->p_m_g_dtmf_index++];
437 if (pgsm_bs->p_m_g_dtmf_index == 8000)
438 pgsm_bs->p_m_g_dtmf_index = 0;
441 pgsm_bs->bchannel_send(PH_DATA_REQ, 0, data, 160);
443 pgsm_bs->frame_receive(arg);
449 if (msg_type != MNCC_SETUP_IND)
452 mISDNport = mISDNport_first;
454 if (mISDNport->gsm_bs)
456 mISDNport = mISDNport->next;
459 struct gsm_mncc *rej;
461 rej = create_mncc(MNCC_REJ_REQ, callref);
462 rej->fields |= MNCC_F_CAUSE;
463 rej->cause.coding = 3;
464 rej->cause.location = 1;
465 rej->cause.value = 27;
466 gsm_trace_header(NULL, NULL, MNCC_REJ_REQ, DIRECTION_OUT);
467 add_trace("cause", "coding", "%d", rej->cause.coding);
468 add_trace("cause", "location", "%d", rej->cause.location);
469 add_trace("cause", "value", "%d", rej->cause.value);
471 send_and_free_mncc(lcr_gsm, rej->msg_type, rej);
474 /* creating port object, transparent until setup with hdlc */
475 SPRINT(name, "%s-%d-in", mISDNport->ifport->interface->name, mISDNport->portnum);
476 if (!(pgsm_bs = new Pgsm_bs(PORT_TYPE_GSM_BS_IN, mISDNport, name, NULL, 0, 0, B_MODE_TRANSPARENT)))
478 FATAL("Cannot create Port instance.\n");
483 pgsm_bs->setup_ind(msg_type, callref, mncc);
486 case MNCC_START_DTMF_IND:
487 pgsm_bs->start_dtmf_ind(msg_type, callref, mncc);
490 case MNCC_STOP_DTMF_IND:
491 pgsm_bs->stop_dtmf_ind(msg_type, callref, mncc);
494 case MNCC_CALL_CONF_IND:
495 pgsm_bs->call_conf_ind(msg_type, callref, mncc);
499 pgsm_bs->alert_ind(msg_type, callref, mncc);
503 pgsm_bs->setup_cnf(msg_type, callref, mncc);
506 case MNCC_SETUP_COMPL_IND:
507 pgsm_bs->setup_compl_ind(msg_type, callref, mncc);
511 pgsm_bs->disc_ind(msg_type, callref, mncc);
517 pgsm_bs->rel_ind(msg_type, callref, mncc);
520 case MNCC_NOTIFY_IND:
521 pgsm_bs->notify_ind(msg_type, callref, mncc);
525 pgsm_bs->hold_ind(msg_type, callref, mncc);
528 case MNCC_RETRIEVE_IND:
529 pgsm_bs->retr_ind(msg_type, callref, mncc);
533 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);
539 void Pgsm_bs::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
541 struct lcr_msg *message;
543 struct epoint_list *epointlist;
544 struct gsm_mncc *mncc;
547 /* copy setup infos to port */
548 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
549 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
550 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
551 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
553 /* no GSM MNCC connection */
554 if (p_m_g_lcr_gsm->mncc_lfd.fd < 0) {
555 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
556 add_trace("failure", NULL, "No MNCC connection.");
558 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
559 message->param.disconnectinfo.cause = 41; // temp. failure.
560 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
561 message_put(message);
562 new_state(PORT_STATE_RELEASE);
563 trigger_work(&p_m_g_delete);
568 if (!p_dialinginfo.id[0]) {
569 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
570 add_trace("failure", NULL, "No dialed subscriber given.");
572 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
573 message->param.disconnectinfo.cause = 28;
574 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
575 message_put(message);
576 new_state(PORT_STATE_RELEASE);
577 trigger_work(&p_m_g_delete);
581 /* release if port is blocked */
582 if (p_m_mISDNport->ifport->block) {
583 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
584 add_trace("failure", NULL, "Port blocked.");
586 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
587 message->param.disconnectinfo.cause = 27; // temp. unavail.
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);
596 ret = channel = hunt_bchannel();
600 ret = seize_bchannel(channel, 1);
603 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
604 add_trace("failure", NULL, "No internal audio channel available.");
606 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
607 message->param.disconnectinfo.cause = 34;
608 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
609 message_put(message);
610 new_state(PORT_STATE_RELEASE);
611 trigger_work(&p_m_g_delete);
614 bchannel_event(p_m_mISDNport, p_m_b_index, B_EVENT_USE);
615 if (bchannel_open(p_m_b_index))
618 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
619 /* screen outgoing caller id */
620 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_m_mISDNport->ifport->interface);
622 /* attach only if not already */
623 epointlist = p_epointlist;
625 if (epointlist->epoint_id == epoint_id)
627 epointlist = epointlist->next;
630 epointlist_new(epoint_id);
633 l1l2l3_trace_header(p_m_mISDNport, this, L3_NEW_L3ID_REQ, DIRECTION_OUT);
634 p_m_g_callref = new_callref++;
635 add_trace("callref", "new", "0x%x", p_m_g_callref);
638 gsm_trace_header(p_m_mISDNport, this, MNCC_SETUP_REQ, DIRECTION_OUT);
639 mncc = create_mncc(MNCC_SETUP_REQ, p_m_g_callref);
640 /* caller information */
641 mncc->fields |= MNCC_F_CALLING;
642 mncc->calling.plan = 1;
643 switch (p_callerinfo.ntype) {
644 case INFO_NTYPE_UNKNOWN:
645 mncc->calling.type = 0x0;
647 case INFO_NTYPE_INTERNATIONAL:
648 mncc->calling.type = 0x1;
650 case INFO_NTYPE_NATIONAL:
651 mncc->calling.type = 0x2;
653 case INFO_NTYPE_SUBSCRIBER:
654 mncc->calling.type = 0x4;
656 default: /* INFO_NTYPE_NOTPRESENT */
657 mncc->fields &= ~MNCC_F_CALLING;
660 switch (p_callerinfo.screen) {
661 case INFO_SCREEN_USER:
662 mncc->calling.screen = 0;
664 default: /* INFO_SCREEN_NETWORK */
665 mncc->calling.screen = 3;
668 switch (p_callerinfo.present) {
669 case INFO_PRESENT_ALLOWED:
670 mncc->calling.present = 0;
672 case INFO_PRESENT_RESTRICTED:
673 mncc->calling.present = 1;
675 default: /* INFO_PRESENT_NOTAVAIL */
676 mncc->calling.present = 2;
679 if (mncc->fields & MNCC_F_CALLING) {
680 SCPY(mncc->calling.number, p_callerinfo.id);
681 add_trace("calling", "type", "%d", mncc->calling.type);
682 add_trace("calling", "plan", "%d", mncc->calling.plan);
683 add_trace("calling", "present", "%d", mncc->calling.present);
684 add_trace("calling", "screen", "%d", mncc->calling.screen);
685 add_trace("calling", "number", "%s", mncc->calling.number);
687 /* dialing information */
688 mncc->fields |= MNCC_F_CALLED;
689 if (!strncmp(p_dialinginfo.id, "imsi-", 5)) {
690 SCPY(mncc->imsi, p_dialinginfo.id+5);
691 add_trace("dialing", "imsi", "%s", mncc->imsi);
693 SCPY(mncc->called.number, p_dialinginfo.id);
694 add_trace("dialing", "number", "%s", mncc->called.number);
697 /* sending user-user */
699 /* redirecting number */
700 mncc->fields |= MNCC_F_REDIRECTING;
701 mncc->redirecting.plan = 1;
702 switch (p_redirinfo.ntype) {
703 case INFO_NTYPE_UNKNOWN:
704 mncc->redirecting.type = 0x0;
706 case INFO_NTYPE_INTERNATIONAL:
707 mncc->redirecting.type = 0x1;
709 case INFO_NTYPE_NATIONAL:
710 mncc->redirecting.type = 0x2;
712 case INFO_NTYPE_SUBSCRIBER:
713 mncc->redirecting.type = 0x4;
715 default: /* INFO_NTYPE_NOTPRESENT */
716 mncc->fields &= ~MNCC_F_REDIRECTING;
719 switch (p_redirinfo.screen) {
720 case INFO_SCREEN_USER:
721 mncc->redirecting.screen = 0;
723 default: /* INFO_SCREE_NETWORK */
724 mncc->redirecting.screen = 3;
727 switch (p_redirinfo.present) {
728 case INFO_PRESENT_ALLOWED:
729 mncc->redirecting.present = 0;
731 case INFO_PRESENT_RESTRICTED:
732 mncc->redirecting.present = 1;
734 default: /* INFO_PRESENT_NOTAVAIL */
735 mncc->redirecting.present = 2;
738 /* sending redirecting number only in ntmode */
739 if (mncc->fields & MNCC_F_REDIRECTING) {
740 SCPY(mncc->redirecting.number, p_redirinfo.id);
741 add_trace("redir", "type", "%d", mncc->redirecting.type);
742 add_trace("redir", "plan", "%d", mncc->redirecting.plan);
743 add_trace("redir", "present", "%d", mncc->redirecting.present);
744 add_trace("redir", "screen", "%d", mncc->redirecting.screen);
745 add_trace("redir", "number", "%s", mncc->redirecting.number);
747 /* bearer capability */
751 send_and_free_mncc(p_m_g_lcr_gsm, mncc->msg_type, mncc);
753 new_state(PORT_STATE_OUT_SETUP);
755 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
756 message_put(message);
758 new_state(PORT_STATE_OUT_PROCEEDING);
762 * endpoint sends messages to the port
764 int Pgsm_bs::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
766 if (Pgsm::message_epoint(epoint_id, message_id, param))
770 case MESSAGE_SETUP: /* dial-out command received from epoint */
771 if (p_state!=PORT_STATE_IDLE)
773 message_setup(epoint_id, message_id, param);
777 PDEBUG(DEBUG_GSM, "Pgsm_bs(%s) gsm port with (caller id %s) received unhandled nessage: %d\n", p_name, p_callerinfo.id, message_id);
783 int gsm_bs_exit(int rc)
785 /* free gsm instance */
787 if (gsm_bs->mncc_lfd.fd > -1) {
788 close(gsm_bs->mncc_lfd.fd);
789 unregister_fd(&gsm_bs->mncc_lfd);
792 del_timer(&gsm_bs->socket_retry);
801 int gsm_bs_init(void)
803 /* create gsm instance */
804 gsm_bs = (struct lcr_gsm *)MALLOC(sizeof(struct lcr_gsm));
806 gsm_bs->type = LCR_GSM_TYPE_NETWORK;
807 gsm_bs->sun.sun_family = AF_UNIX;
808 SCPY(gsm_bs->sun.sun_path, "/tmp/bsc_mncc");
810 memset(&gsm_bs->socket_retry, 0, sizeof(gsm_bs->socket_retry));
811 add_timer(&gsm_bs->socket_retry, mncc_socket_retry_cb, gsm_bs, 0);
813 /* do the initial connect */
814 mncc_socket_retry_cb(&gsm_bs->socket_retry, gsm_bs, 0);