aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2012-07-04 23:25:21 +0200
committerPaul Kocialkowski <contact@paulk.fr>2012-07-04 23:25:21 +0200
commit645a8aa548c7777134cfb505f5ea85bc4cbdcf19 (patch)
treee98988f6f60effad0b58fc85a949cba21405d1cb
parent0b6def0105a1c11eeb728f289045412bddfd2bad (diff)
downloadexternal_libsamsung-ipc-645a8aa548c7777134cfb505f5ea85bc4cbdcf19.zip
external_libsamsung-ipc-645a8aa548c7777134cfb505f5ea85bc4cbdcf19.tar.gz
external_libsamsung-ipc-645a8aa548c7777134cfb505f5ea85bc4cbdcf19.tar.bz2
Reworked nv_data handling in nv_data_specs, moved some functions to gprs_specs
nv_data: * Reworked device-specific nv_data passthrough functions * Moved default values in rfs.h * Added more specific infos (size, chunk size, secret) * Applied to xmm6260 device gprs: * Moved non-io-related gprs handlers to gprs_specs * Applied to crespo, aries and xmm6260 devices Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
-rw-r--r--include/rfs.h17
-rw-r--r--samsung-ipc/device/aries/aries_ipc.c31
-rw-r--r--samsung-ipc/device/crespo/crespo_ipc.c33
-rw-r--r--samsung-ipc/device/xmm6260/xmm6260_ipc.c38
-rw-r--r--samsung-ipc/ipc.c20
-rw-r--r--samsung-ipc/ipc_devices.c33
-rw-r--r--samsung-ipc/ipc_devices.h35
-rw-r--r--samsung-ipc/ipc_private.h17
-rw-r--r--samsung-ipc/rfs.c179
9 files changed, 230 insertions, 173 deletions
diff --git a/include/rfs.h b/include/rfs.h
index fc61069..6c2fa63 100644
--- a/include/rfs.h
+++ b/include/rfs.h
@@ -27,8 +27,14 @@ struct ipc_message_info;
#define IPC_RFS_NV_READ_ITEM 0x4201
#define IPC_RFS_NV_WRITE_ITEM 0x4202
-#define NV_DATA_MD5_SECRET "Samsung_Android_RIL"
-#define NV_DATA_SIZE 0x200000
+#define NV_DATA_PATH_DEFAULT "/efs/nv_data.bin"
+#define NV_DATA_MD5_PATH_DEFAULT "/efs/nv_data.bin.md5"
+#define NV_DATA_BAK_PATH_DEFAULT "/efs/.nv_data.bak"
+#define NV_DATA_MD5_BAK_PATH_DEFAULT "/efs/.nv_data.bak.md5"
+#define NV_STATE_PATH_DEFAULT "/efs/.nv_state"
+#define NV_DATA_SECRET_DEFAULT "Samsung_Android_RIL"
+#define NV_DATA_SIZE_DEFAULT 0x200000
+#define NV_DATA_CHUNK_SIZE_DEFAULT 0x1000
#define MD5_STRING_SIZE MD5_DIGEST_LENGTH * 2 + 1
@@ -46,11 +52,14 @@ struct ipc_rfs_io_confirm {
void md5hash2string(char *out, uint8_t *in);
char *nv_data_path(struct ipc_client *client);
char *nv_data_md5_path(struct ipc_client *client);
-char *nv_state_path(struct ipc_client *client);
char *nv_data_bak_path(struct ipc_client *client);
char *nv_data_md5_bak_path(struct ipc_client *client);
+char *nv_state_path(struct ipc_client *client);
+char *nv_data_secret(struct ipc_client *client);
+int nv_data_size(struct ipc_client *client);
+int nv_data_chunk_size(struct ipc_client *client);
void nv_data_generate(struct ipc_client *client);
-void nv_data_md5_compute(void *data_p, int size, void *hash);
+void nv_data_md5_compute(void *data_p, int size, char *secret, void *hash);
void nv_data_md5_generate(struct ipc_client *client);
void nv_data_backup_create(struct ipc_client *client);
void nv_data_backup_restore(struct ipc_client *client);
diff --git a/samsung-ipc/device/aries/aries_ipc.c b/samsung-ipc/device/aries/aries_ipc.c
index 4e065ef..5ae509f 100644
--- a/samsung-ipc/device/aries/aries_ipc.c
+++ b/samsung-ipc/device/aries/aries_ipc.c
@@ -364,12 +364,12 @@ boot_loop_start:
/* Write nv_data.bin to modem_ctl. */
ipc_client_log(client, "aries_ipc_bootstrap: write nv_data to onedram");
- nv_data_p = ipc_file_read(client, "/efs/nv_data.bin", NV_DATA_SIZE, 1024);
+ nv_data_p = ipc_file_read(client, nv_data_path(client), nv_data_size(client), nv_data_chunk_size(client));
if (nv_data_p == NULL)
goto error;
data_p = nv_data_p;
- memcpy(onedram_p + RADIO_IMG_MAX_SIZE, data_p, NV_DATA_SIZE);
+ memcpy(onedram_p + RADIO_IMG_MAX_SIZE, data_p, nv_data_size(client));
free(nv_data_p);
@@ -993,6 +993,18 @@ int aries_ipc_common_data_get_fd(void *io_data)
return common_data->fd;
}
+struct ipc_ops aries_fmt_ops = {
+ .send = aries_ipc_fmt_client_send,
+ .recv = aries_ipc_fmt_client_recv,
+ .bootstrap = aries_modem_bootstrap,
+};
+
+struct ipc_ops aries_rfs_ops = {
+ .send = aries_ipc_rfs_client_send,
+ .recv = aries_ipc_rfs_client_recv,
+ .bootstrap = NULL,
+};
+
struct ipc_handlers aries_default_handlers = {
.read = aries_ipc_read,
.write = aries_ipc_write,
@@ -1002,8 +1014,6 @@ struct ipc_handlers aries_default_handlers = {
.power_off = aries_ipc_power_off,
.gprs_activate = aries_ipc_gprs_activate,
.gprs_deactivate = aries_ipc_gprs_deactivate,
- .gprs_get_iface = aries_ipc_gprs_get_iface,
- .gprs_get_capabilities = aries_ipc_gprs_get_capabilities,
.common_data = NULL,
.common_data_create = aries_ipc_common_data_create,
.common_data_destroy = aries_ipc_common_data_destroy,
@@ -1011,16 +1021,9 @@ struct ipc_handlers aries_default_handlers = {
.common_data_get_fd = aries_ipc_common_data_get_fd,
};
-struct ipc_ops aries_fmt_ops = {
- .send = aries_ipc_fmt_client_send,
- .recv = aries_ipc_fmt_client_recv,
- .bootstrap = aries_modem_bootstrap,
-};
-
-struct ipc_ops aries_rfs_ops = {
- .send = aries_ipc_rfs_client_send,
- .recv = aries_ipc_rfs_client_recv,
- .bootstrap = NULL,
+struct ipc_gprs_specs aries_gprs_specs = {
+ .gprs_get_iface = aries_ipc_gprs_get_iface,
+ .gprs_get_capabilities = aries_ipc_gprs_get_capabilities,
};
// vim:ts=4:sw=4:expandtab
diff --git a/samsung-ipc/device/crespo/crespo_ipc.c b/samsung-ipc/device/crespo/crespo_ipc.c
index a25c7c7..1efe9b0 100644
--- a/samsung-ipc/device/crespo/crespo_ipc.c
+++ b/samsung-ipc/device/crespo/crespo_ipc.c
@@ -275,7 +275,7 @@ boot_loop_start:
/* Write nv_data.bin to modem_ctl. */
ipc_client_log(client, "crespo_ipc_bootstrap: write nv_data to modem_ctl");
- nv_data_p = ipc_file_read(client, "/efs/nv_data.bin", NV_DATA_SIZE, 1024);
+ nv_data_p = ipc_file_read(client, nv_data_path(client), nv_data_size(client), nv_data_chunk_size(client));
if (nv_data_p == NULL)
goto error;
data_p = nv_data_p;
@@ -284,8 +284,8 @@ boot_loop_start:
for(i=0 ; i < 2 ; i++)
{
- write(modem_ctl_fd, data_p, NV_DATA_SIZE / 2);
- data_p += NV_DATA_SIZE / 2;
+ write(modem_ctl_fd, data_p, nv_data_size(client) / 2);
+ data_p += nv_data_size(client) / 2;
}
free(nv_data_p);
@@ -709,6 +709,18 @@ int crespo_ipc_common_data_get_fd(void *io_data)
return (int) *(common_data);
}
+struct ipc_ops crespo_fmt_ops = {
+ .send = crespo_ipc_fmt_client_send,
+ .recv = crespo_ipc_fmt_client_recv,
+ .bootstrap = crespo_modem_bootstrap,
+};
+
+struct ipc_ops crespo_rfs_ops = {
+ .send = crespo_ipc_rfs_client_send,
+ .recv = crespo_ipc_rfs_client_recv,
+ .bootstrap = NULL,
+};
+
struct ipc_handlers crespo_default_handlers = {
.read = crespo_ipc_read,
.write = crespo_ipc_write,
@@ -716,8 +728,6 @@ struct ipc_handlers crespo_default_handlers = {
.close = crespo_ipc_close,
.power_on = crespo_ipc_power_on,
.power_off = crespo_ipc_power_off,
- .gprs_get_iface = crespo_ipc_gprs_get_iface,
- .gprs_get_capabilities = crespo_ipc_gprs_get_capabilities,
.common_data = NULL,
.common_data_create = crespo_ipc_common_data_create,
.common_data_destroy = crespo_ipc_common_data_destroy,
@@ -725,16 +735,9 @@ struct ipc_handlers crespo_default_handlers = {
.common_data_get_fd = crespo_ipc_common_data_get_fd,
};
-struct ipc_ops crespo_fmt_ops = {
- .send = crespo_ipc_fmt_client_send,
- .recv = crespo_ipc_fmt_client_recv,
- .bootstrap = crespo_modem_bootstrap,
-};
-
-struct ipc_ops crespo_rfs_ops = {
- .send = crespo_ipc_rfs_client_send,
- .recv = crespo_ipc_rfs_client_recv,
- .bootstrap = NULL,
+struct ipc_gprs_specs crespo_gprs_specs = {
+ .gprs_get_iface = crespo_ipc_gprs_get_iface,
+ .gprs_get_capabilities = crespo_ipc_gprs_get_capabilities,
};
// vim:ts=4:sw=4:expandtab
diff --git a/samsung-ipc/device/xmm6260/xmm6260_ipc.c b/samsung-ipc/device/xmm6260/xmm6260_ipc.c
index 4d2cb21..2c1a0a5 100644
--- a/samsung-ipc/device/xmm6260/xmm6260_ipc.c
+++ b/samsung-ipc/device/xmm6260/xmm6260_ipc.c
@@ -418,22 +418,6 @@ int xmm6260_ipc_common_data_get_fd(void *io_data)
return (int) *(common_data);
}
-struct ipc_handlers xmm6260_default_handlers = {
- .read = xmm6260_ipc_read,
- .write = xmm6260_ipc_write,
- .open = xmm6260_ipc_open,
- .close = xmm6260_ipc_close,
- .power_on = xmm6260_ipc_power_on,
- .power_off = xmm6260_ipc_power_off,
- .gprs_get_iface = xmm6260_ipc_gprs_get_iface,
- .gprs_get_capabilities = xmm6260_ipc_gprs_get_capabilities,
- .common_data = NULL,
- .common_data_create = xmm6260_ipc_common_data_create,
- .common_data_destroy = xmm6260_ipc_common_data_destroy,
- .common_data_set_fd = xmm6260_ipc_common_data_set_fd,
- .common_data_get_fd = xmm6260_ipc_common_data_get_fd,
-};
-
struct ipc_ops xmm6260_i9100_fmt_ops = {
.send = xmm6260_ipc_send,
.recv = xmm6260_ipc_recv,
@@ -452,7 +436,27 @@ struct ipc_ops xmm6260_rfs_ops = {
.bootstrap = NULL,
};
-struct ipc_fs_ops xmm6260_i9250_fs_ops = {
+struct ipc_handlers xmm6260_default_handlers = {
+ .read = xmm6260_ipc_read,
+ .write = xmm6260_ipc_write,
+ .open = xmm6260_ipc_open,
+ .close = xmm6260_ipc_close,
+ .power_on = xmm6260_ipc_power_on,
+ .power_off = xmm6260_ipc_power_off,
+ .common_data = NULL,
+ .common_data_create = xmm6260_ipc_common_data_create,
+ .common_data_destroy = xmm6260_ipc_common_data_destroy,
+ .common_data_set_fd = xmm6260_ipc_common_data_set_fd,
+ .common_data_get_fd = xmm6260_ipc_common_data_get_fd,
+};
+
+struct ipc_gprs_specs xmm6260_gprs_specs = {
+ .gprs_get_iface = xmm6260_ipc_gprs_get_iface,
+ .gprs_get_capabilities = xmm6260_ipc_gprs_get_capabilities,
+};
+
+
+struct ipc_nv_data_specs xmm6260_nv_data_specs = {
.nv_data_path = "/factory/nv_data.bin",
.nv_data_md5_path = "/factory/nv_data.bin.md5",
.nv_state_path = "/factory/.nv_state",
diff --git a/samsung-ipc/ipc.c b/samsung-ipc/ipc.c
index d7a1b67..c1139ec 100644
--- a/samsung-ipc/ipc.c
+++ b/samsung-ipc/ipc.c
@@ -140,9 +140,10 @@ struct ipc_client* ipc_client_new(int client_type)
break;
}
- client->fs_ops = ipc_devices[device_index].fs_ops;
-
client->handlers = (struct ipc_handlers *) malloc(sizeof(struct ipc_handlers));
+ client->gprs_specs = ipc_devices[device_index].gprs_specs;
+ client->nv_data_specs = ipc_devices[device_index].nv_data_specs;
+
client->log_handler = log_handler_default;
if (ipc_devices[device_index].handlers != 0)
@@ -370,8 +371,7 @@ int ipc_client_gprs_handlers_available(struct ipc_client *client)
return -1;
if(client->handlers->gprs_activate != NULL &&
- client->handlers->gprs_deactivate != NULL &&
- client->handlers->gprs_get_iface != NULL)
+ client->handlers->gprs_deactivate != NULL)
return 1;
else
return 0;
@@ -400,21 +400,21 @@ int ipc_client_gprs_deactivate(struct ipc_client *client)
int ipc_client_gprs_get_iface(struct ipc_client *client, char **iface)
{
if (client == NULL ||
- client->handlers == NULL ||
- client->handlers->gprs_get_iface == NULL)
+ client->gprs_specs == NULL ||
+ client->gprs_specs->gprs_get_iface == NULL)
return -1;
- return client->handlers->gprs_get_iface(iface);
+ return client->gprs_specs->gprs_get_iface(iface);
}
int ipc_client_gprs_get_capabilities(struct ipc_client *client, struct ipc_client_gprs_capabilities *cap)
{
if (client == NULL ||
- client->handlers == NULL ||
- client->handlers->gprs_get_capabilities == NULL)
+ client->gprs_specs == NULL ||
+ client->gprs_specs->gprs_get_capabilities == NULL)
return -1;
- return client->handlers->gprs_get_capabilities(cap);
+ return client->gprs_specs->gprs_get_capabilities(cap);
}
int _ipc_client_send(struct ipc_client *client, struct ipc_message_info *request)
diff --git a/samsung-ipc/ipc_devices.c b/samsung-ipc/ipc_devices.c
index cb76461..f686ba7 100644
--- a/samsung-ipc/ipc_devices.c
+++ b/samsung-ipc/ipc_devices.c
@@ -22,54 +22,63 @@
#include "ipc_devices.h"
+ struct ipc_gprs_specs *gprs_specs;
+ struct ipc_nv_data_specs *nv_data_specs;
+
struct ipc_device_desc ipc_devices[] = {
{
.name = "crespo",
.board_name = "herring",
- .handlers = &crespo_default_handlers,
.fmt_ops = &crespo_fmt_ops,
.rfs_ops = &crespo_rfs_ops,
- .fs_ops = NULL,
+ .handlers = &crespo_default_handlers,
+ .gprs_specs = &crespo_gprs_specs,
+ .nv_data_specs = NULL,
},
{
.name = "aries",
.board_name = "aries",
- .handlers = &aries_default_handlers,
.fmt_ops = &aries_fmt_ops,
.rfs_ops = &aries_rfs_ops,
- .fs_ops = NULL,
+ .handlers = &aries_default_handlers,
+ .gprs_specs = &aries_gprs_specs,
+ .nv_data_specs = NULL,
},
{
.name = "aries",
.board_name = "gt-p1000",
- .handlers = &aries_default_handlers,
.fmt_ops = &aries_fmt_ops,
.rfs_ops = &aries_rfs_ops,
- .fs_ops = NULL,
+ .handlers = &aries_default_handlers,
+ .gprs_specs = &aries_gprs_specs,
+ .nv_data_specs = NULL,
},
{
.name = "galaxys2",
.board_name = "i9100",
- .handlers = &xmm6260_default_handlers,
.fmt_ops = &xmm6260_i9100_fmt_ops,
.rfs_ops = &xmm6260_rfs_ops,
- .fs_ops = NULL,
+ .handlers = &xmm6260_default_handlers,
+ .gprs_specs = &xmm6260_gprs_specs,
+ .nv_data_specs = NULL,
},
{
.name = "galaxys2",
.board_name = "smdk4210",
- .handlers = &xmm6260_default_handlers,
.fmt_ops = &xmm6260_i9100_fmt_ops,
.rfs_ops = &xmm6260_rfs_ops,
- .fs_ops = NULL,
+ .handlers = &xmm6260_default_handlers,
+ .gprs_specs = &xmm6260_gprs_specs,
+ .nv_data_specs = NULL,
},
{
.name = "maguro",
.board_name = "tuna",
- .handlers = &xmm6260_default_handlers,
.fmt_ops = &xmm6260_i9250_fmt_ops,
.rfs_ops = &xmm6260_rfs_ops,
- .fs_ops = &xmm6260_i9250_fs_ops,
+ .handlers = &xmm6260_default_handlers,
+ .gprs_specs = &xmm6260_gprs_specs,
+ .nv_data_specs = &xmm6260_nv_data_specs,
}
};
diff --git a/samsung-ipc/ipc_devices.h b/samsung-ipc/ipc_devices.h
index 6c987f4..a780c98 100644
--- a/samsung-ipc/ipc_devices.h
+++ b/samsung-ipc/ipc_devices.h
@@ -27,41 +27,46 @@ struct ipc_device_desc {
char *name;
char *board_name;
- struct ipc_handlers *handlers;
struct ipc_ops *fmt_ops;
struct ipc_ops *rfs_ops;
- struct ipc_fs_ops *fs_ops;
+ struct ipc_handlers *handlers;
+ struct ipc_gprs_specs *gprs_specs;
+ struct ipc_nv_data_specs *nv_data_specs;
};
extern struct ipc_device_desc ipc_devices[];
extern int ipc_devices_count;
-// xmm6260
-// Galaxy S2 (I9100)
-// Galaxy Nexus (I9250)
-
-extern struct ipc_handlers xmm6260_default_handlers;
-extern struct ipc_ops xmm6260_rfs_ops;
-extern struct ipc_ops xmm6260_i9100_fmt_ops;
-extern struct ipc_ops xmm6260_i9250_fmt_ops;
-extern struct ipc_fs_ops xmm6260_i9250_fs_ops;
-
// h1
-extern struct ipc_handlers h1_default_handlers;
extern struct ipc_ops h1_fmt_ops;
extern struct ipc_ops h1_rfs_ops;
+extern struct ipc_handlers h1_default_handlers;
// crespo
-extern struct ipc_handlers crespo_default_handlers;
extern struct ipc_ops crespo_fmt_ops;
extern struct ipc_ops crespo_rfs_ops;
+extern struct ipc_handlers crespo_default_handlers;
+extern struct ipc_gprs_specs crespo_gprs_specs;
// aries
-extern struct ipc_handlers aries_default_handlers;
+
extern struct ipc_ops aries_fmt_ops;
extern struct ipc_ops aries_rfs_ops;
+extern struct ipc_handlers aries_default_handlers;
+extern struct ipc_gprs_specs aries_gprs_specs;
+
+// xmm6260
+// Galaxy S2 (I9100)
+// Galaxy Nexus (I9250)
+
+extern struct ipc_handlers xmm6260_default_handlers;
+extern struct ipc_ops xmm6260_rfs_ops;
+extern struct ipc_ops xmm6260_i9100_fmt_ops;
+extern struct ipc_ops xmm6260_i9250_fmt_ops;
+extern struct ipc_gprs_specs xmm6260_gprs_specs;
+extern struct ipc_gprs_specs xmm6260_nv_data_specs;
#endif
diff --git a/samsung-ipc/ipc_private.h b/samsung-ipc/ipc_private.h
index 650ac98..6db8df3 100644
--- a/samsung-ipc/ipc_private.h
+++ b/samsung-ipc/ipc_private.h
@@ -51,8 +51,6 @@ struct ipc_handlers {
void *gprs_activate_data;
ipc_handler_cb gprs_deactivate;
void *gprs_deactivate_data;
- int (*gprs_get_iface)(char **iface);
- int (*gprs_get_capabilities)(struct ipc_client_gprs_capabilities *cap);
/* Handlers common data*/
void *common_data;
@@ -63,12 +61,20 @@ struct ipc_handlers {
int (*common_data_get_fd)(void *io_data);
};
-struct ipc_fs_ops {
+struct ipc_gprs_specs {
+ int (*gprs_get_iface)(char **iface);
+ int (*gprs_get_capabilities)(struct ipc_client_gprs_capabilities *cap);
+};
+
+struct ipc_nv_data_specs {
char *nv_data_path;
char *nv_data_md5_path;
- char *nv_state_path;
char *nv_data_bak_path;
char *nv_data_md5_bak_path;
+ char *nv_state_path;
+ char *nv_data_secret;
+ int nv_data_size;
+ int nv_data_chunk_size;
};
struct ipc_client {
@@ -79,7 +85,8 @@ struct ipc_client {
struct ipc_ops *ops;
struct ipc_handlers *handlers;
- struct ipc_fs_ops *fs_ops;
+ struct ipc_gprs_specs *gprs_specs;
+ struct ipc_nv_data_specs *nv_data_specs;
};
void ipc_client_log(struct ipc_client *client, const char *message, ...);
diff --git a/samsung-ipc/rfs.c b/samsung-ipc/rfs.c
index 8c6005f..d6483cb 100644
--- a/samsung-ipc/rfs.c
+++ b/samsung-ipc/rfs.c
@@ -33,87 +33,100 @@
#include "ipc_private.h"
-char *nv_data_path(struct ipc_client *client) {
- if (!client) {
- ipc_client_log(client, "%s: client is NULL\n", __func__);
- goto fail;
+void md5hash2string(char *out, uint8_t *in)
+{
+ int i;
+
+ for (i=0 ; i < MD5_DIGEST_LENGTH ; i++)
+ {
+ /* After the first iteration, we override \0. */
+ if (*in < 0x10)
+ sprintf(out, "0%x", *in);
+ else
+ sprintf(out, "%x", *in);
+ in++;
+ out+=2;
}
+}
- if (client->fs_ops && client->fs_ops->nv_data_path)
- return client->fs_ops->nv_data_path;
+char *nv_data_path(struct ipc_client *client)
+{
+ if (client == NULL ||
+ client->nv_data_specs == NULL ||
+ client->nv_data_specs->nv_data_path == NULL)
+ return NV_DATA_PATH_DEFAULT;
-fail:
- return "/efs/nv_data.bin";
+ return client->nv_data_specs->nv_data_path;
}
-char *nv_data_md5_path(struct ipc_client *client) {
- if (!client) {
- ipc_client_log(client, "%s: client is NULL\n", __func__);
- goto fail;
- }
-
- if (client->fs_ops && client->fs_ops->nv_data_md5_path)
- return client->fs_ops->nv_data_md5_path;
+char *nv_data_md5_path(struct ipc_client *client)
+{
+ if (client == NULL ||
+ client->nv_data_specs == NULL ||
+ client->nv_data_specs->nv_data_md5_path == NULL)
+ return NV_DATA_MD5_PATH_DEFAULT;
-fail:
- return "/efs/nv_data.bin.md5";
+ return client->nv_data_specs->nv_data_md5_path;
}
-char *nv_state_path(struct ipc_client *client) {
- if (!client) {
- ipc_client_log(client, "%s: client is NULL\n", __func__);
- goto fail;
- }
-
- if (client->fs_ops && client->fs_ops->nv_state_path)
- return client->fs_ops->nv_state_path;
+char *nv_data_bak_path(struct ipc_client *client)
+{
+ if (client == NULL ||
+ client->nv_data_specs == NULL ||
+ client->nv_data_specs->nv_data_bak_path == NULL)
+ return NV_DATA_BAK_PATH_DEFAULT;
-fail:
- return "/efs/.nv_state";
+ return client->nv_data_specs->nv_data_bak_path;
}
-char *nv_data_bak_path(struct ipc_client *client) {
- if (!client) {
- ipc_client_log(client, "%s: client is NULL\n", __func__);
- goto fail;
- }
+char *nv_data_md5_bak_path(struct ipc_client *client)
+{
+ if (client == NULL ||
+ client->nv_data_specs == NULL ||
+ client->nv_data_specs->nv_data_md5_bak_path == NULL)
+ return NV_DATA_MD5_BAK_PATH_DEFAULT;
- if (client->fs_ops && client->fs_ops->nv_data_bak_path) {
- return client->fs_ops->nv_data_bak_path;
- }
+ return client->nv_data_specs->nv_data_md5_bak_path;
+}
+
+char *nv_state_path(struct ipc_client *client)
+{
+ if (client == NULL ||
+ client->nv_data_specs == NULL ||
+ client->nv_data_specs->nv_state_path == NULL)
+ return NV_STATE_PATH_DEFAULT;
-fail:
- return "/efs/.nv_data.bak";
+ return client->nv_data_specs->nv_state_path;
}
-char *nv_data_md5_bak_path(struct ipc_client *client) {
- if (!client) {
- ipc_client_log(client, "%s: client is NULL\n", __func__);
- goto fail;
- }
+char *nv_data_secret(struct ipc_client *client)
+{
+ if (client == NULL ||
+ client->nv_data_specs == NULL ||
+ client->nv_data_specs->nv_data_secret == NULL)
+ return NV_DATA_SECRET_DEFAULT;
- if (client->fs_ops && client->fs_ops->nv_data_md5_bak_path) {
- return client->fs_ops->nv_data_md5_bak_path;
- }
+ return client->nv_data_specs->nv_data_secret;
+}
+
+int nv_data_size(struct ipc_client *client)
+{
+ if (client == NULL ||
+ client->nv_data_specs == NULL ||
+ client->nv_data_specs->nv_data_size == NULL)
+ return NV_DATA_SIZE_DEFAULT;
-fail:
- return "/efs/.nv_data.bak.md5";
+ return client->nv_data_specs->nv_data_size;
}
-void md5hash2string(char *out, uint8_t *in)
+int nv_data_chunk_size(struct ipc_client *client)
{
- int i;
+ if (client == NULL ||
+ client->nv_data_specs == NULL ||
+ client->nv_data_specs->nv_data_chunk_size == NULL)
+ return NV_DATA_CHUNK_SIZE_DEFAULT;
- for (i=0 ; i < MD5_DIGEST_LENGTH ; i++)
- {
- /* After the first iteration, we override \0. */
- if (*in < 0x10)
- sprintf(out, "0%x", *in);
- else
- sprintf(out, "%x", *in);
- in++;
- out+=2;
- }
+ return client->nv_data_specs->nv_data_chunk_size;
}
void nv_data_generate(struct ipc_client *client)
@@ -123,7 +136,7 @@ void nv_data_generate(struct ipc_client *client)
// nv_data_backup_create();
}
-void nv_data_md5_compute(void *data_p, int size, void *hash)
+void nv_data_md5_compute(void *data_p, int size, char *secret, void *hash)
{
MD5_CTX ctx;
@@ -131,7 +144,7 @@ void nv_data_md5_compute(void *data_p, int size, void *hash)
MD5_Init(&ctx);
MD5_Update(&ctx, data_p, size);
- MD5_Update(&ctx, NV_DATA_MD5_SECRET, sizeof(NV_DATA_MD5_SECRET) - 1);
+ MD5_Update(&ctx, secret, strlen(secret));
MD5_Final(hash, &ctx);
}
@@ -146,8 +159,8 @@ void nv_data_md5_generate(struct ipc_client *client)
ipc_client_log(client, "nv_data_md5_generate: generating MD5 hash\n");
nv_data_p=ipc_file_read(client, nv_data_path(client),
- NV_DATA_SIZE, 0x1000);
- nv_data_md5_compute(nv_data_p, NV_DATA_SIZE, nv_data_md5_hash);
+ nv_data_size(client), nv_data_chunk_size(client));
+ nv_data_md5_compute(nv_data_p, nv_data_size(client), nv_data_secret(client), nv_data_md5_hash);
free(nv_data_p);
/* Alloc the memory for the md5 hash string. */
@@ -201,7 +214,7 @@ void nv_data_backup_create(struct ipc_client *client)
nv_data_generate(client);
}
- if (nv_stat.st_size != NV_DATA_SIZE)
+ if (nv_stat.st_size != nv_data_size(client))
{
ipc_client_log(client, "nv_data_backup_create: wrong nv_data.bin size\n");
nv_data_generate(client);
@@ -224,10 +237,10 @@ void nv_data_backup_create(struct ipc_client *client)
/* Read the content of the backup file. */
nv_data_p=ipc_file_read(client, nv_data_path(client),
- NV_DATA_SIZE, 0x1000);
+ nv_data_size(client), nv_data_chunk_size(client));
/* Compute the backup file MD5 hash. */
- nv_data_md5_compute(nv_data_p, NV_DATA_SIZE, nv_data_md5_hash);
+ nv_data_md5_compute(nv_data_p, nv_data_size(client), nv_data_secret(client), nv_data_md5_hash);
md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash);
/* Read the stored backup file MD5 hash. */
@@ -274,8 +287,8 @@ nv_data_backup_create_write:
continue;
}
- rc = write(fd, nv_data_p, NV_DATA_SIZE);
- if (rc < NV_DATA_SIZE)
+ rc = write(fd, nv_data_p, nv_data_size(client));
+ if (rc < nv_data_size(client))
{
ipc_client_log(client, "nv_data_backup_create: wrote less (%d) than what we expected (%d) on /efs/.nv_data.bak, error: %s\n", strerror(errno));
close(fd);
@@ -295,10 +308,11 @@ nv_data_backup_create_write:
}
/* Read the newly-written .nv_data.bak. */
- nv_data_bak_p=ipc_file_read(client, nv_data_bak_path(client), NV_DATA_SIZE, 0x1000);
+ nv_data_bak_p=ipc_file_read(client, nv_data_bak_path(client),
+ nv_data_size(client), nv_data_chunk_size(client));
/* Compute the MD5 hash for nv_data.bin. */
- nv_data_md5_compute(nv_data_bak_p, NV_DATA_SIZE, nv_data_md5_hash);
+ nv_data_md5_compute(nv_data_bak_p, nv_data_size(client), nv_data_secret(client), nv_data_md5_hash);
md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash);
free(nv_data_bak_p);
@@ -360,7 +374,7 @@ void nv_data_backup_restore(struct ipc_client *client)
return;
}
- if (nv_stat.st_size != NV_DATA_SIZE)
+ if (nv_stat.st_size != nv_data_size(client))
{
ipc_client_log(client, "nv_data_backup_restore: wrong .nv_data.bak size\n");
nv_data_generate(client);
@@ -384,10 +398,11 @@ void nv_data_backup_restore(struct ipc_client *client)
memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE);
/* Read the content of the backup file. */
- nv_data_bak_p=ipc_file_read(client, nv_data_bak_path(client), NV_DATA_SIZE, 0x1000);
+ nv_data_bak_p=ipc_file_read(client, nv_data_bak_path(client),
+ nv_data_size(client), nv_data_chunk_size(client));
/* Compute the backup file MD5 hash. */
- nv_data_md5_compute(nv_data_bak_p, NV_DATA_SIZE, nv_data_md5_hash);
+ nv_data_md5_compute(nv_data_bak_p, nv_data_size(client), nv_data_secret(client), nv_data_md5_hash);
md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash);
/* Read the stored backup file MD5 hash. */
@@ -434,8 +449,8 @@ nv_data_backup_restore_write:
continue;
}
- rc = write(fd, nv_data_bak_p, NV_DATA_SIZE);
- if (rc < NV_DATA_SIZE)
+ rc = write(fd, nv_data_bak_p, nv_data_size(client));
+ if (rc < nv_data_size(client))
{
ipc_client_log(client, "nv_data_backup_restore: wrote less (%d) than what we expected (%d) on /efs/nv_data.bin, error: %s\n", strerror(errno));
close(fd);
@@ -456,10 +471,11 @@ nv_data_backup_restore_write:
}
/* Read the newly-written nv_data.bin. */
- nv_data_p=ipc_file_read(client, nv_data_path(client), NV_DATA_SIZE, 0x1000);
+ nv_data_p=ipc_file_read(client, nv_data_path(client),
+ nv_data_size(client), nv_data_chunk_size(client));
/* Compute the MD5 hash for nv_data.bin. */
- nv_data_md5_compute(nv_data_p, NV_DATA_SIZE, nv_data_md5_hash);
+ nv_data_md5_compute(nv_data_p, nv_data_size(client), nv_data_secret(client), nv_data_md5_hash);
md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash);
free(nv_data_p);
@@ -510,7 +526,7 @@ void nv_data_check(struct ipc_client *client)
stat(nv_data_path(client), &nv_stat);
}
- if (nv_stat.st_size != NV_DATA_SIZE)
+ if (nv_stat.st_size != nv_data_size(client))
{
ipc_client_log(client, "nv_data_check: wrong nv_data.bin size\n");
nv_data_backup_restore(client);
@@ -569,10 +585,11 @@ void nv_data_md5_check(struct ipc_client *client)
memset(nv_data_md5_hash_read, 0, MD5_STRING_SIZE);
memset(nv_data_md5_hash_string, 0, MD5_STRING_SIZE);
- nv_data_p=ipc_file_read(client, nv_data_path(client), NV_DATA_SIZE, 0x1000);
+ nv_data_p=ipc_file_read(client, nv_data_path(client),
+ nv_data_size(client), nv_data_chunk_size(client));
data_p=nv_data_p;
- nv_data_md5_compute(data_p, NV_DATA_SIZE, nv_data_md5_hash);
+ nv_data_md5_compute(data_p, nv_data_size(client), nv_data_secret(client), nv_data_md5_hash);
md5hash2string(nv_data_md5_hash_string, nv_data_md5_hash);