summaryrefslogtreecommitdiffstats
path: root/rfs.c
blob: 5234e7384c0695e8c1914d6e7cd2c3c0cb33458e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
/*
 * This file is part of Samsung-RIL.
 *
 * Copyright (C) 2011-2012 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
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * Samsung-RIL is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with Samsung-RIL.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

#define LOG_TAG "RIL-RFS"
#include <utils/Log.h>

#include "samsung-ril.h"
#include "util.h"

void ipc_rfs_nv_read_item(struct ipc_message_info *info)
{
	struct ipc_client_data *ipc_client_data;
	struct ipc_client *ipc_client;

	struct ipc_rfs_io *rfs_io;
	struct ipc_rfs_io_confirm *rfs_io_conf;

	void *rfs_data;
	int rc;

	if (info == NULL || info->data == NULL || info->length < sizeof(struct ipc_rfs_io))
		return;

	rfs_io = (struct ipc_rfs_io *) info->data;

	if (ril_data.ipc_rfs_client == NULL || ril_data.ipc_rfs_client->data == NULL)
		return;

	ipc_client_data = (struct ipc_client_data *) ril_data.ipc_rfs_client->data;

	if (ipc_client_data->ipc_client == NULL)
		return;

	ipc_client = ipc_client_data->ipc_client;

	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);

	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);

	LOGD("Read rfs_data dump:");
	hex_dump(rfs_data, rfs_io->length > 0x100 ? 0x100 : rfs_io->length);

	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;

	ipc_rfs_send(IPC_RFS_NV_READ_ITEM, (unsigned char *) rfs_io_conf, rfs_io->length + sizeof(struct ipc_rfs_io_confirm), info->aseq);

	free(rfs_io_conf);
}

void ipc_rfs_nv_write_item(struct ipc_message_info *info)
{
	struct ipc_client_data *ipc_client_data;
	struct ipc_client *ipc_client;

	struct ipc_rfs_io *rfs_io;
	struct ipc_rfs_io_confirm rfs_io_conf;

	void *rfs_data;
	int rc;

	if (info == NULL || info->data == NULL || info->length < sizeof(struct ipc_rfs_io))
		return;

	rfs_io = (struct ipc_rfs_io *) info->data;

	if (ril_data.ipc_rfs_client == NULL || ril_data.ipc_rfs_client->data == NULL)
		return;

	ipc_client_data = (struct ipc_client_data *) ril_data.ipc_rfs_client->data;

	if (ipc_client_data->ipc_client == NULL)
		return;

	ipc_client = ipc_client_data->ipc_client;

	memset(&rfs_io_conf, 0, sizeof(rfs_io_conf));
	rfs_data = info->data + sizeof(struct ipc_rfs_io);

	LOGD("Write rfs_data dump:");
	hex_dump(rfs_data, rfs_io->length > 0x100 ? 0x100 : rfs_io->length);

	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);

	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;

	ipc_rfs_send(IPC_RFS_NV_WRITE_ITEM, (unsigned char *) &rfs_io_conf, sizeof(struct ipc_rfs_io_confirm), info->aseq);
}