--- modem.c.ORG 2012-05-22 16:42:30.000000000 +0200 +++ modem.c 2012-05-22 16:42:25.000000000 +0200 @@ -371,7 +371,7 @@ char *modem_get_s_register(int r) if (modem_command(command, "?") == 1) { - log(L_DEBUG, "Got s-register value \"%s\".\n", modem_get_last_result()); + log(L_DEBUG, "Got s-register %d value \"%s\".\n", r, modem_get_last_result()); modem_raw_read(temp, 4); @@ -897,7 +897,9 @@ int modem_wait(void) int modem_count_rings(int needrings) { char line[MODEM_BUFFER_LEN + 1]; - char *sreg; + char *prefix; + char *sreg; + char *tmpline; int haverings; int havesregs; int havesetup; @@ -981,7 +983,49 @@ int modem_count_rings(int needrings) voice_init_section(); - xstrncpy(setup.voice.callerid, &line[15], VOICE_MAX_CALLERID); + // read caller-id and remove leading zeros + tmpline = &line[15]; + while(*tmpline == '0') + tmpline++; + + log(L_DEBUG, "TEST-tmpline %s\n", tmpline); + log(L_DEBUG, "TEST-tmpline-length %d\n", strlen(tmpline)); + + if (strlen(tmpline) == 0) + { + // no caller-id has been transmitted + xstrncpy(setup.voice.callerid, &line[15], VOICE_MAX_CALLERID); + } + else + { + // caller-id has been transmitted + prefix = ""; + + if ((sreg = modem_get_s_register(21))) + { + // bit-mapped register. Set on incoming call (during RING) to the value + // of octet 3 of calling party number information element (numbering plan). + int sreg_val = atoi(sreg); + + if (sreg_val & 32) // check if bit 6 has been set -> 0x20 - national + { + // national call + prefix = "0"; + log(L_DEBUG, "check bit 6 -> national call\n", sreg_val); + } + else if (sreg_val & 16) // check if bit 5 has been set -> 0x10 - international + { + // international call + prefix = "00"; + log(L_DEBUG, "check bit 5 -> international call\n", sreg_val); + } + } + + strncpy(setup.voice.callerid, prefix, 3); + xstrncat(setup.voice.callerid, tmpline, VOICE_MAX_CALLERID); + } + + log(L_DEBUG, "TEST-setup.voice.callerid %s\n", setup.voice.callerid); voice_user_section(setup.voice.callerid);