1 /*****************************************************************************\
5 **---------------------------------------------------------------------------**
6 ** Copyright: Andreas Eversberg **
8 ** mISDN gsm (BS mode) **
10 \*****************************************************************************/
15 struct lcr_gsm *gsm_bs = NULL;
17 #define PAYLOAD_TYPE_GSM 3
22 unsigned char dtmf_samples[16][8000];
23 static int dtmf_x[4] = { 1209, 1336, 1477, 1633 };
24 static int dtmf_y[4] = { 697, 770, 852, 941 };
26 void generate_dtmf(void)
28 double fx, fy, sample;
32 for (y = 0; y < 4; y++) {
33 fy = 2 * 3.1415927 * ((double)dtmf_y[y]) / 8000.0;
34 for (x = 0; x < 4; x++) {
35 fx = 2 * 3.1415927 * ((double)dtmf_x[x]) / 8000.0;
36 law = dtmf_samples[y << 2 | x];
37 for (i = 0; i < 8000; i++) {
38 sample = sin(fy * ((double)i)) * 0.251 * 32767.0; /* -6 dB */
39 sample += sin(fx * ((double)i)) * 0.158 * 32767.0; /* -8 dB */
40 *law++ = audio_s16_to_law[(int)sample & 0xffff];
50 Pgsm_bs::Pgsm_bs(int type, char *portname, struct port_settings *settings, struct interface *interface) : Pgsm(type, portname, settings, interface)
56 PDEBUG(DEBUG_GSM, "Created new GSMBSPort(%s).\n", portname);
64 PDEBUG(DEBUG_GSM, "Destroyed GSM BS process(%s).\n", p_name);
67 static const char *media_type2name(unsigned char media_type) {
75 case MEDIA_TYPE_GSM_HR:
77 case MEDIA_TYPE_GSM_EFR:
86 /* PROCEEDING INDICATION (from MS) */
87 void Pgsm_bs::call_conf_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
90 unsigned char payload_types[8];
93 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
94 if (mncc->fields & MNCC_F_CAUSE) {
95 add_trace("cause", "coding", "%d", mncc->cause.coding);
96 add_trace("cause", "location", "%", mncc->cause.location);
97 add_trace("cause", "value", "%", mncc->cause.value);
101 new_state(PORT_STATE_OUT_PROCEEDING);
103 /* get list of offered payload types
104 * if list ist empty, the FR V1 is selected */
105 select_payload_type(mncc, payload_types, media_types, &payloads, sizeof(payload_types));
106 /* if no given payload type is supported, we select from channel type */
108 switch (mncc->lchan_type) {
109 case GSM_LCHAN_TCH_F:
110 media_types[0] = MEDIA_TYPE_GSM;
111 payload_types[0] = PAYLOAD_TYPE_GSM;
114 case GSM_LCHAN_TCH_H:
115 media_types[0] = MEDIA_TYPE_GSM_HR;
116 payload_types[0] = 96; /* dynamic */
120 mncc = create_mncc(MNCC_REL_REQ, callref);
121 gsm_trace_header(p_interface_name, this, MNCC_REL_REQ, DIRECTION_OUT);
122 mncc->fields |= MNCC_F_CAUSE;
123 mncc->cause.coding = 3;
124 mncc->cause.location = 1;
125 mncc->cause.value = 65;
126 add_trace("cause", "coding", "%d", mncc->cause.coding);
127 add_trace("cause", "location", "%d", mncc->cause.location);
128 add_trace("cause", "value", "%d", mncc->cause.value);
129 add_trace("reason", NULL, "Given lchan not supported");
131 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
132 new_state(PORT_STATE_RELEASE);
133 trigger_work(&p_g_delete);
138 /* select first payload type that matches the rtp list */
139 if (p_g_rtp_bridge) {
142 for (i = 0; i < p_g_rtp_payloads; i++) {
143 for (j = 0; j < payloads; j++) {
144 if (p_g_rtp_media_types[i] == media_types[j])
150 if (i == p_g_rtp_payloads) {
151 struct lcr_msg *message;
153 /* payload offered by remote RTP is not supported */
154 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
155 message->param.disconnectinfo.cause = 65;
156 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
157 message_put(message);
159 mncc = create_mncc(MNCC_REL_REQ, p_g_callref);
160 gsm_trace_header(p_interface_name, this, MNCC_REL_REQ, DIRECTION_OUT);
161 mncc->fields |= MNCC_F_CAUSE;
162 mncc->cause.coding = 3;
163 mncc->cause.location = LOCATION_PRIVATE_LOCAL;
164 mncc->cause.value = 65;
165 add_trace("cause", "coding", "%d", mncc->cause.coding);
166 add_trace("cause", "location", "%d", mncc->cause.location);
167 add_trace("cause", "value", "%d", mncc->cause.value);
168 add_trace("reason", NULL, "None of the payload types are supported by MS");
170 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
171 new_state(PORT_STATE_RELEASE);
172 trigger_work(&p_g_delete);
176 modify_lchan(p_g_rtp_media_types[i]);
177 /* use the payload type from received rtp list, not from locally generated payload types */
178 p_g_payload_type = p_g_rtp_payload_types[i];
180 /* modify to first given payload */
181 modify_lchan(media_types[0]);
182 p_g_payload_type = payload_types[0];
186 /* DTMF INDICATION */
187 void Pgsm_bs::start_dtmf_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
189 struct gsm_mncc *resp;
191 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
192 add_trace("keypad", NULL, "%c", mncc->keypad);
194 SPRINT(p_dialinginfo.id, "%c", mncc->keypad);
195 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
198 gsm_trace_header(p_interface_name, this, MNCC_START_DTMF_RSP, DIRECTION_OUT);
199 add_trace("keypad", NULL, "%c", mncc->keypad);
201 resp = create_mncc(MNCC_START_DTMF_RSP, p_g_callref);
202 resp->fields |= MNCC_F_KEYPAD;
203 resp->keypad = mncc->keypad;
204 send_and_free_mncc(p_g_lcr_gsm, resp->msg_type, resp);
206 if (p_g_rtp_bridge) {
207 /* if two members are bridged */
208 if (p_bridge && p_bridge->first && p_bridge->first->next && !p_bridge->first->next->next) {
209 class Port *remote = NULL;
211 /* select other member */
212 if (p_bridge->first->port == this)
213 remote = p_bridge->first->next->port;
214 if (p_bridge->first->next->port == this)
215 remote = p_bridge->first->port;
218 struct lcr_msg *message;
220 /* send dtmf information, because we bridge RTP directly */
221 message = message_create(0, remote->p_serial, EPOINT_TO_PORT, MESSAGE_DTMF);
222 message->param.dtmf = mncc->keypad;
223 message_put(message);
227 /* generate DTMF tones, since we do audio forwarding inside LCR */
228 switch (mncc->keypad) {
229 case '1': p_g_dtmf = dtmf_samples[0]; break;
230 case '2': p_g_dtmf = dtmf_samples[1]; break;
231 case '3': p_g_dtmf = dtmf_samples[2]; break;
233 case 'A': p_g_dtmf = dtmf_samples[3]; break;
234 case '4': p_g_dtmf = dtmf_samples[4]; break;
235 case '5': p_g_dtmf = dtmf_samples[5]; break;
236 case '6': p_g_dtmf = dtmf_samples[6]; break;
238 case 'B': p_g_dtmf = dtmf_samples[7]; break;
239 case '7': p_g_dtmf = dtmf_samples[8]; break;
240 case '8': p_g_dtmf = dtmf_samples[9]; break;
241 case '9': p_g_dtmf = dtmf_samples[10]; break;
243 case 'C': p_g_dtmf = dtmf_samples[11]; break;
244 case '*': p_g_dtmf = dtmf_samples[12]; break;
245 case '0': p_g_dtmf = dtmf_samples[13]; break;
246 case '#': p_g_dtmf = dtmf_samples[14]; break;
248 case 'D': p_g_dtmf = dtmf_samples[15]; break;
253 void Pgsm_bs::stop_dtmf_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
255 struct gsm_mncc *resp;
257 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
258 add_trace("keypad", NULL, "%c", mncc->keypad);
262 gsm_trace_header(p_interface_name, this, MNCC_STOP_DTMF_RSP, DIRECTION_OUT);
263 add_trace("keypad", NULL, "%c", mncc->keypad);
265 resp = create_mncc(MNCC_STOP_DTMF_RSP, p_g_callref);
266 resp->keypad = mncc->keypad;
267 send_and_free_mncc(p_g_lcr_gsm, resp->msg_type, resp);
273 /* HOLD INDICATION */
274 void Pgsm_bs::hold_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
276 struct lcr_msg *message;
277 struct gsm_mncc *resp, *frame;
279 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
282 /* notify the hold of call */
283 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
284 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
285 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
286 message_put(message);
288 /* acknowledge hold */
289 gsm_trace_header(p_interface_name, this, MNCC_HOLD_CNF, DIRECTION_OUT);
291 resp = create_mncc(MNCC_HOLD_CNF, p_g_callref);
292 send_and_free_mncc(p_g_lcr_gsm, resp->msg_type, resp);
295 if (p_g_tch_connected) { /* it should be true */
296 gsm_trace_header(p_interface_name, this, MNCC_FRAME_DROP, DIRECTION_OUT);
298 frame = create_mncc(MNCC_FRAME_DROP, p_g_callref);
299 send_and_free_mncc(p_g_lcr_gsm, frame->msg_type, frame);
300 p_g_tch_connected = 0;
305 /* RETRIEVE INDICATION */
306 void Pgsm_bs::retr_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
308 struct lcr_msg *message;
309 struct gsm_mncc *resp, *frame;
311 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
314 /* notify the retrieve of call */
315 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
316 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
317 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
318 message_put(message);
320 /* acknowledge retr */
321 gsm_trace_header(p_interface_name, this, MNCC_RETRIEVE_CNF, DIRECTION_OUT);
323 resp = create_mncc(MNCC_RETRIEVE_CNF, p_g_callref);
324 send_and_free_mncc(p_g_lcr_gsm, resp->msg_type, resp);
327 if (!p_g_tch_connected) { /* it should be true */
328 gsm_trace_header(p_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
330 frame = create_mncc(MNCC_FRAME_RECV, p_g_callref);
331 send_and_free_mncc(p_g_lcr_gsm, frame->msg_type, frame);
332 p_g_tch_connected = 1;
337 * select payload type by given list or GSM V1 FR
338 * return the payload type or 0 if not given
341 void Pgsm_bs::select_payload_type(struct gsm_mncc *mncc, unsigned char *payload_types, int *media_types, int *payloads, int max_payloads)
344 unsigned char payload_type;
346 void *encoder, *decoder;
350 gsm_trace_header(p_interface_name, this, 1 /* codec negotioation */, DIRECTION_NONE);
351 if ((mncc->fields & MNCC_F_BEARER_CAP)) {
352 /* select preferred payload type from list */
354 unsigned char dynamic_type = 96;
356 add_trace("bearer", "capa", "given by MS");
357 for (i = 0; mncc->bearer_cap.speech_ver[i] >= 0; i++) {
359 /* select payload type we support */
360 switch (mncc->bearer_cap.speech_ver[i]) {
362 add_trace("speech", "version", "Full Rate given");
363 media_type = MEDIA_TYPE_GSM;
364 payload_type = PAYLOAD_TYPE_GSM;
365 encoder = p_g_fr_encoder;
366 decoder = p_g_fr_decoder;
369 add_trace("speech", "version", "EFR given");
370 media_type = MEDIA_TYPE_GSM_EFR;
371 payload_type = dynamic_type++;
372 encoder = p_g_amr_encoder;
373 decoder = p_g_amr_decoder;
376 add_trace("speech", "version", "AMR given");
377 media_type = MEDIA_TYPE_AMR;
378 payload_type = dynamic_type++;
379 encoder = p_g_amr_encoder;
380 decoder = p_g_amr_decoder;
383 add_trace("speech", "version", "Half Rate given");
384 media_type = MEDIA_TYPE_GSM_HR;
385 payload_type = dynamic_type++;
386 encoder = p_g_hr_encoder;
387 decoder = p_g_hr_decoder;
391 add_trace("speech", "version", "AMR Half Rate given");
392 media_type = MEDIA_TYPE_AMR;
393 payload_type = dynamic_type++;
394 encoder = p_g_amr_encoder;
395 decoder = p_g_amr_decoder;
399 add_trace("speech", "version", "%d given", mncc->bearer_cap.speech_ver[i]);
403 /* wen don't support it, so we check the next */
405 add_trace("speech", "ignored", "Not supported by LCR");
408 if (!half && mncc->lchan_type != GSM_LCHAN_TCH_F) {
409 add_trace("speech", "ignored", "Not TCH/F");
412 if (half && mncc->lchan_type != GSM_LCHAN_TCH_H) {
413 add_trace("speech", "ignored", "Not TCH/H");
416 if (!p_g_rtp_bridge) {
417 if (!encoder || !decoder) {
418 add_trace("speech", "ignored", "Codec not supported");
422 if (*payloads <= max_payloads) {
423 media_types[*payloads] = media_type;
424 payload_types[*payloads] = payload_type;
429 add_trace("bearer", "capa", "not given by MS");
430 add_trace("speech", "version", "Full Rate given");
431 media_types[0] = MEDIA_TYPE_GSM;
432 payload_types[0] = PAYLOAD_TYPE_GSM;
436 add_trace("error", "", "All given payload types unsupported");
441 * handles all indications
443 /* SETUP INDICATION */
444 void Pgsm_bs::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
446 class Endpoint *epoint;
447 struct lcr_msg *message;
448 struct gsm_mncc *proceeding, *frame;
449 struct interface *interface;
451 unsigned char payload_types[8];
454 interface = getinterfacebyname(p_interface_name);
456 PERROR("Cannot find interface %s.\n", p_interface_name);
460 /* process given callref */
461 gsm_trace_header(p_interface_name, this, 0, DIRECTION_IN);
462 add_trace("callref", "new", "0x%x", callref);
464 /* release in case the ID is already in use */
465 add_trace("error", NULL, "callref already in use");
467 mncc = create_mncc(MNCC_REJ_REQ, callref);
468 gsm_trace_header(p_interface_name, this, MNCC_REJ_REQ, DIRECTION_OUT);
469 mncc->fields |= MNCC_F_CAUSE;
470 mncc->cause.coding = 3;
471 mncc->cause.location = 1;
472 mncc->cause.value = 47;
473 add_trace("cause", "coding", "%d", mncc->cause.coding);
474 add_trace("cause", "location", "%d", mncc->cause.location);
475 add_trace("cause", "value", "%d", mncc->cause.value);
476 add_trace("reason", NULL, "callref already in use");
478 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
479 new_state(PORT_STATE_RELEASE);
480 trigger_work(&p_g_delete);
483 p_g_callref = callref;
488 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
490 p_callerinfo.present = INFO_PRESENT_ALLOWED;
491 if (mncc->calling.number[0])
492 SCPY(p_callerinfo.id, mncc->calling.number);
494 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
495 SCPY(p_callerinfo.imsi, mncc->imsi);
496 p_callerinfo.screen = INFO_SCREEN_NETWORK;
497 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
498 SCPY(p_callerinfo.interface, p_interface_name);
500 /* dialing information */
501 SCAT(p_dialinginfo.id, mncc->called.number);
502 switch (mncc->called.type) {
504 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
507 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
510 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
513 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
516 if (mncc->emergency) {
517 SCPY(p_dialinginfo.id, "emergency");
519 p_dialinginfo.sending_complete = 1;
521 /* bearer capability */
522 p_capainfo.bearer_capa = INFO_BC_SPEECH;
523 p_capainfo.bearer_info1 = (options.law=='a')?3:2;
524 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
525 p_capainfo.source_mode = B_MODE_TRANSPARENT;
526 p_g_mode = p_capainfo.source_mode;
528 /* get list of offered payload types
529 * if list ist empty, the FR V1 is selected */
530 select_payload_type(mncc, payload_types, media_types, &payloads, sizeof(payload_types));
531 /* if no given payload type is supported, we select from channel type */
533 switch (mncc->lchan_type) {
534 case GSM_LCHAN_TCH_F:
535 media_types[0] = MEDIA_TYPE_GSM;
536 payload_types[0] = PAYLOAD_TYPE_GSM;
539 case GSM_LCHAN_TCH_H:
540 media_types[0] = MEDIA_TYPE_GSM_HR;
541 payload_types[0] = 96; /* dynamic */
545 mncc = create_mncc(MNCC_REJ_REQ, callref);
546 gsm_trace_header(p_interface_name, this, MNCC_REJ_REQ, DIRECTION_OUT);
547 mncc->fields |= MNCC_F_CAUSE;
548 mncc->cause.coding = 3;
549 mncc->cause.location = 1;
550 mncc->cause.value = 65;
551 add_trace("cause", "coding", "%d", mncc->cause.coding);
552 add_trace("cause", "location", "%d", mncc->cause.location);
553 add_trace("cause", "value", "%d", mncc->cause.value);
554 add_trace("reason", NULL, "Given lchan not supported");
556 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
557 new_state(PORT_STATE_RELEASE);
558 trigger_work(&p_g_delete);
563 /* if no given payload type is supported, we reject the call */
570 /* what infos did we got ... */
571 gsm_trace_header(p_interface_name, this, msg_type, DIRECTION_IN);
572 if (p_callerinfo.id[0])
573 add_trace("calling", "number", "%s", p_callerinfo.id);
575 SPRINT(p_callerinfo.id, "imsi-%s", p_callerinfo.imsi);
576 add_trace("calling", "imsi", "%s", p_callerinfo.imsi);
577 add_trace("dialing", "number", "%s", p_dialinginfo.id);
580 /* create endpoint */
582 FATAL("Incoming call but already got an endpoint.\n");
583 if (!(epoint = new Endpoint(p_serial, 0)))
584 FATAL("No memory for Endpoint instance\n");
585 epoint->ep_app = new_endpointapp(epoint, 0, interface->app); //incoming
586 epointlist_new(epoint->ep_serial);
588 /* modify lchan in case of no rtp bridge */
590 modify_lchan(media_types[0]);
592 /* send call proceeding */
593 gsm_trace_header(p_interface_name, this, MNCC_CALL_PROC_REQ, DIRECTION_OUT);
594 proceeding = create_mncc(MNCC_CALL_PROC_REQ, p_g_callref);
596 proceeding->fields |= MNCC_F_PROGRESS;
597 proceeding->progress.coding = 3; /* GSM */
598 proceeding->progress.location = 1;
599 proceeding->progress.descr = 8;
600 add_trace("progress", "coding", "%d", proceeding->progress.coding);
601 add_trace("progress", "location", "%d", proceeding->progress.location);
602 add_trace("progress", "descr", "%d", proceeding->progress.descr);
605 send_and_free_mncc(p_g_lcr_gsm, proceeding->msg_type, proceeding);
607 new_state(PORT_STATE_IN_PROCEEDING);
609 if (p_g_tones && !p_g_tch_connected) { /* only if ... */
610 gsm_trace_header(p_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
612 frame = create_mncc(MNCC_FRAME_RECV, p_g_callref);
613 send_and_free_mncc(p_g_lcr_gsm, frame->msg_type, frame);
614 p_g_tch_connected = 1;
617 /* send setup message to endpoit */
618 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
619 message->param.setup.port_type = p_type;
620 // message->param.setup.dtmf = 0;
621 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
622 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
623 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
624 SCPY((char *)message->param.setup.useruser.data, (char *)mncc->useruser.info);
625 message->param.setup.useruser.len = strlen(mncc->useruser.info);
626 message->param.setup.useruser.protocol = mncc->useruser.proto;
627 if (p_g_rtp_bridge) {
628 struct gsm_mncc_rtp *rtp;
631 PDEBUG(DEBUG_GSM, "Request RTP peer info, before forwarding setup\n");
632 p_g_setup_pending = message;
633 rtp = (struct gsm_mncc_rtp *) create_mncc(MNCC_RTP_CREATE, p_g_callref);
634 send_and_free_mncc(p_g_lcr_gsm, rtp->msg_type, rtp);
636 for (i = 0; i < (int)sizeof(message->param.setup.rtpinfo.payload_types) && i < payloads; i++) {
637 message->param.setup.rtpinfo.media_types[i] = media_types[i];
638 message->param.setup.rtpinfo.payload_types[i] = payload_types[i];
639 message->param.setup.rtpinfo.payloads++;
643 message_put(message);
648 * BSC sends message to port
650 int message_bsc(struct lcr_gsm *lcr_gsm, int msg_type, void *arg)
652 struct gsm_mncc *mncc = (struct gsm_mncc *)arg;
653 unsigned int callref = mncc->callref;
655 class Pgsm_bs *pgsm_bs = NULL;
657 // struct mISDNport *mISDNport;
659 /* Special messages */
664 callref = mncc->callref;
667 if ((port->p_type & PORT_CLASS_GSM_MASK) == PORT_CLASS_GSM_BS) {
668 pgsm_bs = (class Pgsm_bs *)port;
669 if (pgsm_bs->p_g_callref == callref) {
676 if (msg_type == GSM_TCHF_FRAME
677 || msg_type == GSM_TCHF_FRAME_EFR
678 || msg_type == GSM_TCHH_FRAME
679 || msg_type == GSM_TCH_FRAME_AMR
680 || msg_type == GSM_BAD_FRAME) {
682 /* inject DTMF, if enabled */
683 if (pgsm_bs->p_g_dtmf) {
684 unsigned char data[160];
687 for (i = 0; i < 160; i++) {
688 data[i] = pgsm_bs->p_g_dtmf[pgsm_bs->p_g_dtmf_index++];
689 if (pgsm_bs->p_g_dtmf_index == 8000)
690 pgsm_bs->p_g_dtmf_index = 0;
693 pgsm_bs->bridge_tx(data, 160);
695 pgsm_bs->frame_receive(arg);
696 /* if we do not bridge we need to inject audio, if available */
697 if (!pgsm_bs->p_bridge || pgsm_bs->p_tone_name[0]) {
698 unsigned char data[160];
701 i = pgsm_bs->read_audio(data, 160);
703 pgsm_bs->audio_send(data, i);
710 struct interface *interface;
712 if (msg_type != MNCC_SETUP_IND)
715 interface = getinterfacebyname(lcr_gsm->interface_name);
717 struct gsm_mncc *rej;
719 rej = create_mncc(MNCC_REJ_REQ, callref);
720 rej->fields |= MNCC_F_CAUSE;
721 rej->cause.coding = 3;
722 rej->cause.location = 1;
723 rej->cause.value = 27;
724 gsm_trace_header(NULL, NULL, MNCC_REJ_REQ, DIRECTION_OUT);
725 add_trace("cause", "coding", "%d", rej->cause.coding);
726 add_trace("cause", "location", "%d", rej->cause.location);
727 add_trace("cause", "value", "%d", rej->cause.value);
728 add_trace("reason", NULL, "interface %s not found", lcr_gsm->interface_name);
730 send_and_free_mncc(lcr_gsm, rej->msg_type, rej);
733 /* creating port object, transparent until setup with hdlc */
734 SPRINT(name, "%s-%d-in", interface->name, 0);
735 if (!(pgsm_bs = new Pgsm_bs(PORT_TYPE_GSM_BS_IN, name, NULL, interface)))
736 FATAL("Cannot create Port instance.\n");
741 pgsm_bs->setup_ind(msg_type, callref, mncc);
744 case MNCC_RTP_CREATE:
745 pgsm_bs->rtp_create_ind(msg_type, callref, mncc);
748 case MNCC_RTP_CONNECT:
749 pgsm_bs->rtp_connect_ind(msg_type, callref, mncc);
752 case MNCC_START_DTMF_IND:
753 pgsm_bs->start_dtmf_ind(msg_type, callref, mncc);
756 case MNCC_STOP_DTMF_IND:
757 pgsm_bs->stop_dtmf_ind(msg_type, callref, mncc);
760 case MNCC_CALL_CONF_IND:
761 pgsm_bs->call_conf_ind(msg_type, callref, mncc);
765 pgsm_bs->alert_ind(msg_type, callref, mncc);
769 pgsm_bs->setup_cnf(msg_type, callref, mncc);
772 case MNCC_SETUP_COMPL_IND:
773 pgsm_bs->setup_compl_ind(msg_type, callref, mncc);
777 pgsm_bs->disc_ind(msg_type, callref, mncc);
783 pgsm_bs->rel_ind(msg_type, callref, mncc);
786 case MNCC_NOTIFY_IND:
787 pgsm_bs->notify_ind(msg_type, callref, mncc);
791 pgsm_bs->hold_ind(msg_type, callref, mncc);
794 case MNCC_RETRIEVE_IND:
795 pgsm_bs->retr_ind(msg_type, callref, mncc);
799 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);
805 void Pgsm_bs::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
807 struct lcr_msg *message;
808 struct epoint_list *epointlist;
809 struct gsm_mncc *mncc;
811 /* copy setup infos to port */
812 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
813 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
814 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
815 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
817 /* no GSM MNCC connection */
818 if (p_g_lcr_gsm->mncc_lfd.fd < 0) {
819 gsm_trace_header(p_interface_name, this, MNCC_SETUP_REQ, DIRECTION_OUT);
820 add_trace("failure", NULL, "No MNCC connection.");
822 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
823 message->param.disconnectinfo.cause = 41; // temp. failure.
824 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
825 message_put(message);
826 new_state(PORT_STATE_RELEASE);
827 trigger_work(&p_g_delete);
832 if (!p_dialinginfo.id[0]) {
833 gsm_trace_header(p_interface_name, this, MNCC_SETUP_REQ, DIRECTION_OUT);
834 add_trace("failure", NULL, "No dialed subscriber given.");
836 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
837 message->param.disconnectinfo.cause = 28;
838 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
839 message_put(message);
840 new_state(PORT_STATE_RELEASE);
841 trigger_work(&p_g_delete);
845 /* unsupported codec for RTP bridge */
846 if (param->setup.rtpinfo.port) {
849 p_g_rtp_payloads = 0;
850 gsm_trace_header(p_interface_name, this, 1 /* codec negotioation */, DIRECTION_NONE);
851 for (i = 0; i < param->setup.rtpinfo.payloads; i++) {
852 switch (param->setup.rtpinfo.media_types[i]) {
854 case MEDIA_TYPE_GSM_EFR:
856 case MEDIA_TYPE_GSM_HR:
857 add_trace("rtp", "payload", "%s:%d supported", media_type2name(param->setup.rtpinfo.media_types[i]), param->setup.rtpinfo.payload_types[i]);
858 if (p_g_rtp_payloads < (int)sizeof(p_g_rtp_payload_types)) {
859 p_g_rtp_media_types[p_g_rtp_payloads] = param->setup.rtpinfo.media_types[i];
860 p_g_rtp_payload_types[p_g_rtp_payloads] = param->setup.rtpinfo.payload_types[i];
865 add_trace("rtp", "payload", "%s:%d unsupported", media_type2name(param->setup.rtpinfo.media_types[i]), param->setup.rtpinfo.payload_types[i]);
869 if (!p_g_rtp_payloads) {
870 gsm_trace_header(p_interface_name, this, MNCC_SETUP_REQ, DIRECTION_OUT);
871 add_trace("failure", NULL, "No payload given that is supported by GSM");
873 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
874 message->param.disconnectinfo.cause = 65;
875 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
876 message_put(message);
877 new_state(PORT_STATE_RELEASE);
878 trigger_work(&p_g_delete);
883 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
884 /* screen outgoing caller id */
885 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_interface_name);
887 /* attach only if not already */
888 epointlist = p_epointlist;
890 if (epointlist->epoint_id == epoint_id)
892 epointlist = epointlist->next;
895 epointlist_new(epoint_id);
898 gsm_trace_header(p_interface_name, this, 0, DIRECTION_OUT);
899 p_g_callref = new_callref++;
900 add_trace("callref", "new", "0x%x", p_g_callref);
903 gsm_trace_header(p_interface_name, this, MNCC_SETUP_REQ, DIRECTION_OUT);
904 mncc = create_mncc(MNCC_SETUP_REQ, p_g_callref);
905 /* caller information */
906 mncc->fields |= MNCC_F_CALLING;
907 mncc->calling.plan = 1;
908 switch (p_callerinfo.ntype) {
909 case INFO_NTYPE_UNKNOWN:
910 mncc->calling.type = 0x0;
912 case INFO_NTYPE_INTERNATIONAL:
913 mncc->calling.type = 0x1;
915 case INFO_NTYPE_NATIONAL:
916 mncc->calling.type = 0x2;
918 case INFO_NTYPE_SUBSCRIBER:
919 mncc->calling.type = 0x4;
921 default: /* INFO_NTYPE_NOTPRESENT */
922 mncc->fields &= ~MNCC_F_CALLING;
925 switch (p_callerinfo.screen) {
926 case INFO_SCREEN_USER:
927 mncc->calling.screen = 0;
929 default: /* INFO_SCREEN_NETWORK */
930 mncc->calling.screen = 3;
933 switch (p_callerinfo.present) {
934 case INFO_PRESENT_ALLOWED:
935 mncc->calling.present = 0;
937 case INFO_PRESENT_RESTRICTED:
938 mncc->calling.present = 1;
940 default: /* INFO_PRESENT_NOTAVAIL */
941 mncc->calling.present = 2;
944 if (mncc->fields & MNCC_F_CALLING) {
945 SCPY(mncc->calling.number, p_callerinfo.id);
946 add_trace("calling", "type", "%d", mncc->calling.type);
947 add_trace("calling", "plan", "%d", mncc->calling.plan);
948 add_trace("calling", "present", "%d", mncc->calling.present);
949 add_trace("calling", "screen", "%d", mncc->calling.screen);
950 add_trace("calling", "number", "%s", mncc->calling.number);
952 /* dialing information */
953 mncc->fields |= MNCC_F_CALLED;
954 if (!strncmp(p_dialinginfo.id, "imsi-", 5)) {
955 SCPY(mncc->imsi, p_dialinginfo.id+5);
956 add_trace("dialing", "imsi", "%s", mncc->imsi);
958 SCPY(mncc->called.number, p_dialinginfo.id);
959 add_trace("dialing", "number", "%s", mncc->called.number);
962 /* sending user-user */
964 /* redirecting number */
965 mncc->fields |= MNCC_F_REDIRECTING;
966 mncc->redirecting.plan = 1;
967 switch (p_redirinfo.ntype) {
968 case INFO_NTYPE_UNKNOWN:
969 mncc->redirecting.type = 0x0;
971 case INFO_NTYPE_INTERNATIONAL:
972 mncc->redirecting.type = 0x1;
974 case INFO_NTYPE_NATIONAL:
975 mncc->redirecting.type = 0x2;
977 case INFO_NTYPE_SUBSCRIBER:
978 mncc->redirecting.type = 0x4;
980 default: /* INFO_NTYPE_NOTPRESENT */
981 mncc->fields &= ~MNCC_F_REDIRECTING;
984 switch (p_redirinfo.screen) {
985 case INFO_SCREEN_USER:
986 mncc->redirecting.screen = 0;
988 default: /* INFO_SCREE_NETWORK */
989 mncc->redirecting.screen = 3;
992 switch (p_redirinfo.present) {
993 case INFO_PRESENT_ALLOWED:
994 mncc->redirecting.present = 0;
996 case INFO_PRESENT_RESTRICTED:
997 mncc->redirecting.present = 1;
999 default: /* INFO_PRESENT_NOTAVAIL */
1000 mncc->redirecting.present = 2;
1003 /* sending redirecting number only in ntmode */
1004 if (mncc->fields & MNCC_F_REDIRECTING) {
1005 SCPY(mncc->redirecting.number, p_redirinfo.id);
1006 add_trace("redir", "type", "%d", mncc->redirecting.type);
1007 add_trace("redir", "plan", "%d", mncc->redirecting.plan);
1008 add_trace("redir", "present", "%d", mncc->redirecting.present);
1009 add_trace("redir", "screen", "%d", mncc->redirecting.screen);
1010 add_trace("redir", "number", "%s", mncc->redirecting.number);
1014 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
1016 new_state(PORT_STATE_OUT_SETUP);
1018 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
1019 message_put(message);
1022 if (param->setup.rtpinfo.port) {
1024 p_g_rtp_ip_remote = param->setup.rtpinfo.ip;
1025 p_g_rtp_port_remote = param->setup.rtpinfo.port;
1031 * endpoint sends messages to the port
1033 int Pgsm_bs::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
1035 if (Pgsm::message_epoint(epoint_id, message_id, param))
1038 switch(message_id) {
1039 case MESSAGE_SETUP: /* dial-out command received from epoint */
1040 if (p_state!=PORT_STATE_IDLE)
1042 message_setup(epoint_id, message_id, param);
1046 PDEBUG(DEBUG_GSM, "Pgsm_bs(%s) gsm port with (caller id %s) received unhandled nessage: %d\n", p_name, p_callerinfo.id, message_id);
1052 int gsm_bs_exit(int rc)
1054 /* free gsm instance */
1056 if (gsm_bs->mncc_lfd.fd > -1) {
1057 close(gsm_bs->mncc_lfd.fd);
1058 unregister_fd(&gsm_bs->mncc_lfd);
1061 del_timer(&gsm_bs->socket_retry);
1070 int gsm_bs_init(struct interface *interface)
1072 /* create gsm instance */
1073 gsm_bs = (struct lcr_gsm *)MALLOC(sizeof(struct lcr_gsm));
1075 SCPY(gsm_bs->interface_name, interface->name);
1076 gsm_bs->type = LCR_GSM_TYPE_NETWORK;
1077 gsm_bs->sun.sun_family = AF_UNIX;
1078 SCPY(gsm_bs->sun.sun_path, "/tmp/bsc_mncc");
1080 memset(&gsm_bs->socket_retry, 0, sizeof(gsm_bs->socket_retry));
1081 add_timer(&gsm_bs->socket_retry, mncc_socket_retry_cb, gsm_bs, 0);
1083 /* do the initial connect */
1084 mncc_socket_retry_cb(&gsm_bs->socket_retry, gsm_bs, 0);