Initial commit: Started Hayes (AT command set) RIL
authorPaul Kocialkowski <contact@paulk.fr>
Sun, 12 Feb 2012 18:27:07 +0000 (19:27 +0100)
committerPaul Kocialkowski <contact@paulk.fr>
Wed, 18 Jul 2012 14:32:59 +0000 (16:32 +0200)
Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Android.mk [new file with mode: 0644]
MODULE_LICENSE_APACHE2 [new file with mode: 0644]
device.c [new file with mode: 0644]
device/dream_sapphire/dream_sapphire.c [new file with mode: 0644]
device/passion/passion.c [new file with mode: 0644]
hayes-ril.c [new file with mode: 0644]
hayes-ril.h [new file with mode: 0644]

diff --git a/Android.mk b/Android.mk
new file mode 100644 (file)
index 0000000..27684ab
--- /dev/null
@@ -0,0 +1,45 @@
+# This file is part of hayes-ril.
+#
+# Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+#     http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+LOCAL_PATH:= $(call my-dir)
+include $(CLEAR_VARS)
+
+hayes_ril_files := \
+       hayes-ril.c \
+       device.c
+
+ifeq ($(TARGET_DEVICE),passion)
+       hayes_ril_device_files := device/passion/passion.c
+       LOCAL_C_INCLUDES += $(LOCAL_PATH)/device/passion/
+endif
+
+ifeq ($(TARGET_DEVICE),dream_sapphire)
+       hayes_ril_device_files := device/dream_sapphire/dream_sapphire.c
+       LOCAL_C_INCLUDES += $(LOCAL_PATH)/device/dream_sapphire/
+endif
+
+LOCAL_SRC_FILES := $(hayes_ril_files) $(hayes_ril_device_files)
+LOCAL_SHARED_LIBRARIES += libcutils libutils
+LOCAL_PRELINK_MODULE := false
+
+LOCAL_C_INCLUDES += $(KERNEL_HEADERS) $(LOCAL_PATH)
+LOCAL_LDLIBS += -lpthread
+LOCAL_CFLAGS += -DRIL_SHLIB -D_GNU_SOURCE
+
+LOCAL_MODULE_TAGS := optional
+LOCAL_MODULE:= libhayes-ril
+
+include $(BUILD_SHARED_LIBRARY)
diff --git a/MODULE_LICENSE_APACHE2 b/MODULE_LICENSE_APACHE2
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/device.c b/device.c
new file mode 100644 (file)
index 0000000..c8a080f
--- /dev/null
+++ b/device.c
@@ -0,0 +1,173 @@
+/**
+ * This file is part of hayes-ril.
+ *
+ * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "RIL-DEV"
+#include <utils/Log.h>
+
+#include <hayes-ril.h>
+
+// Create shared data for all the handlers
+int ril_device_data_create(struct ril_device *ril_device_p)
+{
+       int rc;
+
+       if(ril_device_p->handlers == NULL) {
+               LOGE("Missing device handlers!");
+               return -1;
+       }
+
+       if(ril_device_p->handlers->power == NULL) {
+               LOGE("Missing device power handlers!");
+               return -1;
+       }
+
+       if(ril_device_p->handlers->power->data_create == NULL ||
+               ril_device_p->handlers->power->data_destroy == NULL) {
+               LOGE("Missing device power data handlers!");
+               return -1;
+       }
+
+       if(ril_device_p->handlers->transport == NULL) {
+               LOGE("Missing device transport handlers!");
+               return -1;
+       }
+
+       if(ril_device_p->handlers->transport->data_create == NULL ||
+               ril_device_p->handlers->transport->data_destroy == NULL) {
+               LOGE("Missing device transport data handlers!");
+               return -1;
+       }
+
+       // iface
+
+       LOGD("Creating data for transport handlers...");
+
+       rc = ril_device_p->handlers->power->data_create(ril_device_p->handlers->power->data);
+       if(rc < 0) {
+               LOGE("Creating data for power handlers failed!");
+               return -1;
+       }
+
+       ril_device_p->handlers->transport->data_create(ril_device_p->handlers->transport->data);
+       if(rc < 0) {
+               LOGE("Creating data for transport handlers failed!");
+               return -1;
+       }
+
+       return 0;
+}
+
+int ril_device_boot(struct ril_device *ril_device_p)
+{
+       int rc;
+
+       if(ril_device_p->handlers == NULL) {
+               LOGE("Missing device handlers!");
+               return -1;
+       }
+
+       if(ril_device_p->handlers->power == NULL) {
+               LOGE("Missing device power handlers!");
+               return -1;
+       }
+
+       if(ril_device_p->handlers->power->boot == NULL) {
+               LOGE("Missing device power boot handler!");
+               return -1;
+       }
+
+       LOGD("Booting modem...");
+
+       rc = ril_device_p->handlers->power->boot(ril_device_p->handlers->power->data);
+       return rc;
+}
+
+int ril_device_power_on(struct ril_device *ril_device_p)
+{
+       int rc;
+
+       if(ril_device_p->handlers == NULL) {
+               LOGE("Missing device handlers!");
+               return -1;
+       }
+
+       if(ril_device_p->handlers->power == NULL) {
+               LOGE("Missing device power handlers!");
+               return -1;
+       }
+
+       if(ril_device_p->handlers->power->power_on == NULL) {
+               LOGE("Missing device power on handler!");
+               return -1;
+       }
+
+       LOGD("Powering modem on...");
+
+       rc = ril_device_p->handlers->power->power_on(ril_device_p->handlers->power->data);
+       return rc;
+}
+
+int ril_device_power_off(struct ril_device *ril_device_p)
+{
+       int rc;
+
+       if(ril_device_p->handlers == NULL) {
+               LOGE("Missing device handlers!");
+               return -1;
+       }
+
+       if(ril_device_p->handlers->power == NULL) {
+               LOGE("Missing device power handlers!");
+               return -1;
+       }
+
+       if(ril_device_p->handlers->power->power_off == NULL) {
+               LOGE("Missing device power off handler!");
+               return -1;
+       }
+
+       LOGD("Powering modem off...");
+
+       rc = ril_device_p->handlers->power->power_off(ril_device_p->handlers->power->data);
+       return rc;
+}
+
+int ril_device_open(struct ril_device *ril_device_p)
+{
+       int rc;
+
+       if(ril_device_p->handlers == NULL) {
+               LOGE("Missing device handlers!");
+               return -1;
+       }
+
+       if(ril_device_p->handlers->transport == NULL) {
+               LOGE("Missing device transport handlers!");
+               return -1;
+       }
+
+       if(ril_device_p->handlers->transport->open == NULL) {
+               LOGE("Missing device transport open handler!");
+               return -1;
+       }
+
+       LOGD("Opening modem...");
+
+       rc = ril_device_p->handlers->transport->open(ril_device_p->handlers->transport->data);
+       return rc;
+}
diff --git a/device/dream_sapphire/dream_sapphire.c b/device/dream_sapphire/dream_sapphire.c
new file mode 100644 (file)
index 0000000..461023a
--- /dev/null
@@ -0,0 +1,29 @@
+/**
+ * This file is part of hayes-ril.
+ *
+ * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hayes-ril.h>
+
+struct ril_device dream_sapphire_device = {
+       .name = "HTC Dream/HTC Magic",
+       .type = DEV_GSM,
+};
+
+void ril_device_register(struct ril_device **ril_device_p)
+{
+       *ril_device_p = &dream_sapphire_device;
+}
diff --git a/device/passion/passion.c b/device/passion/passion.c
new file mode 100644 (file)
index 0000000..9f852d6
--- /dev/null
@@ -0,0 +1,29 @@
+/**
+ * This file is part of hayes-ril.
+ *
+ * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <hayes-ril.h>
+
+struct ril_device passion_device = {
+       .name = "Nexus One",
+       .type = DEV_GSM,
+};
+
+void ril_device_register(struct ril_device **ril_device_p)
+{
+       *ril_device_p = &passion_device;
+}
diff --git a/hayes-ril.c b/hayes-ril.c
new file mode 100644 (file)
index 0000000..0ec85f6
--- /dev/null
@@ -0,0 +1,82 @@
+/**
+ * This file is part of hayes-ril.
+ *
+ * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
+ * 
+ * Based on htcgeneric-ril, reference-ril:
+ * Copyright 2006-2011, htcgeneric-ril contributors
+ * Copyright 2006, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define LOG_TAG "RIL"
+#include <utils/Log.h>
+#include <telephony/ril.h>
+
+#include <hayes-ril.h>
+
+#define RIL_VERSION_STRING "Hayes RIL"
+
+struct ril_device *ril_device;
+
+const char *getVersion(void)
+{
+       return RIL_VERSION_STRING;
+}
+
+
+static const RIL_RadioFunctions ril_ops = {
+       RIL_VERSION,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       getVersion
+};
+
+
+const RIL_RadioFunctions *RIL_Init(const struct RIL_Env *env, int argc, char **argv)
+{
+       int rc;
+
+       ril_device_register(&ril_device);
+
+       LOGD("Starting %s for device: %s", RIL_VERSION_STRING, ril_device->name);
+
+       rc = ril_device_data_create(ril_device);
+       if(rc < 0) {
+               goto failure;
+       }
+
+       rc = ril_device_boot(ril_device);
+       if(rc < 0) {
+               goto failure;
+       }
+
+       rc = ril_device_power_on(ril_device);
+       if(rc < 0) {
+               goto failure;
+       }
+
+       rc = ril_device_open(ril_device);
+       if(rc < 0) {
+               goto failure;
+       }
+
+       return &ril_ops;
+
+failure:
+       LOGE("Failure, aborting!");
+       return NULL;
+}
diff --git a/hayes-ril.h b/hayes-ril.h
new file mode 100644 (file)
index 0000000..e410476
--- /dev/null
@@ -0,0 +1,85 @@
+/**
+ * This file is part of hayes-ril.
+ *
+ * Copyright (C) 2012 Paul Kocialkowski <contact@paulk.fr>
+ * 
+ * Based on htcgeneric-ril, reference-ril:
+ * Copyright 2006-2011, htcgeneric-ril contributors
+ * Copyright 2006, The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef _HAYES_RIL_H_
+#define _HAYES_RIL_H_
+
+#define DEV_GSM                RIL_DEVICE_TYPE_GSM
+#define DEV_CDMA       RIL_DEVICE_TYPE_CDMA
+
+extern struct ril_device *ril_device;
+
+enum ril_device_type {
+       RIL_DEVICE_TYPE_GSM,
+       RIL_DEVICE_TYPE_CDMA
+};
+
+struct ril_device_power_handlers {
+       void *data;
+       int (*data_create)(void **data);
+       int (*data_destroy)(void *data);
+
+       int (*power_on)(void *data);
+       int (*power_off)(void *data);
+
+       int (*suspend)(void *data);
+       int (*resume)(void *data);
+
+       int (*boot)(void *data);
+};
+
+struct ril_device_transport_handlers {
+       void *data;
+       int (*data_create)(void **data);
+       int (*data_destroy)(void *data);
+
+       int (*open)(void *data);
+       int (*close)(void *data);
+
+       int (*send)(void *data);
+       int (*recv)(void *data);
+
+       int (*poll)(void *data);
+};
+
+struct ril_device_handlers {
+       struct ril_device_power_handlers *power;
+       struct ril_device_transport_handlers *transport;
+};
+
+struct ril_device {
+       char *name;
+       void *data;
+
+       enum ril_device_type type;
+       struct ril_device_handlers *handlers;
+};
+
+// Device
+void ril_device_register(struct ril_device **ril_device_p);
+int ril_device_data_create(struct ril_device*ril_device_p);
+int ril_device_boot(struct ril_device*ril_device_p);
+int ril_device_power_on(struct ril_device *ril_device_p);
+int ril_device_power_off(struct ril_device *ril_device_p);
+int ril_device_open(struct ril_device *ril_device_p);
+
+#endif