2 * This file is part of libsamsung-ipc.
4 * Copyright (C) 2011-2013 Paul Kocialkowski <contact@paulk.fr>
6 * libsamsung-ipc is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 2 of the License, or
9 * (at your option) any later version.
11 * libsamsung-ipc is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with libsamsung-ipc. If not, see <http://www.gnu.org/licenses/>.
26 #include <sys/select.h>
28 #include <samsung-ipc.h>
33 int xmm6160_psi_send(struct ipc_client *client, int serial_fd,
34 void *modem_image_data, unsigned short psi_size)
36 char at[] = XMM6160_AT;
37 unsigned char version;
39 unsigned char psi_magic;
40 unsigned char psi_crc;
41 unsigned char psi_ack;
43 struct termios termios;
44 struct timeval timeout;
52 if (client == NULL || serial_fd < 0 || modem_image_data == NULL || psi_size <= 0)
55 tcgetattr(serial_fd, &termios);
58 cfsetispeed(&termios, B115200);
59 cfsetospeed(&termios, B115200);
61 tcsetattr(serial_fd, TCSANOW, &termios);
64 for (i=0; i < XMM6160_AT_COUNT; i++) {
65 rc = write(serial_fd, at, length);
67 ipc_client_log(client, "Writing AT in ASCII failed");
73 ipc_client_log(client, "Wrote AT in ASCII");
79 rc = read(serial_fd, &version, sizeof(version));
80 if (rc < (int) sizeof(version)) {
81 ipc_client_log(client, "Reading bootcore version failed");
85 if (version != XMM6160_BOOTCORE_VERSION) {
86 ipc_client_log(client, "Read wrong bootcore version (0x%x)", version);
90 ipc_client_log(client, "Read bootcore version (0x%x)", version);
92 rc = read(serial_fd, &info, sizeof(info));
93 if (rc < (int) sizeof(info)) {
94 ipc_client_log(client, "Reading info size failed");
97 ipc_client_log(client, "Read info size (0x%x)", info);
99 psi_magic = XMM6160_PSI_MAGIC;
101 rc = write(serial_fd, &psi_magic, sizeof(psi_magic));
102 if (rc < (int) sizeof(psi_magic)) {
103 ipc_client_log(client, "Writing PSI magic failed");
106 ipc_client_log(client, "Wrote PSI magic (0x%x)", psi_magic);
108 rc = write(serial_fd, &psi_size, sizeof(psi_size));
109 if (rc < (int) sizeof(psi_size)) {
110 ipc_client_log(client, "Writing PSI size failed");
113 ipc_client_log(client, "Wrote PSI size (0x%x)", psi_size);
116 FD_SET(serial_fd, &fds);
121 p = (unsigned char *) modem_image_data;
124 for (i=0; i < psi_size; i++) {
125 rc = select(serial_fd + 1, NULL, &fds, NULL, &timeout);
127 ipc_client_log(client, "Writing PSI failed");
131 rc = write(serial_fd, p, 1);
133 ipc_client_log(client, "Writing PSI failed");
139 ipc_client_log(client, "Wrote PSI, CRC is 0x%x", psi_crc);
141 rc = select(serial_fd + 1, NULL, &fds, NULL, &timeout);
143 ipc_client_log(client, "Writing PSI crc failed");
147 rc = write(serial_fd, &psi_crc, sizeof(psi_crc));
148 if (rc < (int) sizeof(psi_crc)) {
149 ipc_client_log(client, "Writing PSI crc failed");
152 ipc_client_log(client, "Wrote PSI CRC (0x%x)", psi_crc);
159 rc = select(serial_fd + 1, &fds, NULL, NULL, &timeout);
161 ipc_client_log(client, "Reading PSI ACK failed");
165 rc = read(serial_fd, &psi_ack, sizeof(psi_ack));
166 if (rc < (int) sizeof(psi_ack)) {
167 ipc_client_log(client, "Reading PSI ACK failed");
172 ipc_client_log(client, "Reading PSI ACK failed");
175 } while (psi_ack != XMM6160_PSI_ACK);
176 ipc_client_log(client, "Read PSI ACK (0x%x)", psi_ack);
188 int xmm6160_modem_image_send(struct ipc_client *client, int device_fd,
189 void *device_address, void *modem_image_data, int modem_image_size)
197 if (client == NULL || (device_fd < 0 && device_address == NULL) || modem_image_data == NULL || modem_image_size <= 0)
200 p = (unsigned char *) modem_image_data;
202 if (device_address != NULL) {
203 memcpy(device_address, (void *) p, modem_image_size);
206 while (wc < modem_image_size) {
207 rc = write(device_fd, (void *) p, modem_image_size - wc);
209 ipc_client_log(client, "Writing modem image failed");
217 ipc_client_log(client, "Wrote modem image");
229 int xmm6160_nv_data_send(struct ipc_client *client, int device_fd,
230 void *device_address)
232 void *nv_data = NULL;
239 if (client == NULL || (device_fd < 0 && device_address == NULL))
242 rc = nv_data_check(client);
244 ipc_client_log(client, "Checking nv_data failed");
247 ipc_client_log(client, "Checked nv_data");
249 rc = nv_data_md5_check(client);
251 ipc_client_log(client, "Checking nv_data md5 failed");
254 ipc_client_log(client, "Checked nv_data md5");
256 nv_data = file_data_read(nv_data_path(client), nv_data_size(client), nv_data_chunk_size(client));
257 if (nv_data == NULL) {
258 ipc_client_log(client, "Reading nv_data failed");
261 ipc_client_log(client, "Read nv_data");
263 p = (unsigned char *) nv_data;
264 length = nv_data_size(client);
266 if (device_address != NULL) {
267 memcpy(device_address, p, length);
270 while (wc < length) {
271 rc = write(device_fd, p, length - wc);
273 ipc_client_log(client, "Writing modem image failed");
295 // vim:ts=4:sw=4:expandtab