summaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authorJoerie de Gram <j.de.gram@gmail.com>2011-10-26 18:03:00 +0200
committerJoerie de Gram <j.de.gram@gmail.com>2011-10-29 16:26:26 +0200
commit791fd3e4a946c05d6598f5054075515df6327b7d (patch)
treee45cfbe6eb9a9ce1515c6c1cc81e50761971ad15 /util.c
downloadhardware_ril_samsung-ril-791fd3e4a946c05d6598f5054075515df6327b7d.zip
hardware_ril_samsung-ril-791fd3e4a946c05d6598f5054075515df6327b7d.tar.gz
hardware_ril_samsung-ril-791fd3e4a946c05d6598f5054075515df6327b7d.tar.bz2
Temporary initial commit
Diffstat (limited to 'util.c')
-rw-r--r--util.c136
1 files changed, 136 insertions, 0 deletions
diff --git a/util.c b/util.c
new file mode 100644
index 0000000..3e33e0f
--- /dev/null
+++ b/util.c
@@ -0,0 +1,136 @@
+#include <stdio.h>
+#include <string.h>
+
+#define LOG_TAG "RIL-UTIL"
+#include <utils/Log.h>
+
+/**
+ * Converts a hexidecimal string to binary
+ */
+void hex2bin(const char *data, int length, unsigned char *buf)
+{
+ int i = 0;
+ char b = 0;
+ unsigned char *p = buf;
+
+ length ^= 0x01;
+
+ while(i < length) {
+ if(data[i] - '0' < 10)
+ b = data[i++] - '0';
+ else if(data[i] - 'a' < 7)
+ b = data[i++] - 'a' + 10;
+ else if(data[i] - 'A' < 7)
+ b = data[i++] - 'A' + 10;
+
+ b = (b << 4);
+
+ if(data[i] - '0' < 10)
+ b |= data[i++] - '0';
+ else if(data[i] - 'a' < 7)
+ b |= data[i++] - 'a' + 10;
+ else if(data[i] - 'A' < 7)
+ b |= data[i++] - 'A' + 10;
+
+ *p++ = b;
+ }
+}
+
+/**
+ * Converts binary data to a hexidecimal string
+ */
+void bin2hex(const unsigned char *data, int length, char *buf)
+{
+ int i;
+ char b;
+ char *p = buf;
+
+ for(i = 0; i < length; i++) {
+ b = (data[i] >> 4 & 0x0f);
+ b += (b < 10) ? '0' : ('a' - 10);
+ *p++ = b;
+
+ b = (data[i] & 0x0f);
+ b += (b < 10) ? '0' : ('a' - 10);
+ *p++ = b;
+ }
+
+ *p = '\0';
+}
+
+/**
+ * Converts IPC network registration status to Android RIL format
+ */
+unsigned char registatus_ipc2ril(unsigned char status)
+{
+ switch(status) {
+ case 1:
+ return 0;
+ case 2:
+ return 1;
+ case 3:
+ return 2;
+ case 4:
+ return 13;
+ case 5:
+ return 14;
+ case 6:
+ return 5;
+ default:
+ LOGE("%s: invalid status %d", __FUNCTION__, status);
+ return 255;
+ }
+}
+
+/**
+ * Converts IPC network access technology to Android RIL format
+ */
+unsigned char act_ipc2ril(unsigned char act)
+{
+ switch(act) {
+ case 1:
+ case 2:
+ return 1;
+ case 3:
+ return 2;
+ case 4:
+ return 3;
+ default:
+ return 0;
+ }
+}
+
+/**
+ * Converts IPC preferred network type to Android RIL format
+ */
+unsigned char modesel_ipc2ril(unsigned char mode)
+{
+ switch(mode) {
+ case 0:
+ return 7;
+ case 1:
+ case 3:
+ return 1;
+ case 2:
+ case 4:
+ return 2;
+ default:
+ return 255;
+ }
+}
+
+/**
+ * Converts Android RIL preferred network type to IPC format
+ */
+unsigned char modesel_ril2ipc(unsigned char mode)
+{
+ switch(mode) {
+ case 1:
+ return 2;
+ case 2:
+ return 3;
+ default:
+ return 1;
+ }
+}
+