diff --git a/src/mod/endpoints/mod_gsmopen/gsmopen.h b/src/mod/endpoints/mod_gsmopen/gsmopen.h index 6ba413e3b1..97731c676d 100644 --- a/src/mod/endpoints/mod_gsmopen/gsmopen.h +++ b/src/mod/endpoints/mod_gsmopen/gsmopen.h @@ -451,6 +451,8 @@ struct private_object { int requesting_imsi; char operator_name[128]; int requesting_operator_name; + char subscriber_number[128]; + int requesting_subscriber_number; int network_creg_not_supported; char creg[128]; diff --git a/src/mod/endpoints/mod_gsmopen/gsmopen_protocol.cpp b/src/mod/endpoints/mod_gsmopen/gsmopen_protocol.cpp index 7533e40a5b..5f0efb9121 100644 --- a/src/mod/endpoints/mod_gsmopen/gsmopen_protocol.cpp +++ b/src/mod/endpoints/mod_gsmopen/gsmopen_protocol.cpp @@ -367,6 +367,14 @@ int gsmopen_serial_config_AT(private_t *tech_pvt) DEBUGA_GSMOPEN("AT+COPS? failed\n", GSMOPEN_P_LOG); } + /* subscriber number */ + tech_pvt->requesting_subscriber_number = 1; + res = gsmopen_serial_write_AT_ack(tech_pvt, "AT+CNUM"); + tech_pvt->requesting_subscriber_number = 0; + if (res) { + DEBUGA_GSMOPEN("AT+CNUM failed, continue\n", GSMOPEN_P_LOG); + } + /* IMEI */ tech_pvt->requesting_imei = 1; res = gsmopen_serial_write_AT_ack(tech_pvt, "AT+GSN"); @@ -1032,6 +1040,41 @@ int gsmopen_serial_read_AT(private_t *tech_pvt, int look_for_ack, int timeout_us strncpy(tech_pvt->operator_name, oper, sizeof(tech_pvt->operator_name)); } + if ((strncmp(tech_pvt->line_array.result[i], "+CNUM:", 6) == 0) || (strncmp(tech_pvt->line_array.result[i], "ERROR+CNUM:", 11) == 0)) { + int skip_chars, err, type; + char number[128] = ""; + char *in_ptr, *out_ptr; + + skip_chars = err = type = 0; + in_ptr = out_ptr = number; + + /* +CNUM or ERROR+CNUM ? */ + if ((strncmp(tech_pvt->line_array.result[i], "+CNUM:", 6) == 0)) + skip_chars = 7; + else + skip_chars = 12; + + err = sscanf(&tech_pvt->line_array.result[i][skip_chars], "%*[^,],%[^,],%d", &number, &type); + + /* Remove any double quotes */ + while (*in_ptr) { + if (*in_ptr != '\"') *out_ptr++ = *in_ptr; + in_ptr++; + } + *out_ptr = '\0'; + + if (err < 2) { + DEBUGA_GSMOPEN("|%s| is not formatted as: |+CNUM: \"Name\", \"+39025458068\", 145|\n", GSMOPEN_P_LOG, tech_pvt->line_array.result[i]); + } else if (option_debug) { + DEBUGA_GSMOPEN("|%s| +CNUM: Subscriber number = %s, Type = %d\n", GSMOPEN_P_LOG, tech_pvt->line_array.result[i], number, type); + } + + /* Copy only the first number listed if there are more then one */ + if (tech_pvt->requesting_subscriber_number && !strlen(tech_pvt->subscriber_number)) + strncpy(tech_pvt->subscriber_number, number, sizeof(tech_pvt->subscriber_number)); + + } + if ((strncmp(tech_pvt->line_array.result[i], "+CMGW:", 6) == 0)) { int err; diff --git a/src/mod/endpoints/mod_gsmopen/mod_gsmopen.cpp b/src/mod/endpoints/mod_gsmopen/mod_gsmopen.cpp index 73478826e7..c9af03e3b1 100644 --- a/src/mod/endpoints/mod_gsmopen/mod_gsmopen.cpp +++ b/src/mod/endpoints/mod_gsmopen/mod_gsmopen.cpp @@ -2422,6 +2422,7 @@ SWITCH_STANDARD_API(gsmopen_dump_function) stream->write_function(stream, "got_signal = %s\n", value); snprintf(value, sizeof(value) - 1, "%d", tech_pvt->running); stream->write_function(stream, "running = %s\n", value); + stream->write_function(stream, "subscriber_number = %s\n", tech_pvt->subscriber_number); stream->write_function(stream, "operator = %s\n", tech_pvt->operator_name); stream->write_function(stream, "imei = %s\n", tech_pvt->imei); stream->write_function(stream, "imsi = %s\n", tech_pvt->imsi); @@ -2481,6 +2482,7 @@ SWITCH_STANDARD_API(gsmopen_dump_function) stream->write_function(stream, "got_signal = %s\n", value); snprintf(value, sizeof(value) - 1, "%d", tech_pvt->running); stream->write_function(stream, "running = %s\n", value); + stream->write_function(stream, "subscriber_number = %s\n", tech_pvt->subscriber_number); stream->write_function(stream, "operator = %s\n", tech_pvt->operator_name); stream->write_function(stream, "imei = %s\n", tech_pvt->imei); stream->write_function(stream, "imsi = %s\n", tech_pvt->imsi); @@ -2811,6 +2813,7 @@ int dump_event_full(private_t *tech_pvt, int is_alarm, int alarm_code, const cha switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "got_signal", value); snprintf(value, sizeof(value) - 1, "%d", tech_pvt->running); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "running", value); + switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "subscriber_number", tech_pvt->subscriber_number); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "operator", tech_pvt->operator_name); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "imei", tech_pvt->imei); switch_event_add_header_string(event, SWITCH_STACK_BOTTOM, "imsi", tech_pvt->imsi);