summaryrefslogtreecommitdiffstats
path: root/rfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'rfs.c')
-rw-r--r--rfs.c148
1 files changed, 98 insertions, 50 deletions
diff --git a/rfs.c b/rfs.c
index da2a77e..74d5325 100644
--- a/rfs.c
+++ b/rfs.c
@@ -1,7 +1,7 @@
/*
* This file is part of Samsung-RIL.
*
- * Copyright (C) 2011-2013 Paul Kocialkowski <contact@paulk.fr>
+ * Copyright (C) 2011-2014 Paul Kocialkowski <contact@paulk.fr>
*
* Samsung-RIL is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -17,84 +17,132 @@
* along with Samsung-RIL. If not, see <http://www.gnu.org/licenses/>.
*/
+#include <stdlib.h>
+
#define LOG_TAG "RIL-RFS"
#include <utils/Log.h>
-#include "samsung-ril.h"
-#include "util.h"
+#include <samsung-ril.h>
+#include <utils.h>
-void ipc_rfs_nv_read_item(struct ipc_message_info *info)
+int ipc_rfs_nv_read_item(struct ipc_message *message)
{
- struct ipc_client *ipc_client;
+ struct ipc_rfs_nv_read_item_response_header response_header;
+ struct ipc_rfs_nv_read_item_request_data *data;
+ struct ril_client *client;
+ struct ipc_rfs_data *ipc_rfs_data;
+ void *response_data = NULL;
+ size_t response_size = 0;
+ void *nv_data = NULL;
+ int rc;
- struct ipc_rfs_io *rfs_io;
- struct ipc_rfs_io_confirm *rfs_io_conf;
+ if (message == NULL || message->data == NULL || message->size < sizeof(struct ipc_rfs_nv_read_item_request_data))
+ return -1;
- void *rfs_data;
- int rc;
+ client = ril_client_find_id(RIL_CLIENT_IPC_RFS);
+ if (client == NULL || client->data == NULL)
+ return 0;
+
+ ipc_rfs_data = (struct ipc_rfs_data *) client->data;
+ if (ipc_rfs_data->ipc_client == NULL)
+ return 0;
+
+ data = (struct ipc_rfs_nv_read_item_request_data *) message->data;
+
+ memset(&response_header, 0, sizeof(response_header));
- if (info->data == NULL || info->length < sizeof(struct ipc_rfs_io))
- return;
+ nv_data = ipc_nv_data_read(ipc_rfs_data->ipc_client, data->length, data->offset);
+ if (nv_data == NULL) {
+ RIL_LOGE("Reading %d nv_data bytes at offset 0x%x failed", data->length, data->offset);
- rfs_io = (struct ipc_rfs_io *) info->data;
+ response_header.confirm = 0;
- if (ril_data.ipc_rfs_client == NULL || ril_data.ipc_rfs_client->data == NULL)
- return;
+ rc = ipc_rfs_send(message->aseq, IPC_RFS_NV_READ_ITEM, (void *) &response_header, sizeof(response_header));
+ if (rc < 0)
+ goto complete;
- ipc_client = (struct ipc_client *) ril_data.ipc_rfs_client->data;
+ goto complete;
+ }
- rfs_io_conf = calloc(1, rfs_io->length + sizeof(struct ipc_rfs_io_confirm));
- rfs_data = rfs_io_conf + sizeof(struct ipc_rfs_io_confirm);
+ RIL_LOGD("Read %d nv_data bytes at offset 0x%x", data->length, data->offset);
- RIL_LOGD("Asked to read 0x%x bytes at offset 0x%x", rfs_io->length, rfs_io->offset);
- rc = nv_data_read(ipc_client, rfs_io->offset, rfs_io->length, rfs_data);
+ response_header.confirm = 1;
+ response_header.offset = data->offset;
+ response_header.length = data->length;
- RIL_LOGD("Read rfs_data dump:");
- hex_dump(rfs_data, rfs_io->length > 0x100 ? 0x100 : rfs_io->length);
+ response_size = ipc_rfs_nv_data_item_size_setup(&response_header, nv_data, data->length);
+ if (response_size == 0)
+ goto complete;
- RIL_LOGD("Sending RFS IO Confirm message (rc is %d)", rc);
- rfs_io_conf->confirm = rc < 0 ? 0 : 1;
- rfs_io_conf->offset = rfs_io->offset;
- rfs_io_conf->length = rfs_io->length;
+ response_data = ipc_rfs_nv_read_item_setup(&response_header, nv_data, data->length);
+ if (response_data == NULL)
+ goto complete;
- ipc_rfs_send(IPC_RFS_NV_READ_ITEM, (unsigned char *) rfs_io_conf, rfs_io->length + sizeof(struct ipc_rfs_io_confirm), info->aseq);
+ rc = ipc_rfs_send(message->aseq, IPC_RFS_NV_READ_ITEM, response_data, response_size);
+ if (rc < 0)
+ goto complete;
- free(rfs_io_conf);
+ goto complete;
+
+complete:
+ if (response_data != NULL && response_size > 0)
+ free(response_data);
+
+ if (nv_data != NULL)
+ free(nv_data);
+
+ return 0;
}
-void ipc_rfs_nv_write_item(struct ipc_message_info *info)
+int ipc_rfs_nv_write_item(struct ipc_message *message)
{
- struct ipc_client *ipc_client;
+ struct ipc_rfs_nv_write_item_request_header *header;
+ struct ipc_rfs_nv_write_item_response_data data;
+ struct ril_client *client;
+ struct ipc_rfs_data *ipc_rfs_data;
+ void *nv_data;
+ size_t nv_size;
+ int rc;
- struct ipc_rfs_io *rfs_io;
- struct ipc_rfs_io_confirm rfs_io_conf;
+ if (message == NULL || message->data == NULL || message->size < sizeof(struct ipc_rfs_nv_write_item_request_header))
+ return -1;
- void *rfs_data;
- int rc;
+ client = ril_client_find_id(RIL_CLIENT_IPC_RFS);
+ if (client == NULL || client->data == NULL)
+ return 0;
+
+ ipc_rfs_data = (struct ipc_rfs_data *) client->data;
+ if (ipc_rfs_data->ipc_client == NULL)
+ return 0;
- if (info->data == NULL || info->length < sizeof(struct ipc_rfs_io))
- return;
+ header = (struct ipc_rfs_nv_write_item_request_header *) message->data;
- rfs_io = (struct ipc_rfs_io *) info->data;
+ nv_size = ipc_rfs_nv_write_item_size_extract(message->data, message->size);
+ if (nv_size == 0)
+ return 0;
- if (ril_data.ipc_rfs_client == NULL || ril_data.ipc_rfs_client->data == NULL)
- return;
+ nv_data = ipc_rfs_nv_write_item_extract(message->data, message->size);
+ if (nv_data == NULL)
+ return 0;
- ipc_client = (struct ipc_client *) ril_data.ipc_rfs_client->data;
+ memset(&data, 0, sizeof(data));
- memset(&rfs_io_conf, 0, sizeof(rfs_io_conf));
- rfs_data = info->data + sizeof(struct ipc_rfs_io);
+ rc = ipc_nv_data_write(ipc_rfs_data->ipc_client, nv_data, header->length, header->offset);
+ if (rc < 0) {
+ RIL_LOGD("Writing %d nv_data byte(s) at offset 0x%x failed", header->length, header->offset);
- RIL_LOGD("Write rfs_data dump:");
- hex_dump(rfs_data, rfs_io->length > 0x100 ? 0x100 : rfs_io->length);
+ data.confirm = 0;
+ } else {
+ RIL_LOGD("Wrote %d nv_data byte(s) at offset 0x%x", header->length, header->offset);
- RIL_LOGD("Asked to write 0x%x bytes at offset 0x%x", rfs_io->length, rfs_io->offset);
- rc = nv_data_write(ipc_client, rfs_io->offset, rfs_io->length, rfs_data);
+ data.confirm = 1;
+ data.offset = header->offset;
+ data.length = header->length;
+ }
- RIL_LOGD("Sending RFS IO Confirm message (rc is %d)", rc);
- rfs_io_conf.confirm = rc < 0 ? 0 : 1;
- rfs_io_conf.offset = rfs_io->offset;
- rfs_io_conf.length = rfs_io->length;
+ rc = ipc_rfs_send(message->aseq, IPC_RFS_NV_WRITE_ITEM, (void *) &data, sizeof(data));
+ if (rc < 0)
+ return 0;
- ipc_rfs_send(IPC_RFS_NV_WRITE_ITEM, (unsigned char *) &rfs_io_conf, sizeof(struct ipc_rfs_io_confirm), info->aseq);
+ return 0;
}