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 */
299 uint8_t dynamic_type = 96;
301 add_trace("bearer", "capa", "given by MS");
302 for (i = 0; mncc->bearer_cap.speech_ver[i] >= 0; i++) {
303 /* select payload type we support */
304 switch (mncc->bearer_cap.speech_ver[i]) {
306 add_trace("speech", "version", "Full Rate given");
307 media_type = MEDIA_TYPE_GSM;
308 payload_type = PAYLOAD_TYPE_GSM;
311 add_trace("speech", "version", "EFR given");
312 media_type = MEDIA_TYPE_GSM_EFR;
313 payload_type = dynamic_type++;
316 add_trace("speech", "version", "AMR given");
317 media_type = MEDIA_TYPE_AMR;
318 payload_type = dynamic_type++;
321 add_trace("speech", "version", "Half Rate given");
322 media_type = MEDIA_TYPE_GSM_HR;
323 payload_type = dynamic_type++;
326 add_trace("speech", "version", "%d given", mncc->bearer_cap.speech_ver[i]);
330 /* wen don't support it, so we check the next */
332 add_trace("speech", "ignored", "Not supported by LCR");
335 if (!p_g_rtp_bridge) {
336 if (media_type != MEDIA_TYPE_GSM) {
337 add_trace("speech", "ignored", "Not suitable for LCR");
341 if (*payloads <= max_payloads) {
342 media_types[*payloads] = media_type;
343 payload_types[*payloads] = payload_type;
348 add_trace("bearer", "capa", "not given by MS");
349 add_trace("speech", "version", "Full Rate given");
350 media_types[0] = MEDIA_TYPE_GSM;
351 payload_types[0] = PAYLOAD_TYPE_GSM;
355 add_trace("error", "", "All given payload types unsupported");
360 * handles all indications
362 /* SETUP INDICATION */
363 void Pgsm_bs::setup_ind(unsigned int msg_type, unsigned int callref, struct gsm_mncc *mncc)
365 class Endpoint *epoint;
366 struct lcr_msg *message;
367 struct gsm_mncc *proceeding, *frame;
368 struct interface *interface;
370 unsigned char payload_types[8];
373 interface = getinterfacebyname(p_g_interface_name);
375 PERROR("Cannot find interface %s.\n", p_g_interface_name);
379 /* process given callref */
380 gsm_trace_header(p_g_interface_name, this, 0, DIRECTION_IN);
381 add_trace("callref", "new", "0x%x", callref);
383 /* release in case the ID is already in use */
384 add_trace("error", NULL, "callref already in use");
386 mncc = create_mncc(MNCC_REJ_REQ, callref);
387 gsm_trace_header(p_g_interface_name, this, MNCC_REJ_REQ, DIRECTION_OUT);
388 mncc->fields |= MNCC_F_CAUSE;
389 mncc->cause.coding = 3;
390 mncc->cause.location = 1;
391 mncc->cause.value = 47;
392 add_trace("cause", "coding", "%d", mncc->cause.coding);
393 add_trace("cause", "location", "%d", mncc->cause.location);
394 add_trace("cause", "value", "%d", mncc->cause.value);
395 add_trace("reason", NULL, "callref already in use");
397 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
398 new_state(PORT_STATE_RELEASE);
399 trigger_work(&p_g_delete);
402 p_g_callref = callref;
407 p_callerinfo.present = INFO_PRESENT_RESTRICTED;
409 p_callerinfo.present = INFO_PRESENT_ALLOWED;
410 if (mncc->calling.number[0])
411 SCPY(p_callerinfo.id, mncc->calling.number);
413 p_callerinfo.present = INFO_PRESENT_NOTAVAIL;
414 SCPY(p_callerinfo.imsi, mncc->imsi);
415 p_callerinfo.screen = INFO_SCREEN_NETWORK;
416 p_callerinfo.ntype = INFO_NTYPE_UNKNOWN;
417 SCPY(p_callerinfo.interface, p_g_interface_name);
419 /* dialing information */
420 SCAT(p_dialinginfo.id, mncc->called.number);
421 switch (mncc->called.type) {
423 p_dialinginfo.ntype = INFO_NTYPE_INTERNATIONAL;
426 p_dialinginfo.ntype = INFO_NTYPE_NATIONAL;
429 p_dialinginfo.ntype = INFO_NTYPE_SUBSCRIBER;
432 p_dialinginfo.ntype = INFO_NTYPE_UNKNOWN;
435 if (mncc->emergency) {
436 SCPY(p_dialinginfo.id, "emergency");
438 p_dialinginfo.sending_complete = 1;
440 /* bearer capability */
441 p_capainfo.bearer_capa = INFO_BC_SPEECH;
442 p_capainfo.bearer_info1 = (options.law=='a')?3:2;
443 p_capainfo.bearer_mode = INFO_BMODE_CIRCUIT;
444 p_capainfo.source_mode = B_MODE_TRANSPARENT;
445 p_g_mode = p_capainfo.source_mode;
447 /* get list of offered payload types
448 * if list ist empty, the FR V1 is selected */
449 select_payload_type(mncc, payload_types, media_types, &payloads, sizeof(payload_types));
450 /* if no given payload type is supported, we assume */
452 media_types[0] = MEDIA_TYPE_GSM;
453 payload_types[0] = PAYLOAD_TYPE_GSM;
457 /* if no given payload type is supported, we reject the call */
459 mncc = create_mncc(MNCC_REJ_REQ, callref);
460 gsm_trace_header(p_g_interface_name, this, MNCC_REJ_REQ, DIRECTION_OUT);
461 mncc->fields |= MNCC_F_CAUSE;
462 mncc->cause.coding = 3;
463 mncc->cause.location = 1;
464 mncc->cause.value = 65;
465 add_trace("cause", "coding", "%d", mncc->cause.coding);
466 add_trace("cause", "location", "%d", mncc->cause.location);
467 add_trace("cause", "value", "%d", mncc->cause.value);
468 add_trace("reason", NULL, "Given speech codec(s) not supported");
470 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
471 new_state(PORT_STATE_RELEASE);
472 trigger_work(&p_g_delete);
479 /* what infos did we got ... */
480 gsm_trace_header(p_g_interface_name, this, msg_type, DIRECTION_IN);
481 if (p_callerinfo.id[0])
482 add_trace("calling", "number", "%s", p_callerinfo.id);
484 SPRINT(p_callerinfo.id, "imsi-%s", p_callerinfo.imsi);
485 add_trace("calling", "imsi", "%s", p_callerinfo.imsi);
486 add_trace("dialing", "number", "%s", p_dialinginfo.id);
489 /* create endpoint */
491 FATAL("Incoming call but already got an endpoint.\n");
492 if (!(epoint = new Endpoint(p_serial, 0)))
493 FATAL("No memory for Endpoint instance\n");
494 epoint->ep_app = new_endpointapp(epoint, 0, interface->app); //incoming
495 epointlist_new(epoint->ep_serial);
497 /* modify lchan in case of no rtp bridge */
499 modify_lchan(media_types[0]);
501 /* send call proceeding */
502 gsm_trace_header(p_g_interface_name, this, MNCC_CALL_PROC_REQ, DIRECTION_OUT);
503 proceeding = create_mncc(MNCC_CALL_PROC_REQ, p_g_callref);
505 proceeding->fields |= MNCC_F_PROGRESS;
506 proceeding->progress.coding = 3; /* GSM */
507 proceeding->progress.location = 1;
508 proceeding->progress.descr = 8;
509 add_trace("progress", "coding", "%d", proceeding->progress.coding);
510 add_trace("progress", "location", "%d", proceeding->progress.location);
511 add_trace("progress", "descr", "%d", proceeding->progress.descr);
514 send_and_free_mncc(p_g_lcr_gsm, proceeding->msg_type, proceeding);
516 new_state(PORT_STATE_IN_PROCEEDING);
518 if (p_g_tones && !p_g_tch_connected) { /* only if ... */
519 gsm_trace_header(p_g_interface_name, this, MNCC_FRAME_RECV, DIRECTION_OUT);
521 frame = create_mncc(MNCC_FRAME_RECV, p_g_callref);
522 send_and_free_mncc(p_g_lcr_gsm, frame->msg_type, frame);
523 p_g_tch_connected = 1;
526 /* send setup message to endpoit */
527 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_SETUP);
528 message->param.setup.port_type = p_type;
529 // message->param.setup.dtmf = 0;
530 memcpy(&message->param.setup.dialinginfo, &p_dialinginfo, sizeof(struct dialing_info));
531 memcpy(&message->param.setup.callerinfo, &p_callerinfo, sizeof(struct caller_info));
532 memcpy(&message->param.setup.capainfo, &p_capainfo, sizeof(struct capa_info));
533 SCPY((char *)message->param.setup.useruser.data, (char *)mncc->useruser.info);
534 message->param.setup.useruser.len = strlen(mncc->useruser.info);
535 message->param.setup.useruser.protocol = mncc->useruser.proto;
536 if (p_g_rtp_bridge) {
537 struct gsm_mncc_rtp *rtp;
540 PDEBUG(DEBUG_GSM, "Request RTP peer info, before forwarding setup\n");
541 p_g_setup_pending = message;
542 rtp = (struct gsm_mncc_rtp *) create_mncc(MNCC_RTP_CREATE, p_g_callref);
543 send_and_free_mncc(p_g_lcr_gsm, rtp->msg_type, rtp);
545 for (i = 0; i < (int)sizeof(message->param.setup.rtpinfo.payload_types) && i < payloads; i++) {
546 message->param.setup.rtpinfo.media_types[i] = media_types[i];
547 message->param.setup.rtpinfo.payload_types[i] = payload_types[i];
548 message->param.setup.rtpinfo.payloads++;
552 message_put(message);
557 * BSC sends message to port
559 int message_bsc(struct lcr_gsm *lcr_gsm, int msg_type, void *arg)
561 struct gsm_mncc *mncc = (struct gsm_mncc *)arg;
562 unsigned int callref = mncc->callref;
564 class Pgsm_bs *pgsm_bs = NULL;
566 // struct mISDNport *mISDNport;
568 /* Special messages */
573 callref = mncc->callref;
576 if ((port->p_type & PORT_CLASS_GSM_MASK) == PORT_CLASS_GSM_BS) {
577 pgsm_bs = (class Pgsm_bs *)port;
578 if (pgsm_bs->p_g_callref == callref) {
585 if (msg_type == GSM_TCHF_FRAME
586 || msg_type == GSM_TCHF_BAD_FRAME) {
588 /* inject DTMF, if enabled */
589 if (pgsm_bs->p_g_dtmf) {
590 unsigned char data[160];
593 for (i = 0; i < 160; i++) {
594 data[i] = pgsm_bs->p_g_dtmf[pgsm_bs->p_g_dtmf_index++];
595 if (pgsm_bs->p_g_dtmf_index == 8000)
596 pgsm_bs->p_g_dtmf_index = 0;
599 pgsm_bs->bridge_tx(data, 160);
601 pgsm_bs->frame_receive(arg);
602 /* if we do not bridge we need to inject audio, if available */
603 if (!pgsm_bs->p_bridge || pgsm_bs->p_tone_name[0]) {
604 unsigned char data[160];
607 i = pgsm_bs->read_audio(data, 160);
609 pgsm_bs->audio_send(data, i);
616 struct interface *interface;
618 if (msg_type != MNCC_SETUP_IND)
621 interface = getinterfacebyname(lcr_gsm->interface_name);
623 struct gsm_mncc *rej;
625 rej = create_mncc(MNCC_REJ_REQ, callref);
626 rej->fields |= MNCC_F_CAUSE;
627 rej->cause.coding = 3;
628 rej->cause.location = 1;
629 rej->cause.value = 27;
630 gsm_trace_header(NULL, NULL, MNCC_REJ_REQ, DIRECTION_OUT);
631 add_trace("cause", "coding", "%d", rej->cause.coding);
632 add_trace("cause", "location", "%d", rej->cause.location);
633 add_trace("cause", "value", "%d", rej->cause.value);
634 add_trace("reason", NULL, "interface %s not found", lcr_gsm->interface_name);
636 send_and_free_mncc(lcr_gsm, rej->msg_type, rej);
639 /* creating port object, transparent until setup with hdlc */
640 SPRINT(name, "%s-%d-in", interface->name, 0);
641 if (!(pgsm_bs = new Pgsm_bs(PORT_TYPE_GSM_BS_IN, name, NULL, interface)))
642 FATAL("Cannot create Port instance.\n");
647 pgsm_bs->setup_ind(msg_type, callref, mncc);
650 case MNCC_RTP_CREATE:
651 pgsm_bs->rtp_create_ind(msg_type, callref, mncc);
654 case MNCC_RTP_CONNECT:
655 pgsm_bs->rtp_connect_ind(msg_type, callref, mncc);
658 case MNCC_START_DTMF_IND:
659 pgsm_bs->start_dtmf_ind(msg_type, callref, mncc);
662 case MNCC_STOP_DTMF_IND:
663 pgsm_bs->stop_dtmf_ind(msg_type, callref, mncc);
666 case MNCC_CALL_CONF_IND:
667 pgsm_bs->call_conf_ind(msg_type, callref, mncc);
671 pgsm_bs->alert_ind(msg_type, callref, mncc);
675 pgsm_bs->setup_cnf(msg_type, callref, mncc);
678 case MNCC_SETUP_COMPL_IND:
679 pgsm_bs->setup_compl_ind(msg_type, callref, mncc);
683 pgsm_bs->disc_ind(msg_type, callref, mncc);
689 pgsm_bs->rel_ind(msg_type, callref, mncc);
692 case MNCC_NOTIFY_IND:
693 pgsm_bs->notify_ind(msg_type, callref, mncc);
697 pgsm_bs->hold_ind(msg_type, callref, mncc);
700 case MNCC_RETRIEVE_IND:
701 pgsm_bs->retr_ind(msg_type, callref, mncc);
705 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);
711 void Pgsm_bs::message_setup(unsigned int epoint_id, int message_id, union parameter *param)
713 struct lcr_msg *message;
714 struct epoint_list *epointlist;
715 struct gsm_mncc *mncc;
717 /* copy setup infos to port */
718 memcpy(&p_callerinfo, ¶m->setup.callerinfo, sizeof(p_callerinfo));
719 memcpy(&p_dialinginfo, ¶m->setup.dialinginfo, sizeof(p_dialinginfo));
720 memcpy(&p_capainfo, ¶m->setup.capainfo, sizeof(p_capainfo));
721 memcpy(&p_redirinfo, ¶m->setup.redirinfo, sizeof(p_redirinfo));
723 /* no GSM MNCC connection */
724 if (p_g_lcr_gsm->mncc_lfd.fd < 0) {
725 gsm_trace_header(p_g_interface_name, this, MNCC_SETUP_REQ, DIRECTION_OUT);
726 add_trace("failure", NULL, "No MNCC connection.");
728 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
729 message->param.disconnectinfo.cause = 41; // temp. failure.
730 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
731 message_put(message);
732 new_state(PORT_STATE_RELEASE);
733 trigger_work(&p_g_delete);
738 if (!p_dialinginfo.id[0]) {
739 gsm_trace_header(p_g_interface_name, this, MNCC_SETUP_REQ, DIRECTION_OUT);
740 add_trace("failure", NULL, "No dialed subscriber given.");
742 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
743 message->param.disconnectinfo.cause = 28;
744 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
745 message_put(message);
746 new_state(PORT_STATE_RELEASE);
747 trigger_work(&p_g_delete);
751 /* unsupported codec for RTP bridge */
752 if (param->setup.rtpinfo.port) {
755 p_g_rtp_payloads = 0;
756 gsm_trace_header(p_g_interface_name, this, 1 /* codec negotioation */, DIRECTION_NONE);
757 for (i = 0; i < param->setup.rtpinfo.payloads; i++) {
758 switch (param->setup.rtpinfo.media_types[i]) {
760 case MEDIA_TYPE_GSM_EFR:
762 case MEDIA_TYPE_GSM_HR:
763 add_trace("rtp", "payload", "%s:%d supported", media_type2name(param->setup.rtpinfo.media_types[i]), param->setup.rtpinfo.payload_types[i]);
764 if (p_g_rtp_payloads < (int)sizeof(p_g_rtp_payload_types)) {
765 p_g_rtp_media_types[p_g_rtp_payloads] = param->setup.rtpinfo.media_types[i];
766 p_g_rtp_payload_types[p_g_rtp_payloads] = param->setup.rtpinfo.payload_types[i];
771 add_trace("rtp", "payload", "%s:%d unsupported", media_type2name(param->setup.rtpinfo.media_types[i]), param->setup.rtpinfo.payload_types[i]);
775 if (!p_g_rtp_payloads) {
776 gsm_trace_header(p_g_interface_name, this, MNCC_SETUP_REQ, DIRECTION_OUT);
777 add_trace("failure", NULL, "No payload given that is supported by GSM");
779 message = message_create(p_serial, epoint_id, PORT_TO_EPOINT, MESSAGE_RELEASE);
780 message->param.disconnectinfo.cause = 65;
781 message->param.disconnectinfo.location = LOCATION_PRIVATE_LOCAL;
782 message_put(message);
783 new_state(PORT_STATE_RELEASE);
784 trigger_work(&p_g_delete);
789 // SCPY(&p_m_tones_dir, param->setup.ext.tones_dir);
790 /* screen outgoing caller id */
791 do_screen(1, p_callerinfo.id, sizeof(p_callerinfo.id), &p_callerinfo.ntype, &p_callerinfo.present, p_g_interface_name);
793 /* attach only if not already */
794 epointlist = p_epointlist;
796 if (epointlist->epoint_id == epoint_id)
798 epointlist = epointlist->next;
801 epointlist_new(epoint_id);
804 gsm_trace_header(p_g_interface_name, this, 0, DIRECTION_OUT);
805 p_g_callref = new_callref++;
806 add_trace("callref", "new", "0x%x", p_g_callref);
809 gsm_trace_header(p_g_interface_name, this, MNCC_SETUP_REQ, DIRECTION_OUT);
810 mncc = create_mncc(MNCC_SETUP_REQ, p_g_callref);
811 /* caller information */
812 mncc->fields |= MNCC_F_CALLING;
813 mncc->calling.plan = 1;
814 switch (p_callerinfo.ntype) {
815 case INFO_NTYPE_UNKNOWN:
816 mncc->calling.type = 0x0;
818 case INFO_NTYPE_INTERNATIONAL:
819 mncc->calling.type = 0x1;
821 case INFO_NTYPE_NATIONAL:
822 mncc->calling.type = 0x2;
824 case INFO_NTYPE_SUBSCRIBER:
825 mncc->calling.type = 0x4;
827 default: /* INFO_NTYPE_NOTPRESENT */
828 mncc->fields &= ~MNCC_F_CALLING;
831 switch (p_callerinfo.screen) {
832 case INFO_SCREEN_USER:
833 mncc->calling.screen = 0;
835 default: /* INFO_SCREEN_NETWORK */
836 mncc->calling.screen = 3;
839 switch (p_callerinfo.present) {
840 case INFO_PRESENT_ALLOWED:
841 mncc->calling.present = 0;
843 case INFO_PRESENT_RESTRICTED:
844 mncc->calling.present = 1;
846 default: /* INFO_PRESENT_NOTAVAIL */
847 mncc->calling.present = 2;
850 if (mncc->fields & MNCC_F_CALLING) {
851 SCPY(mncc->calling.number, p_callerinfo.id);
852 add_trace("calling", "type", "%d", mncc->calling.type);
853 add_trace("calling", "plan", "%d", mncc->calling.plan);
854 add_trace("calling", "present", "%d", mncc->calling.present);
855 add_trace("calling", "screen", "%d", mncc->calling.screen);
856 add_trace("calling", "number", "%s", mncc->calling.number);
858 /* dialing information */
859 mncc->fields |= MNCC_F_CALLED;
860 if (!strncmp(p_dialinginfo.id, "imsi-", 5)) {
861 SCPY(mncc->imsi, p_dialinginfo.id+5);
862 add_trace("dialing", "imsi", "%s", mncc->imsi);
864 SCPY(mncc->called.number, p_dialinginfo.id);
865 add_trace("dialing", "number", "%s", mncc->called.number);
868 /* sending user-user */
870 /* redirecting number */
871 mncc->fields |= MNCC_F_REDIRECTING;
872 mncc->redirecting.plan = 1;
873 switch (p_redirinfo.ntype) {
874 case INFO_NTYPE_UNKNOWN:
875 mncc->redirecting.type = 0x0;
877 case INFO_NTYPE_INTERNATIONAL:
878 mncc->redirecting.type = 0x1;
880 case INFO_NTYPE_NATIONAL:
881 mncc->redirecting.type = 0x2;
883 case INFO_NTYPE_SUBSCRIBER:
884 mncc->redirecting.type = 0x4;
886 default: /* INFO_NTYPE_NOTPRESENT */
887 mncc->fields &= ~MNCC_F_REDIRECTING;
890 switch (p_redirinfo.screen) {
891 case INFO_SCREEN_USER:
892 mncc->redirecting.screen = 0;
894 default: /* INFO_SCREE_NETWORK */
895 mncc->redirecting.screen = 3;
898 switch (p_redirinfo.present) {
899 case INFO_PRESENT_ALLOWED:
900 mncc->redirecting.present = 0;
902 case INFO_PRESENT_RESTRICTED:
903 mncc->redirecting.present = 1;
905 default: /* INFO_PRESENT_NOTAVAIL */
906 mncc->redirecting.present = 2;
909 /* sending redirecting number only in ntmode */
910 if (mncc->fields & MNCC_F_REDIRECTING) {
911 SCPY(mncc->redirecting.number, p_redirinfo.id);
912 add_trace("redir", "type", "%d", mncc->redirecting.type);
913 add_trace("redir", "plan", "%d", mncc->redirecting.plan);
914 add_trace("redir", "present", "%d", mncc->redirecting.present);
915 add_trace("redir", "screen", "%d", mncc->redirecting.screen);
916 add_trace("redir", "number", "%s", mncc->redirecting.number);
920 send_and_free_mncc(p_g_lcr_gsm, mncc->msg_type, mncc);
922 new_state(PORT_STATE_OUT_SETUP);
924 message = message_create(p_serial, ACTIVE_EPOINT(p_epointlist), PORT_TO_EPOINT, MESSAGE_PROCEEDING);
925 message_put(message);
928 if (param->setup.rtpinfo.port) {
930 p_g_rtp_ip_remote = param->setup.rtpinfo.ip;
931 p_g_rtp_port_remote = param->setup.rtpinfo.port;
937 * endpoint sends messages to the port
939 int Pgsm_bs::message_epoint(unsigned int epoint_id, int message_id, union parameter *param)
941 if (Pgsm::message_epoint(epoint_id, message_id, param))
945 case MESSAGE_SETUP: /* dial-out command received from epoint */
946 if (p_state!=PORT_STATE_IDLE)
948 message_setup(epoint_id, message_id, param);
952 PDEBUG(DEBUG_GSM, "Pgsm_bs(%s) gsm port with (caller id %s) received unhandled nessage: %d\n", p_name, p_callerinfo.id, message_id);
958 int gsm_bs_exit(int rc)
960 /* free gsm instance */
962 if (gsm_bs->mncc_lfd.fd > -1) {
963 close(gsm_bs->mncc_lfd.fd);
964 unregister_fd(&gsm_bs->mncc_lfd);
967 del_timer(&gsm_bs->socket_retry);
976 int gsm_bs_init(struct interface *interface)
978 /* create gsm instance */
979 gsm_bs = (struct lcr_gsm *)MALLOC(sizeof(struct lcr_gsm));
981 SCPY(gsm_bs->interface_name, interface->name);
982 gsm_bs->type = LCR_GSM_TYPE_NETWORK;
983 gsm_bs->sun.sun_family = AF_UNIX;
984 SCPY(gsm_bs->sun.sun_path, "/tmp/bsc_mncc");
986 memset(&gsm_bs->socket_retry, 0, sizeof(gsm_bs->socket_retry));
987 add_timer(&gsm_bs->socket_retry, mncc_socket_retry_cb, gsm_bs, 0);
989 /* do the initial connect */
990 mncc_socket_retry_cb(&gsm_bs->socket_retry, gsm_bs, 0);