Network: Added operator request
authorPaul Kocialkowski <contact@paulk.fr>
Tue, 31 Jul 2012 19:45:27 +0000 (21:45 +0200)
committerPaul Kocialkowski <contact@paulk.fr>
Tue, 31 Jul 2012 19:45:27 +0000 (21:45 +0200)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
hayes-ril.c
hayes-ril.h
network.c

index 8cbe064..b397350 100644 (file)
@@ -55,6 +55,9 @@ void ril_on_request(int request, void *data, size_t length, RIL_Token t)
                case RIL_REQUEST_REGISTRATION_STATE:
                        ril_request_registration_state(t, data, length);
                        break;
+               case RIL_REQUEST_OPERATOR:
+                       ril_request_operator(t, data, length);
+                       break;
                // Call
                case RIL_REQUEST_GET_CURRENT_CALLS:
                        ril_request_get_current_calls(t, data, length);
index 9f36697..8180089 100644 (file)
@@ -157,5 +157,6 @@ void ril_request_sim_io(RIL_Token t, void *data, size_t length);
 void ril_request_signal_strength(RIL_Token t, void *data, size_t length);
 void at_creg_unexpect(struct at_response *response);
 void ril_request_registration_state(RIL_Token t, void *data, size_t length);
+void ril_request_operator(RIL_Token t, void *data, size_t length);
 
 #endif
index 349d7a9..1188b07 100644 (file)
--- a/network.c
+++ b/network.c
@@ -298,3 +298,70 @@ void ril_request_registration_state(RIL_Token t, void *data, size_t length)
                at_send_expect_to_func("AT+CREG?", NULL, NULL, t, at_creg_expect);
        }
 }
+
+/*
+ * Operator
+ */
+
+char *at_cops_request(int index)
+{
+       struct at_response_data **response_data = NULL;
+       struct at_response *response = NULL;
+       int response_data_count = 0;
+       int status = AT_STATUS_UNDEF;
+       char *result = NULL;
+       char *data = NULL;
+
+       asprintf(&data, "3,%d", index);
+
+       status = at_send_expect_status("AT+COPS", data);
+       if(at_status_error(status))
+               goto error;
+
+       response = at_send_sync("AT+COPS?", NULL);
+       if(response == NULL || response->data == NULL || response->data_count <= 0)
+               goto error;
+
+       response_data_count = at_response_data_process(&response_data, response->data[0], strlen(response->data[0]));
+       if(response_data_count <= 0)
+               goto error;
+       if(response_data_count >= 3 && response_data[2]->type == AT_RESPONSE_DATA_STRING) {
+               result = strdup(response_data[2]->value.s);
+       }
+       at_response_data_free(response_data, response_data_count);
+
+       free(response);
+       free(data);
+LOGE(">%s<", result);
+       return result;
+
+error:
+       free(data);
+       if(response != NULL)
+               free(response);
+       if(response_data != NULL)
+               at_response_data_free(response_data, response_data_count);
+
+       return NULL;
+}
+
+void ril_request_operator(RIL_Token t, void *data, size_t length)
+{
+       char *operator[3] = { NULL };
+
+       // Reuqest long operator string
+       operator[0] = at_cops_request(0);
+       // Reuqest short operator string
+       operator[1] = at_cops_request(1);
+       // Reuqest MCC+MNC string
+       operator[2] = at_cops_request(2);
+
+       RIL_onRequestComplete(t, RIL_E_SUCCESS, operator,  sizeof(operator));
+
+       if(operator[0] != NULL)
+               free(operator[0]);
+       if(operator[1] != NULL)
+               free(operator[1]);
+       if(operator[2] != NULL)
+               free(operator[2]);
+}