mod_gsmopen: add support for reading own number from ON phonebook using AT+CNUM

This commit is contained in:
Dušan Dragić 2014-09-11 22:50:22 +02:00
parent d5f9de4fa3
commit 79d962f38e
3 changed files with 48 additions and 0 deletions

View File

@ -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];

View File

@ -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;

View File

@ -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);