2 * This file is part of libsamsung-ipc.
4 * Copyright (C) 2013 Paul Kocialkowski <contact@paulk.fr>
5 * Copyright (C) 2012 Alexander Tarasikov <alexander.tarasikov@gmail.com>
7 * libsamsung-ipc is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 2 of the License, or
10 * (at your option) any later version.
12 * libsamsung-ipc is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with libsamsung-ipc. If not, see <http://www.gnu.org/licenses/>.
27 #include <sys/ioctl.h>
28 #include <sys/select.h>
30 #include <samsung-ipc.h>
35 #include "modem_prj.h"
36 #include "modem_link_device_hsic.h"
39 #include "xmm6260_sec_modem.h"
41 int xmm6260_sec_modem_power(int device_fd, int power)
48 rc = ioctl(device_fd, power ? IOCTL_MODEM_ON : IOCTL_MODEM_OFF, 0);
55 int xmm6260_sec_modem_boot_power(int device_fd, int power)
62 rc = ioctl(device_fd, power ? IOCTL_MODEM_BOOT_ON : IOCTL_MODEM_BOOT_OFF, 0);
69 int xmm6260_sec_modem_status_online_wait(int device_fd)
78 for (i = 0; i < 100; i++) {
79 status = ioctl(device_fd, IOCTL_MODEM_STATUS, 0);
80 if (status == STATE_ONLINE)
89 int xmm6260_sec_modem_hci_power(int power)
93 ehci_rc = sysfs_value_write(XMM6260_SEC_MODEM_EHCI_POWER_SYSFS, !!power);
97 ohci_rc = sysfs_value_write(XMM6260_SEC_MODEM_OHCI_POWER_SYSFS, !!power);
101 if (ehci_rc < 0 && ohci_rc < 0)
107 int xmm6260_sec_modem_link_control_enable(int device_fd, int enable)
114 rc = ioctl(device_fd, IOCTL_LINK_CONTROL_ENABLE, &enable);
121 int xmm6260_sec_modem_link_control_active(int device_fd, int active)
128 rc = ioctl(device_fd, IOCTL_LINK_CONTROL_ACTIVE, &active);
135 int xmm6260_sec_modem_link_connected_wait(int device_fd)
144 for (i = 0; i < 100; i++) {
145 status = ioctl(device_fd, IOCTL_LINK_CONNECTED, 0);
155 int xmm6260_sec_modem_link_get_hostwake_wait(int device_fd)
164 for (i = 0; i < 10; i++) {
165 status = ioctl(device_fd, IOCTL_LINK_GET_HOSTWAKE, 0);
175 int xmm6260_sec_modem_ipc_fmt_send(struct ipc_client *client, struct ipc_message_info *request)
177 struct ipc_fmt_header header;
183 if (client == NULL || client->handlers == NULL || client->handlers->write == NULL || request == NULL)
186 ipc_fmt_header_fill(&header, request);
188 buffer = malloc(header.length);
190 memcpy(buffer, &header, sizeof(struct ipc_fmt_header));
191 if (request->data != NULL && request->length > 0)
192 memcpy((void *) ((unsigned char *) buffer + sizeof(struct ipc_fmt_header)), request->data, request->length);
194 ipc_client_log_send(client, request, __func__);
196 p = (unsigned char *) buffer;
199 while (count < header.length) {
200 rc = client->handlers->write(client->handlers->transport_data, p, header.length - count);
202 ipc_client_log(client, "Writing FMT data to the modem failed");
223 int xmm6260_sec_modem_ipc_fmt_recv(struct ipc_client *client, struct ipc_message_info *response)
225 struct ipc_fmt_header *header;
232 if (client == NULL || client->handlers == NULL || client->handlers->read == NULL || response == NULL)
235 length = XMM6260_DATA_SIZE;
236 buffer = malloc(length);
238 rc = client->handlers->read(client->handlers->transport_data, buffer, length);
239 if (rc < (int) sizeof(struct ipc_fmt_header)) {
240 ipc_client_log(client, "Reading FMT header from the modem failed");
244 header = (struct ipc_fmt_header *) buffer;
246 ipc_fmt_message_fill(header, response);
248 if (header->length > sizeof(struct ipc_fmt_header)) {
249 response->length = header->length - sizeof(struct ipc_fmt_header);
250 response->data = malloc(response->length);
252 p = (unsigned char *) response->data;
254 count = rc - sizeof(struct ipc_fmt_header);
256 memcpy(p, (void *) ((unsigned char *) buffer + sizeof(struct ipc_fmt_header)), count);
260 while (count < (int) response->length) {
261 rc = client->handlers->read(client->handlers->transport_data, p, response->length - count);
263 ipc_client_log(client, "Reading FMT data from the modem failed");
272 ipc_client_log_recv(client, response, __func__);
287 int xmm6260_sec_modem_ipc_rfs_send(struct ipc_client *client, struct ipc_message_info *request)
289 struct ipc_rfs_header header;
296 if (client == NULL || client->handlers == NULL || client->handlers->write == NULL || request == NULL)
299 ipc_rfs_header_fill(&header, request);
301 buffer = malloc(header.length);
303 memcpy(buffer, &header, sizeof(struct ipc_rfs_header));
304 if (request->data != NULL && request->length > 0)
305 memcpy((void *) ((unsigned char *) buffer + sizeof(struct ipc_rfs_header)), request->data, request->length);
307 ipc_client_log_send(client, request, __func__);
309 p = (unsigned char *) buffer;
312 while (count < (int) header.length) {
313 rc = client->handlers->write(client->handlers->transport_data, p, header.length - count);
315 ipc_client_log(client, "Writing RFS data to the modem failed");
336 int xmm6260_sec_modem_ipc_rfs_recv(struct ipc_client *client, struct ipc_message_info *response)
338 struct ipc_rfs_header *header;
345 if (client == NULL || client->handlers == NULL || client->handlers->read == NULL || response == NULL)
348 length = XMM6260_DATA_SIZE;
349 buffer = malloc(length);
351 rc = client->handlers->read(client->handlers->transport_data, buffer, length);
352 if (rc < (int) sizeof(struct ipc_rfs_header)) {
353 ipc_client_log(client, "Reading RFS header from the modem failed");
357 header = (struct ipc_rfs_header *) buffer;
359 ipc_rfs_message_fill(header, response);
361 if (header->length > sizeof(struct ipc_rfs_header)) {
362 response->length = header->length - sizeof(struct ipc_rfs_header);
363 response->data = malloc(response->length);
365 p = (unsigned char *) response->data;
367 count = rc - sizeof(struct ipc_rfs_header);
369 memcpy(p, (void *) ((unsigned char *) buffer + sizeof(struct ipc_rfs_header)), count);
373 while (count < (int) response->length) {
374 rc = client->handlers->read(client->handlers->transport_data, p, response->length - count);
376 ipc_client_log(client, "Reading RFS data from the modem failed");
385 ipc_client_log_recv(client, response, __func__);
400 int xmm6260_sec_modem_ipc_open(int type)
405 case IPC_CLIENT_TYPE_FMT:
406 fd = open(XMM6260_SEC_MODEM_IPC0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK);
408 case IPC_CLIENT_TYPE_RFS:
409 fd = open(XMM6260_SEC_MODEM_RFS0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK);
418 int xmm6260_sec_modem_ipc_close(int fd)
428 int xmm6260_sec_modem_ipc_read(int fd, void *buffer, unsigned int length)
432 if (fd < 0 || buffer == NULL || length <= 0)
435 rc = read(fd, buffer, length);
439 int xmm6260_sec_modem_ipc_write(int fd, void *buffer, unsigned int length)
443 if (fd < 0 || buffer == NULL || length <= 0)
446 rc = write(fd, buffer, length);
450 int xmm6260_sec_modem_ipc_poll(int fd, struct timeval *timeout)
462 rc = select(fd + 1, &fds, NULL, NULL, timeout);
463 if (FD_ISSET(fd, &fds)) {
464 status = ioctl(fd, IOCTL_MODEM_STATUS, 0);
465 if (status != STATE_ONLINE && status != STATE_BOOTING)
472 char *xmm6260_sec_modem_ipc_gprs_get_iface(int cid)
476 if (cid > XMM6260_SEC_MODEM_GPRS_IFACE_COUNT)
479 asprintf(&iface, "%s%d", XMM6260_SEC_MODEM_GPRS_IFACE_PREFIX, cid - 1);
484 int xmm6260_sec_modem_ipc_gprs_get_capabilities(struct ipc_client_gprs_capabilities *capabilities)
486 if (capabilities == NULL)
489 capabilities->port_list = 0;
490 capabilities->cid_max = XMM6260_SEC_MODEM_GPRS_IFACE_COUNT;
495 // vim:ts=4:sw=4:expandtab