Use to decode a final error string to error code.
---
src/common.c | 35 +++++++++++++++++++++++++++++++++++
src/common.h | 1 +
2 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/src/common.c b/src/common.c
index 4eaff5e..8fa8f8f 100644
--- a/src/common.c
+++ b/src/common.c
@@ -290,6 +290,41 @@ const char *telephony_error_to_str(const struct ofono_error *error)
return "Unknown error";
}
+static gboolean search_entry(const char *str, struct error_entry *e,
+ enum ofono_error_type type,
+ struct ofono_error *error)
+{
+ int maxentries;
+ int i;
+
+ maxentries = sizeof(e) / sizeof(struct error_entry);
+
+ for (i = 0; i < maxentries; i++) {
+ if (!strcmp(e[i].str, str)) {
+ error->type = type;
+ error->error = e[i].error;
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
+void telephony_str_to_error(const char *str, struct ofono_error *error)
+{
+ if (search_entry(str, cme_errors, OFONO_ERROR_TYPE_CME, error))
+ return;
+
+ if (search_entry(str, cms_errors, OFONO_ERROR_TYPE_CMS, error))
+ return;
+
+ if (search_entry(str, ceer_errors, OFONO_ERROR_TYPE_CEER, error))
+ return;
+
+ error->type = OFONO_ERROR_TYPE_FAILURE;
+ error->error = 0;
+}
+
int mmi_service_code_to_bearer_class(int code)
{
int cls = 0;
diff --git a/src/common.h b/src/common.h
index c43e46d..ec917d1 100644
--- a/src/common.h
+++ b/src/common.h
@@ -123,6 +123,7 @@ enum pin_type {
};
const char *telephony_error_to_str(const struct ofono_error *error);
+void telephony_str_to_error(const char *str, struct ofono_error *error);
gboolean valid_phone_number_format(const char *number);
const char *phone_number_to_string(const struct ofono_phone_number *ph);
--
1.6.3.3