aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaulK <contact@paulk.fr>2012-01-14 16:56:48 +0100
committerPaulK <contact@paulk.fr>2012-01-14 16:56:48 +0100
commitb469707433b2e306fe80b7da844fa87d284fa571 (patch)
treee4c6b40bfd738fce2304fba01b1a5af17a6b451d
parentbedac849cbc7c5bbcaffa878a2e0c1c3305b25d4 (diff)
downloadhardware_replicant_libsamsung-ipc-b469707433b2e306fe80b7da844fa87d284fa571.tar.gz
hardware_replicant_libsamsung-ipc-b469707433b2e306fe80b7da844fa87d284fa571.tar.bz2
hardware_replicant_libsamsung-ipc-b469707433b2e306fe80b7da844fa87d284fa571.zip
Modified handlers with common handlers data and device-specific functions
-rw-r--r--include/radio.h9
-rw-r--r--samsung-ipc/device/crespo/crespo_ipc.c61
-rw-r--r--samsung-ipc/device/h1/h1_ipc.c69
-rw-r--r--samsung-ipc/ipc.c106
-rw-r--r--samsung-ipc/ipc_private.h8
-rw-r--r--tools/modemctrl.c4
6 files changed, 239 insertions, 18 deletions
diff --git a/include/radio.h b/include/radio.h
index a306a81..3decc07 100644
--- a/include/radio.h
+++ b/include/radio.h
@@ -57,7 +57,7 @@ extern struct ipc_handlers ipc_default_handlers;
typedef void (*ipc_client_log_handler_cb)(const char *message, void *user_data);
typedef int (*ipc_io_handler_cb)(void *data, unsigned int size, void *io_data);
-typedef int (*ipc_handler_cb)(void *data);
+typedef int (*ipc_handler_cb)(void *io_data);
struct ipc_client *ipc_client_new(int client_type);
int ipc_client_free(struct ipc_client *client);
@@ -68,7 +68,12 @@ int ipc_client_set_handlers(struct ipc_client *client, struct ipc_handlers *hand
int ipc_client_set_io_handlers(struct ipc_client *client,
ipc_io_handler_cb read, void *read_data,
ipc_io_handler_cb write, void *write_data);
-int ipc_client_set_all_handlers_data(struct ipc_client *client, void *data);
+int ipc_client_set_handlers_common_data(struct ipc_client *client, void *data);
+void *ipc_client_get_handlers_common_data(struct ipc_client *client);
+int ipc_client_create_handlers_common_data(struct ipc_client *client);
+int ipc_client_destroy_handlers_common_data(struct ipc_client *client);
+int ipc_client_set_handlers_common_data_fd(struct ipc_client *client, int fd);
+int ipc_client_get_handlers_common_data_fd(struct ipc_client *client);
int ipc_client_bootstrap_modem(struct ipc_client *client);
int ipc_client_open(struct ipc_client *client);
diff --git a/samsung-ipc/device/crespo/crespo_ipc.c b/samsung-ipc/device/crespo/crespo_ipc.c
index 8cb0501..65f144d 100644
--- a/samsung-ipc/device/crespo/crespo_ipc.c
+++ b/samsung-ipc/device/crespo/crespo_ipc.c
@@ -595,7 +595,7 @@ int crespo_ipc_write(void *data, unsigned int size, void *io_data)
return 0;
}
-int crespo_ipc_power_on(void *data)
+int crespo_ipc_power_on(void *io_data)
{
int fd=open("/dev/modem_ctl", O_RDWR);
int rc;
@@ -617,7 +617,7 @@ int crespo_ipc_power_on(void *data)
return 0;
}
-int crespo_ipc_power_off(void *data)
+int crespo_ipc_power_off(void *io_data)
{
int fd=open("/dev/modem_ctl", O_RDWR);
int rc;
@@ -639,6 +639,58 @@ int crespo_ipc_power_off(void *data)
return 0;
}
+void *crespo_ipc_common_data_create(void)
+{
+ void *io_data;
+ int io_data_len;
+
+ io_data_len = sizeof(int);
+ io_data = malloc(io_data_len);
+
+ if(io_data == NULL)
+ return NULL;
+
+ memset(io_data, 0, io_data_len);
+
+ return io_data;
+}
+
+int crespo_ipc_common_data_destroy(void *io_data)
+{
+ // This was already done, not an error but we need to return
+ if(io_data == NULL)
+ return 0;
+
+ free(io_data);
+
+ return 0;
+}
+
+int crespo_ipc_common_data_set_fd(void *io_data, int fd)
+{
+ int *common_data;
+
+ if(io_data == NULL)
+ return -1;
+
+ common_data = (int *) io_data;
+ common_data = &fd;
+
+ return 0;
+}
+
+int crespo_ipc_common_data_get_fd(void *io_data)
+{
+ int *common_data;
+
+ if(io_data == NULL)
+ return -1;
+
+ common_data = (int *) io_data;
+
+ return (int) *(common_data);
+}
+
struct ipc_handlers ipc_default_handlers = {
.read = crespo_ipc_read,
.write = crespo_ipc_write,
@@ -646,6 +698,11 @@ struct ipc_handlers ipc_default_handlers = {
.close = crespo_ipc_close,
.power_on = crespo_ipc_power_on,
.power_off = crespo_ipc_power_off,
+ .common_data = NULL,
+ .common_data_create = crespo_ipc_common_data_create,
+ .common_data_destroy = crespo_ipc_common_data_destroy,
+ .common_data_set_fd = crespo_ipc_common_data_set_fd,
+ .common_data_get_fd = crespo_ipc_common_data_get_fd,
};
struct ipc_ops ipc_fmt_ops = {
diff --git a/samsung-ipc/device/h1/h1_ipc.c b/samsung-ipc/device/h1/h1_ipc.c
index ac229e5..8363449 100644
--- a/samsung-ipc/device/h1/h1_ipc.c
+++ b/samsung-ipc/device/h1/h1_ipc.c
@@ -65,28 +65,28 @@ int h1_ipc_close(void *io_data)
return 0;
}
-int h1_ipc_power_on(void *data)
+int h1_ipc_power_on(void *io_data)
{
int fd = -1;
- if(data == NULL)
+ if(io_data == NULL)
return -1;
- fd = *((int *) data);
+ fd = *((int *) io_data);
ioctl(fd, IOCTL_PHONE_ON);
return 0;
}
-int h1_ipc_power_off(void *data)
+int h1_ipc_power_off(void *io_data)
{
int fd = -1;
- if(data == NULL)
+ if(io_data == NULL)
return -1;
- fd = *((int *) data);
+ fd = *((int *) io_data);
ioctl(fd, IOCTL_PHONE_OFF);
@@ -211,6 +211,58 @@ int h1_ipc_write(void *data, unsigned int size, void *io_data)
return write(fd, data, size);
}
+void *h1_ipc_common_data_create(void)
+{
+ void *io_data;
+ int io_data_len;
+
+ io_data_len = sizeof(int);
+ io_data = malloc(io_data_len);
+
+ if(io_data == NULL)
+ return NULL;
+
+ memset(io_data, 0, io_data_len);
+
+ return io_data;
+}
+
+int h1_ipc_common_data_destroy(void *io_data)
+{
+ // This was already done, not an error but we need to return
+ if(io_data == NULL)
+ return 0;
+
+ free(io_data);
+
+ return 0;
+}
+
+int h1_ipc_common_data_set_fd(void *io_data, int fd)
+{
+ int *common_data;
+
+ if(io_data == NULL)
+ return -1;
+
+ common_data = (int *) io_data;
+ common_data = &fd;
+
+ return 0;
+}
+
+int h1_ipc_common_data_get_fd(void *io_data)
+{
+ int *common_data;
+
+ if(io_data == NULL)
+ return -1;
+
+ common_data = (int *) io_data;
+
+ return (int) *(common_data);
+}
+
struct ipc_handlers ipc_default_handlers = {
.open = h1_ipc_open,
.close = h1_ipc_close,
@@ -218,6 +270,11 @@ struct ipc_handlers ipc_default_handlers = {
.power_off = h1_ipc_power_off,
.read = h1_ipc_read,
.write = h1_ipc_write,
+ .common_data = NULL,
+ .common_data_create = h1_ipc_common_data_create,
+ .common_data_destroy = h1_ipc_common_data_destroy,
+ .common_data_set_fd = h1_ipc_common_data_set_fd,
+ .common_data_get_fd = h1_ipc_common_data_get_fd,
};
struct ipc_ops ipc_fmt_ops = {
diff --git a/samsung-ipc/ipc.c b/samsung-ipc/ipc.c
index 17b943b..29c8f63 100644
--- a/samsung-ipc/ipc.c
+++ b/samsung-ipc/ipc.c
@@ -117,6 +117,8 @@ int ipc_client_set_io_handlers(struct ipc_client *client,
{
if(client == NULL)
return -1;
+ if(client->handlers == NULL)
+ return -1;
if(read != NULL)
client->handlers->read = read;
@@ -130,23 +132,113 @@ int ipc_client_set_io_handlers(struct ipc_client *client,
return 0;
}
-int ipc_client_set_all_handlers_data(struct ipc_client *client, void *data)
+int ipc_client_set_handlers_common_data(struct ipc_client *client, void *data)
{
+ void *common_data;
+
if(client == NULL)
return -1;
+ if(client->handlers == NULL)
+ return -1;
if(data == NULL)
return -1;
- client->handlers->read_data = data;
- client->handlers->write_data = data;
- client->handlers->open_data = data;
- client->handlers->close_data = data;
- client->handlers->power_on_data = data;
- client->handlers->power_off_data = data;
+ common_data = data;
+ client->handlers->common_data = common_data;
+
+ client->handlers->read_data = common_data;
+ client->handlers->write_data = common_data;
+ client->handlers->open_data = common_data;
+ client->handlers->close_data = common_data;
+ client->handlers->power_on_data = common_data;
+ client->handlers->power_off_data = common_data;
+
+ return 0;
+}
+
+void *ipc_client_get_handlers_common_data(struct ipc_client *client)
+{
+ if(client == NULL)
+ return NULL;
+ if(client->handlers == NULL)
+ return -1;
+
+ return client->handlers->common_data;
+
+ return 0;
+}
+
+int ipc_client_create_handlers_common_data(struct ipc_client *client)
+{
+ void *common_data;
+
+ if(client == NULL)
+ return -1;
+ if(client->handlers == NULL)
+ return -1;
+
+ common_data = client->handlers->common_data_create();
+ client->handlers->common_data = common_data;
+
+ client->handlers->read_data = common_data;
+ client->handlers->write_data = common_data;
+ client->handlers->open_data = common_data;
+ client->handlers->close_data = common_data;
+ client->handlers->power_on_data = common_data;
+ client->handlers->power_off_data = common_data;
+
+ return 0;
+}
+
+int ipc_client_destroy_handlers_common_data(struct ipc_client *client)
+{
+ void *common_data;
+ int rc;
+
+ if(client == NULL)
+ return -1;
+ if(client->handlers == NULL)
+ return -1;
+
+ rc = client->handlers->common_data_destroy(client->handlers->common_data);
+
+ if(rc < 0)
+ return -1;
+
+ common_data = NULL;
+ client->handlers->common_data = common_data;
+
+ client->handlers->read_data = common_data;
+ client->handlers->write_data = common_data;
+ client->handlers->open_data = common_data;
+ client->handlers->close_data = common_data;
+ client->handlers->power_on_data = common_data;
+ client->handlers->power_off_data = common_data;
return 0;
}
+int ipc_client_set_handlers_common_data_fd(struct ipc_client *client, int fd)
+{
+ if(client == NULL)
+ return -1;
+ if(client->handlers == NULL)
+ return -1;
+
+ return client->handlers->common_data_set_fd(client->handlers->common_data, fd);
+}
+
+int ipc_client_get_handlers_common_data_fd(struct ipc_client *client)
+{
+ if(client == NULL)
+ return -1;
+ if(client->handlers == NULL)
+ return -1;
+
+ return client->handlers->common_data_get_fd(client->handlers->common_data);
+}
+
+
int ipc_client_bootstrap_modem(struct ipc_client *client)
{
if (client == NULL ||
diff --git a/samsung-ipc/ipc_private.h b/samsung-ipc/ipc_private.h
index 7c2787b..5e374d0 100644
--- a/samsung-ipc/ipc_private.h
+++ b/samsung-ipc/ipc_private.h
@@ -49,6 +49,14 @@ struct ipc_handlers {
void *power_on_data;
ipc_handler_cb power_off;
void *power_off_data;
+
+ /* Handlers common data*/
+ void *common_data;
+
+ void *(*common_data_create)(void);
+ int (*common_data_destroy)(void *io_data);
+ int (*common_data_set_fd)(void *io_data, int fd);
+ int (*common_data_get_fd)(void *io_data);
};
struct ipc_client {
diff --git a/tools/modemctrl.c b/tools/modemctrl.c
index dc7eaaa..75cfc83 100644
--- a/tools/modemctrl.c
+++ b/tools/modemctrl.c
@@ -440,7 +440,7 @@ int modem_start(struct ipc_client *client)
int rc = -1;
// ipc_client_set_handlers(client, &ipc_default_handlers);
- ipc_client_set_all_handlers_data(client, &client_fd);
+ ipc_client_create_handlers_common_data(client);
ipc_client_bootstrap_modem(client);
@@ -450,6 +450,8 @@ int modem_start(struct ipc_client *client)
if(rc < 0)
return -1;
+ client_fd = ipc_client_get_handlers_common_data_fd(client);
+
rc = ipc_client_power_on(client);
if(rc < 0)
return -1;