]> git.ipfire.org Git - thirdparty/freeswitch.git/commitdiff
mod_gsmopen: add support for reading own number from ON phonebook using AT+CNUM
authorDušan Dragić <dragic.dusan@gmail.com>
Thu, 11 Sep 2014 20:50:22 +0000 (22:50 +0200)
committerDušan Dragić <dragic.dusan@gmail.com>
Sun, 21 Sep 2014 18:04:04 +0000 (20:04 +0200)
src/mod/endpoints/mod_gsmopen/gsmopen.h
src/mod/endpoints/mod_gsmopen/gsmopen_protocol.cpp
src/mod/endpoints/mod_gsmopen/mod_gsmopen.cpp

index 6ba413e3b1cc987244a465ec5459f06a385f472a..97731c676d661b8da202c520758b40be933b4d07 100644 (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];
 
index 7533e40a5ba4f7ef635af933002bd9577233d178..5f0efb912118f6dac5aafb62973e796e7001c871 100644 (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;
 
index 73478826e7f049f2113f5dea1fbd29a90ea8d7c6..c9af03e3b12b7fb7b89403d147daeb9ebc06c229 100644 (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);