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 /* PROCEEDING INDICATION (from MS) */
68 void Pgsm_bs::call_conf_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
71 unsigned char payload_types[8];
74 gsm_trace_header(p_g_interface_name, this, msg_type, DIRECTION_IN);
75 if (mncc->fields & MNCC_F_CAUSE) {
76 add_trace("cause", "coding", "%d", mncc->cause.coding);
77 add_trace("cause", "location", "%", mncc->cause.location);
78 add_trace("cause", "value", "%", mncc->cause.value);
82 new_state(PORT_STATE_OUT_PROCEEDING);
84 /* get list of offered payload types
85 * if list ist empty, the FR V1 is selected */
86 select_payload_type(mncc, payload_types, media_types, &payloads, sizeof(payload_types));
87 /* if no given payload type is supported, we assume */
89 media_types[0] = MEDIA_TYPE_GSM;
90 payload_types[0] = PAYLOAD_TYPE_GSM;
94 /* select first payload type that matches the rtp list */
98 for (i = 0; i < p_g_rtp_payloads; i++) {
99 for (j = 0; j < payloads; j++) {
100 if (p_g_rtp_media_types[i] == media_types[j])
106 if (i == p_g_rtp_payloads) {
107 struct lcr_msg *message;
109 /* payload offered by remote RTP is not supported */
110 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_RELEASE);
111 message->param.disconnectinfo.cause = 65;
112 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
113 message_put(message);
115 mncc = create_mncc(MNCC_REL_REQ, p_g_callref);
116 gsm_trace_header(p_g_interface_name, this, MNCC_REL_REQ, DIRECTION_OUT);
117 mncc->fields |= MNCC_F_CAUSE;
118 mncc->cause.coding = 3;
119 mncc->cause.location = LOCATION_PRIVATE_LOCAL;
120 mncc->cause.value = 65;
121 add_trace("cause", "coding", "%d", mncc->cause.coding);
122 add_trace("cause", "location", "%d", mncc->cause.location);
123 add_trace("cause", "value", "%d", mncc->cause.value);
124 add_trace("reason", NULL, "None of the payload types are supported by MS");
126 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
127 new_state(PORT_STATE_RELEASE);
128 trigger_work(&p_g_delete);
132 modify_lchan(p_g_rtp_media_types[i]);
133 /* use the payload type from received rtp list, not from locally generated payload types */
134 p_g_payload_type = p_g_rtp_payload_types[i];
136 /* modify to first given payload */
137 modify_lchan(media_types[0]);
138 p_g_payload_type = payload_types[0];
142 /* DTMF INDICATION */
143 void Pgsm_bs::start_dtmf_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
145 struct gsm_mncc *resp;
147 gsm_trace_header(p_g_interface_name, this, msg_type, DIRECTION_IN);
148 add_trace("keypad", NULL, "%c", mncc->keypad);
150 SPRINT(p_dialinginfo.id, "%c", mncc->keypad);
151 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
154 gsm_trace_header(p_g_interface_name, this, MNCC_START_DTMF_RSP, DIRECTION_OUT);
155 add_trace("keypad", NULL, "%c", mncc->keypad);
157 resp = create_mncc(MNCC_START_DTMF_RSP, p_g_callref);
158 resp->fields |= MNCC_F_KEYPAD;
159 resp->keypad = mncc->keypad;
160 send_and_free_mncc(p_g_lcr_gsm, resp->msg_type, resp);
162 if (p_g_rtp_bridge) {
163 class Port *remote = bridge_remote();
166 struct lcr_msg *message;
168 /* send dtmf information, because we bridge RTP directly */
169 message = message_create(0, remote->p_serial, EPOINT_TO_PORT, MESSAGE_DTMF);
170 message->param.dtmf = mncc->keypad;
171 message_put(message);
174 /* generate DTMF tones, since we do audio forwarding inside LCR */
175 switch (mncc->keypad) {
176 case '1': p_g_dtmf = dtmf_samples[0]; break;
177 case '2': p_g_dtmf = dtmf_samples[1]; break;
178 case '3': p_g_dtmf = dtmf_samples[2]; break;
180 case 'A': p_g_dtmf = dtmf_samples[3]; break;
181 case '4': p_g_dtmf = dtmf_samples[4]; break;
182 case '5': p_g_dtmf = dtmf_samples[5]; break;
183 case '6': p_g_dtmf = dtmf_samples[6]; break;
185 case 'B': p_g_dtmf = dtmf_samples[7]; break;
186 case '7': p_g_dtmf = dtmf_samples[8]; break;
187 case '8': p_g_dtmf = dtmf_samples[9]; break;
188 case '9': p_g_dtmf = dtmf_samples[10]; break;
190 case 'C': p_g_dtmf = dtmf_samples[11]; break;
191 case '*': p_g_dtmf = dtmf_samples[12]; break;
192 case '0': p_g_dtmf = dtmf_samples[13]; break;
193 case '#': p_g_dtmf = dtmf_samples[14]; break;
195 case 'D': p_g_dtmf = dtmf_samples[15]; break;
200 void Pgsm_bs::stop_dtmf_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
202 struct gsm_mncc *resp;
204 gsm_trace_header(p_g_interface_name, this, msg_type, DIRECTION_IN);
205 add_trace("keypad", NULL, "%c", mncc->keypad);
209 gsm_trace_header(p_g_interface_name, this, MNCC_STOP_DTMF_RSP, DIRECTION_OUT);
210 add_trace("keypad", NULL, "%c", mncc->keypad);
212 resp = create_mncc(MNCC_STOP_DTMF_RSP, p_g_callref);
213 resp->keypad = mncc->keypad;
214 send_and_free_mncc(p_g_lcr_gsm, resp->msg_type, resp);
220 /* HOLD INDICATION */
221 void Pgsm_bs::hold_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
223 struct lcr_msg *message;
224 struct gsm_mncc *resp, *frame;
226 gsm_trace_header(p_g_interface_name, this, msg_type, DIRECTION_IN);
229 /* notify the hold of call */
230 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
231 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_HOLD;
232 message->param.notifyinfo.local = 1; /* call is held by supplementary service */
233 message_put(message);
235 /* acknowledge hold */
236 gsm_trace_header(p_g_interface_name, this, MNCC_HOLD_CNF, DIRECTION_OUT);
238 resp = create_mncc(MNCC_HOLD_CNF, p_g_callref);
239 send_and_free_mncc(p_g_lcr_gsm, resp->msg_type, resp);
242 if (p_g_tch_connected) { /* it should be true */
243 gsm_trace_header(p_g_interface_name, this, MNCC_FRAME_DROP, DIRECTION_OUT);
245 frame = create_mncc(MNCC_FRAME_DROP, p_g_callref);
246 send_and_free_mncc(p_g_lcr_gsm, frame->msg_type, frame);
247 p_g_tch_connected = 0;
252 /* RETRIEVE INDICATION */
253 void Pgsm_bs::retr_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
255 struct lcr_msg *message;
256 struct gsm_mncc *resp, *frame;
258 gsm_trace_header(p_g_interface_name, this, msg_type, DIRECTION_IN);
261 /* notify the retrieve of call */
262 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_NOTIFY);
263 message->param.notifyinfo.notify = INFO_NOTIFY_REMOTE_RETRIEVAL;
264 message->param.notifyinfo.local = 1; /* call is retrieved by supplementary service */
265 message_put(message);
267 /* acknowledge retr */
268 gsm_trace_header(p_g_interface_name, this, MNCC_RETRIEVE_CNF, DIRECTION_OUT);
270 resp = create_mncc(MNCC_RETRIEVE_CNF, p_g_callref);
271 send_and_free_mncc(p_g_lcr_gsm, resp->msg_type, resp);
274 if (!p_g_tch_connected) { /* it should be true */
275 gsm_trace_header(p_g_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
277 frame = create_mncc(MNCC_FRAME_RECV, p_g_callref);
278 send_and_free_mncc(p_g_lcr_gsm, frame->msg_type, frame);
279 p_g_tch_connected = 1;
284 * select payload type by given list or GSM V1 FR
285 * return the payload type or 0 if not given
288 void Pgsm_bs::select_payload_type(struct gsm_mncc *mncc, unsigned char *payload_types, int *media_types, int *payloads, int max_payloads)
291 unsigned char payload_type;
295 gsm_trace_header(p_g_interface_name, this, 1 /* codec negotioation */, DIRECTION_NONE);
296 if ((mncc->fields & MNCC_F_BEARER_CAP)) {
297 /* select preferred payload type from list */
300 add_trace("bearer", "capa", "given by MS");
301 for (i = 0; mncc->bearer_cap.speech_ver[i] >= 0; i++) {
302 /* select payload type we support */
303 switch (mncc->bearer_cap.speech_ver[i]) {
305 add_trace("speech", "version", "Full Rate given");
306 media_type = MEDIA_TYPE_GSM;
307 payload_type = PAYLOAD_TYPE_GSM;
310 add_trace("speech", "version", "EFR given");
311 media_type = MEDIA_TYPE_GSM_EFR;
312 payload_type = 100 + *payloads;
315 add_trace("speech", "version", "AMR given");
316 media_type = MEDIA_TYPE_AMR;
317 payload_type = 100 + *payloads;
320 add_trace("speech", "version", "Half Rate given");
321 media_type = MEDIA_TYPE_GSM_HR;
322 payload_type = 100 + *payloads;
325 add_trace("speech", "version", "%d given", mncc->bearer_cap.speech_ver[i]);
329 /* wen don't support it, so we check the next */
331 add_trace("speech", "ignored", "Not supported by LCR");
334 if (!p_g_rtp_bridge) {
335 if (media_type != MEDIA_TYPE_GSM) {
336 add_trace("speech", "ignored", "Not suitable for LCR");
340 if (*payloads <= max_payloads) {
341 media_types[*payloads] = media_type;
342 payload_types[*payloads] = payload_type;
347 add_trace("bearer", "capa", "not given by MS");
348 add_trace("speech", "version", "Full Rate given");
349 media_types[0] = MEDIA_TYPE_GSM;
350 payload_types[0] = PAYLOAD_TYPE_GSM;
354 add_trace("error", "", "All given payload types unsupported");
359 * handles all indications
361 /* SETUP INDICATION */
362 void Pgsm_bs::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
364 class Endpoint *epoint;
365 struct lcr_msg *message;
366 struct gsm_mncc *proceeding, *frame;
367 struct interface *interface;
369 unsigned char payload_types[8];
372 interface = getinterfacebyname(p_g_interface_name);
374 PERROR("Cannot find interface %s.\n", p_g_interface_name);
378 /* process given callref */
379 gsm_trace_header(p_g_interface_name, this, 0, DIRECTION_IN);
380 add_trace("callref", "new", "0x%x", callref);
382 /* release in case the ID is already in use */
383 add_trace("error", NULL, "callref already in use");
385 mncc = create_mncc(MNCC_REJ_REQ, callref);
386 gsm_trace_header(p_g_interface_name, this, MNCC_REJ_REQ, DIRECTION_OUT);
387 mncc->fields |= MNCC_F_CAUSE;
388 mncc->cause.coding = 3;
389 mncc->cause.location = 1;
390 mncc->cause.value = 47;
391 add_trace("cause", "coding", "%d", mncc->cause.coding);
392 add_trace("cause", "location", "%d", mncc->cause.location);
393 add_trace("cause", "value", "%d", mncc->cause.value);
394 add_trace("reason", NULL, "callref already in use");
396 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
397 new_state(PORT_STATE_RELEASE);
398 trigger_work(&p_g_delete);
401 p_g_callref = callref;
406 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
408 p_callerinfo.present = INFO_PRESENT_ALLOWED;
409 if (mncc->calling.number[0])
410 SCPY(p_callerinfo.id, mncc->calling.number);
412 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
413 SCPY(p_callerinfo.imsi, mncc->imsi);
414 p_callerinfo.screen = INFO_SCREEN_NETWORK;
415 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
416 SCPY(p_callerinfo.interface, p_g_interface_name);
418 /* dialing information */
419 SCAT(p_dialinginfo.id, mncc->called.number);
420 switch (mncc->called.type) {
422 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
425 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
428 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
431 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
434 if (mncc->emergency) {
435 SCPY(p_dialinginfo.id, "emergency");
437 p_dialinginfo.sending_complete = 1;
439 /* bearer capability */
440 p_capainfo.bearer_capa = INFO_BC_SPEECH;
441 p_capainfo.bearer_info1 = (options.law=='a')?3:2;
442 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
443 p_capainfo.source_mode = B_MODE_TRANSPARENT;
444 p_g_mode = p_capainfo.source_mode;
446 /* get list of offered payload types
447 * if list ist empty, the FR V1 is selected */
448 select_payload_type(mncc, payload_types, media_types, &payloads, sizeof(payload_types));
449 /* if no given payload type is supported, we assume */
451 media_types[0] = MEDIA_TYPE_GSM;
452 payload_types[0] = PAYLOAD_TYPE_GSM;
456 /* if no given payload type is supported, we reject the call */
458 mncc = create_mncc(MNCC_REJ_REQ, callref);
459 gsm_trace_header(p_g_interface_name, this, MNCC_REJ_REQ, DIRECTION_OUT);
460 mncc->fields |= MNCC_F_CAUSE;
461 mncc->cause.coding = 3;
462 mncc->cause.location = 1;
463 mncc->cause.value = 65;
464 add_trace("cause", "coding", "%d", mncc->cause.coding);
465 add_trace("cause", "location", "%d", mncc->cause.location);
466 add_trace("cause", "value", "%d", mncc->cause.value);
467 add_trace("reason", NULL, "Given speech codec(s) not supported");
469 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
470 new_state(PORT_STATE_RELEASE);
471 trigger_work(&p_g_delete);
478 /* what infos did we got ... */
479 gsm_trace_header(p_g_interface_name, this, msg_type, DIRECTION_IN);
480 if (p_callerinfo.id[0])
481 add_trace("calling", "number", "%s", p_callerinfo.id);
483 SPRINT(p_callerinfo.id, "imsi-%s", p_callerinfo.imsi);
484 add_trace("calling", "imsi", "%s", p_callerinfo.imsi);
485 add_trace("dialing", "number", "%s", p_dialinginfo.id);
488 /* create endpoint */
490 FATAL("Incoming call but already got an endpoint.\n");
491 if (!(epoint = new Endpoint(p_serial, 0)))
492 FATAL("No memory for Endpoint instance\n");
493 epoint->ep_app = new_endpointapp(epoint, 0, interface->app); //incoming
494 epointlist_new(epoint->ep_serial);
496 /* modify lchan in case of no rtp bridge */
498 modify_lchan(media_types[0]);
500 /* send call proceeding */
501 gsm_trace_header(p_g_interface_name, this, MNCC_CALL_PROC_REQ, DIRECTION_OUT);
502 proceeding = create_mncc(MNCC_CALL_PROC_REQ, p_g_callref);
504 proceeding->fields |= MNCC_F_PROGRESS;
505 proceeding->progress.coding = 3; /* GSM */
506 proceeding->progress.location = 1;
507 proceeding->progress.descr = 8;
508 add_trace("progress", "coding", "%d", proceeding->progress.coding);
509 add_trace("progress", "location", "%d", proceeding->progress.location);
510 add_trace("progress", "descr", "%d", proceeding->progress.descr);
513 send_and_free_mncc(p_g_lcr_gsm, proceeding->msg_type, proceeding);
515 new_state(PORT_STATE_IN_PROCEEDING);
517 if (p_g_tones && !p_g_tch_connected) { /* only if ... */
518 gsm_trace_header(p_g_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
520 frame = create_mncc(MNCC_FRAME_RECV, p_g_callref);
521 send_and_free_mncc(p_g_lcr_gsm, frame->msg_type, frame);
522 p_g_tch_connected = 1;
525 /* send setup message to endpoit */
526 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
527 message->param.setup.port_type = p_type;
528 // message->param.setup.dtmf = 0;
529 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
530 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
531 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
532 SCPY((char *)message->param.setup.useruser.data, (char *)mncc->useruser.info);
533 message->param.setup.useruser.len = strlen(mncc->useruser.info);
534 message->param.setup.useruser.protocol = mncc->useruser.proto;
535 if (p_g_rtp_bridge) {
536 struct gsm_mncc_rtp *rtp;
539 PDEBUG(DEBUG_GSM, "Request RTP peer info, before forwarding setup\n");
540 p_g_setup_pending = message;
541 rtp = (struct gsm_mncc_rtp *) create_mncc(MNCC_RTP_CREATE, p_g_callref);
542 send_and_free_mncc(p_g_lcr_gsm, rtp->msg_type, rtp);
544 for (i = 0; i < (int)sizeof(message->param.setup.rtpinfo.payload_types) && i < payloads; i++) {
545 message->param.setup.rtpinfo.media_types[i] = media_types[i];
546 message->param.setup.rtpinfo.payload_types[i] = payload_types[i];
547 message->param.setup.rtpinfo.payloads++;
551 message_put(message);
556 * BSC sends message to port
558 int message_bsc(struct lcr_gsm *lcr_gsm, int msg_type, void *arg)
560 struct gsm_mncc *mncc = (struct gsm_mncc *)arg;
561 unsigned int callref = mncc->callref;
563 class Pgsm_bs *pgsm_bs = NULL;
565 // struct mISDNport *mISDNport;
567 /* Special messages */
572 callref = mncc->callref;
575 if ((port->p_type & PORT_CLASS_GSM_MASK) == PORT_CLASS_GSM_BS) {
576 pgsm_bs = (class Pgsm_bs *)port;
577 if (pgsm_bs->p_g_callref == callref) {
584 if (msg_type == GSM_TCHF_FRAME
585 || msg_type == GSM_TCHF_BAD_FRAME) {
587 /* inject DTMF, if enabled */
588 if (pgsm_bs->p_g_dtmf) {
589 unsigned char data[160];
592 for (i = 0; i < 160; i++) {
593 data[i] = pgsm_bs->p_g_dtmf[pgsm_bs->p_g_dtmf_index++];
594 if (pgsm_bs->p_g_dtmf_index == 8000)
595 pgsm_bs->p_g_dtmf_index = 0;
598 pgsm_bs->bridge_tx(data, 160);
600 pgsm_bs->frame_receive(arg);
601 /* if we do not bridge we need to inject audio, if available */
602 if (!pgsm_bs->p_bridge || pgsm_bs->p_tone_name[0]) {
603 unsigned char data[160];
606 i = pgsm_bs->read_audio(data, 160);
608 pgsm_bs->audio_send(data, i);
615 struct interface *interface;
617 if (msg_type != MNCC_SETUP_IND)
620 interface = getinterfacebyname(lcr_gsm->interface_name);
622 struct gsm_mncc *rej;
624 rej = create_mncc(MNCC_REJ_REQ, callref);
625 rej->fields |= MNCC_F_CAUSE;
626 rej->cause.coding = 3;
627 rej->cause.location = 1;
628 rej->cause.value = 27;
629 gsm_trace_header(NULL, NULL, MNCC_REJ_REQ, DIRECTION_OUT);
630 add_trace("cause", "coding", "%d", rej->cause.coding);
631 add_trace("cause", "location", "%d", rej->cause.location);
632 add_trace("cause", "value", "%d", rej->cause.value);
633 add_trace("reason", NULL, "interface %s not found", lcr_gsm->interface_name);
635 send_and_free_mncc(lcr_gsm, rej->msg_type, rej);
638 /* creating port object, transparent until setup with hdlc */
639 SPRINT(name, "%s-%d-in", interface->name, 0);
640 if (!(pgsm_bs = new Pgsm_bs(PORT_TYPE_GSM_BS_IN, name, NULL, interface)))
641 FATAL("Cannot create Port instance.\n");
646 pgsm_bs->setup_ind(msg_type, callref, mncc);
649 case MNCC_RTP_CREATE:
650 pgsm_bs->rtp_create_ind(msg_type, callref, mncc);
653 case MNCC_RTP_CONNECT:
654 pgsm_bs->rtp_connect_ind(msg_type, callref, mncc);
657 case MNCC_START_DTMF_IND:
658 pgsm_bs->start_dtmf_ind(msg_type, callref, mncc);
661 case MNCC_STOP_DTMF_IND:
662 pgsm_bs->stop_dtmf_ind(msg_type, callref, mncc);
665 case MNCC_CALL_CONF_IND:
666 pgsm_bs->call_conf_ind(msg_type, callref, mncc);
670 pgsm_bs->alert_ind(msg_type, callref, mncc);
674 pgsm_bs->setup_cnf(msg_type, callref, mncc);
677 case MNCC_SETUP_COMPL_IND:
678 pgsm_bs->setup_compl_ind(msg_type, callref, mncc);
682 pgsm_bs->disc_ind(msg_type, callref, mncc);
688 pgsm_bs->rel_ind(msg_type, callref, mncc);
691 case MNCC_NOTIFY_IND:
692 pgsm_bs->notify_ind(msg_type, callref, mncc);
696 pgsm_bs->hold_ind(msg_type, callref, mncc);
699 case MNCC_RETRIEVE_IND:
700 pgsm_bs->retr_ind(msg_type, callref, mncc);
704 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);
710 void Pgsm_bs::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
712 struct lcr_msg *message;
713 struct epoint_list *epointlist;
714 struct gsm_mncc *mncc;
716 /* copy setup infos to port */
717 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
718 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
719 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
720 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
722 /* no GSM MNCC connection */
723 if (p_g_lcr_gsm->mncc_lfd.fd < 0) {
724 gsm_trace_header(p_g_interface_name, this, MNCC_SETUP_REQ, DIRECTION_OUT);
725 add_trace("failure", NULL, "No MNCC connection.");
727 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
728 message->param.disconnectinfo.cause = 41; // temp. failure.
729 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
730 message_put(message);
731 new_state(PORT_STATE_RELEASE);
732 trigger_work(&p_g_delete);
737 if (!p_dialinginfo.id[0]) {
738 gsm_trace_header(p_g_interface_name, this, MNCC_SETUP_REQ, DIRECTION_OUT);
739 add_trace("failure", NULL, "No dialed subscriber given.");
741 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
742 message->param.disconnectinfo.cause = 28;
743 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
744 message_put(message);
745 new_state(PORT_STATE_RELEASE);
746 trigger_work(&p_g_delete);
750 /* unsupported codec for RTP bridge */
751 if (param->setup.rtpinfo.port) {
754 p_g_rtp_payloads = 0;
755 gsm_trace_header(p_g_interface_name, this, 1 /* codec negotioation */, DIRECTION_NONE);
756 for (i = 0; i < param->setup.rtpinfo.payloads; i++) {
757 switch (param->setup.rtpinfo.media_types[i]) {
759 case MEDIA_TYPE_GSM_EFR:
761 case MEDIA_TYPE_GSM_HR:
762 add_trace("rtp", "payload", "%s:%d supported", media_type2name(param->setup.rtpinfo.media_types[i]), param->setup.rtpinfo.payload_types[i]);
763 if (p_g_rtp_payloads < (int)sizeof(p_g_rtp_payload_types)) {
764 p_g_rtp_media_types[p_g_rtp_payloads] = param->setup.rtpinfo.media_types[i];
765 p_g_rtp_payload_types[p_g_rtp_payloads] = param->setup.rtpinfo.payload_types[i];
770 add_trace("rtp", "payload", "%s:%d unsupported", media_type2name(param->setup.rtpinfo.media_types[i]), param->setup.rtpinfo.payload_types[i]);
774 if (!p_g_rtp_payloads) {
775 gsm_trace_header(p_g_interface_name, this, MNCC_SETUP_REQ, DIRECTION_OUT);
776 add_trace("failure", NULL, "No payload given that is supported by GSM");
778 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
779 message->param.disconnectinfo.cause = 65;
780 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
781 message_put(message);
782 new_state(PORT_STATE_RELEASE);
783 trigger_work(&p_g_delete);
788 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
789 /* screen outgoing caller id */
790 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_g_interface_name);
792 /* attach only if not already */
793 epointlist = p_epointlist;
795 if (epointlist->epoint_id == epoint_id)
797 epointlist = epointlist->next;
800 epointlist_new(epoint_id);
803 gsm_trace_header(p_g_interface_name, this, 0, DIRECTION_OUT);
804 p_g_callref = new_callref++;
805 add_trace("callref", "new", "0x%x", p_g_callref);
808 gsm_trace_header(p_g_interface_name, this, MNCC_SETUP_REQ, DIRECTION_OUT);
809 mncc = create_mncc(MNCC_SETUP_REQ, p_g_callref);
810 /* caller information */
811 mncc->fields |= MNCC_F_CALLING;
812 mncc->calling.plan = 1;
813 switch (p_callerinfo.ntype) {
814 case INFO_NTYPE_UNKNOWN:
815 mncc->calling.type = 0x0;
817 case INFO_NTYPE_INTERNATIONAL:
818 mncc->calling.type = 0x1;
820 case INFO_NTYPE_NATIONAL:
821 mncc->calling.type = 0x2;
823 case INFO_NTYPE_SUBSCRIBER:
824 mncc->calling.type = 0x4;
826 default: /* INFO_NTYPE_NOTPRESENT */
827 mncc->fields &= ~MNCC_F_CALLING;
830 switch (p_callerinfo.screen) {
831 case INFO_SCREEN_USER:
832 mncc->calling.screen = 0;
834 default: /* INFO_SCREEN_NETWORK */
835 mncc->calling.screen = 3;
838 switch (p_callerinfo.present) {
839 case INFO_PRESENT_ALLOWED:
840 mncc->calling.present = 0;
842 case INFO_PRESENT_RESTRICTED:
843 mncc->calling.present = 1;
845 default: /* INFO_PRESENT_NOTAVAIL */
846 mncc->calling.present = 2;
849 if (mncc->fields & MNCC_F_CALLING) {
850 SCPY(mncc->calling.number, p_callerinfo.id);
851 add_trace("calling", "type", "%d", mncc->calling.type);
852 add_trace("calling", "plan", "%d", mncc->calling.plan);
853 add_trace("calling", "present", "%d", mncc->calling.present);
854 add_trace("calling", "screen", "%d", mncc->calling.screen);
855 add_trace("calling", "number", "%s", mncc->calling.number);
857 /* dialing information */
858 mncc->fields |= MNCC_F_CALLED;
859 if (!strncmp(p_dialinginfo.id, "imsi-", 5)) {
860 SCPY(mncc->imsi, p_dialinginfo.id+5);
861 add_trace("dialing", "imsi", "%s", mncc->imsi);
863 SCPY(mncc->called.number, p_dialinginfo.id);
864 add_trace("dialing", "number", "%s", mncc->called.number);
867 /* sending user-user */
869 /* redirecting number */
870 mncc->fields |= MNCC_F_REDIRECTING;
871 mncc->redirecting.plan = 1;
872 switch (p_redirinfo.ntype) {
873 case INFO_NTYPE_UNKNOWN:
874 mncc->redirecting.type = 0x0;
876 case INFO_NTYPE_INTERNATIONAL:
877 mncc->redirecting.type = 0x1;
879 case INFO_NTYPE_NATIONAL:
880 mncc->redirecting.type = 0x2;
882 case INFO_NTYPE_SUBSCRIBER:
883 mncc->redirecting.type = 0x4;
885 default: /* INFO_NTYPE_NOTPRESENT */
886 mncc->fields &= ~MNCC_F_REDIRECTING;
889 switch (p_redirinfo.screen) {
890 case INFO_SCREEN_USER:
891 mncc->redirecting.screen = 0;
893 default: /* INFO_SCREE_NETWORK */
894 mncc->redirecting.screen = 3;
897 switch (p_redirinfo.present) {
898 case INFO_PRESENT_ALLOWED:
899 mncc->redirecting.present = 0;
901 case INFO_PRESENT_RESTRICTED:
902 mncc->redirecting.present = 1;
904 default: /* INFO_PRESENT_NOTAVAIL */
905 mncc->redirecting.present = 2;
908 /* sending redirecting number only in ntmode */
909 if (mncc->fields & MNCC_F_REDIRECTING) {
910 SCPY(mncc->redirecting.number, p_redirinfo.id);
911 add_trace("redir", "type", "%d", mncc->redirecting.type);
912 add_trace("redir", "plan", "%d", mncc->redirecting.plan);
913 add_trace("redir", "present", "%d", mncc->redirecting.present);
914 add_trace("redir", "screen", "%d", mncc->redirecting.screen);
915 add_trace("redir", "number", "%s", mncc->redirecting.number);
919 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
921 new_state(PORT_STATE_OUT_SETUP);
923 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
924 message_put(message);
927 if (param->setup.rtpinfo.port) {
929 p_g_rtp_ip_remote = param->setup.rtpinfo.ip;
930 p_g_rtp_port_remote = param->setup.rtpinfo.port;
936 * endpoint sends messages to the port
938 int Pgsm_bs::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
940 if (Pgsm::message_epoint(epoint_id, message_id, param))
944 case MESSAGE_SETUP: /* dial-out command received from epoint */
945 if (p_state!=PORT_STATE_IDLE)
947 message_setup(epoint_id, message_id, param);
951 PDEBUG(DEBUG_GSM, "Pgsm_bs(%s) gsm port with (caller id %s) received unhandled nessage: %d\n", p_name, p_callerinfo.id, message_id);
957 int gsm_bs_exit(int rc)
959 /* free gsm instance */
961 if (gsm_bs->mncc_lfd.fd > -1) {
962 close(gsm_bs->mncc_lfd.fd);
963 unregister_fd(&gsm_bs->mncc_lfd);
966 del_timer(&gsm_bs->socket_retry);
975 int gsm_bs_init(struct interface *interface)
977 /* create gsm instance */
978 gsm_bs = (struct lcr_gsm *)MALLOC(sizeof(struct lcr_gsm));
980 SCPY(gsm_bs->interface_name, interface->name);
981 gsm_bs->type = LCR_GSM_TYPE_NETWORK;
982 gsm_bs->sun.sun_family = AF_UNIX;
983 SCPY(gsm_bs->sun.sun_path, "/tmp/bsc_mncc");
985 memset(&gsm_bs->socket_retry, 0, sizeof(gsm_bs->socket_retry));
986 add_timer(&gsm_bs->socket_retry, mncc_socket_retry_cb, gsm_bs, 0);
988 /* do the initial connect */
989 mncc_socket_retry_cb(&gsm_bs->socket_retry, gsm_bs, 0);