From 005645221f3d4dd432970f8f28d9092d66d61213 Mon Sep 17 00:00:00 2001 From: Paul Kocialkowski Date: Sat, 15 Feb 2014 20:16:19 +0100 Subject: ipc: Consistent coding style and major cleanup Signed-off-by: Paul Kocialkowski --- Android.mk | 18 +- include/protocol.h | 7 +- include/samsung-ipc.h | 86 ++- samsung-ipc/Makefile.am | 30 +- samsung-ipc/devices/aries/aries.c | 811 +++++++++++++++++++++++ samsung-ipc/devices/aries/aries.h | 65 ++ samsung-ipc/devices/aries/aries_ipc.c | 816 ------------------------ samsung-ipc/devices/aries/aries_ipc.h | 65 -- samsung-ipc/devices/crespo/crespo.c | 564 ++++++++++++++++ samsung-ipc/devices/crespo/crespo.h | 50 ++ samsung-ipc/devices/crespo/crespo_ipc.c | 569 ----------------- samsung-ipc/devices/crespo/crespo_ipc.h | 50 -- samsung-ipc/devices/galaxys2/galaxys2.c | 398 ++++++++++++ samsung-ipc/devices/galaxys2/galaxys2.h | 49 ++ samsung-ipc/devices/galaxys2/galaxys2_ipc.c | 427 ------------- samsung-ipc/devices/galaxys2/galaxys2_ipc.h | 49 -- samsung-ipc/devices/i9300/i9300.c | 391 ++++++++++++ samsung-ipc/devices/i9300/i9300.h | 49 ++ samsung-ipc/devices/i9300/i9300_ipc.c | 421 ------------ samsung-ipc/devices/i9300/i9300_ipc.h | 49 -- samsung-ipc/devices/maguro/maguro.c | 374 +++++++++++ samsung-ipc/devices/maguro/maguro.h | 56 ++ samsung-ipc/devices/maguro/maguro_ipc.c | 403 ------------ samsung-ipc/devices/maguro/maguro_ipc.h | 56 -- samsung-ipc/devices/n7100/n7100.c | 392 ++++++++++++ samsung-ipc/devices/n7100/n7100.h | 49 ++ samsung-ipc/devices/n7100/n7100_ipc.c | 421 ------------ samsung-ipc/devices/n7100/n7100_ipc.h | 49 -- samsung-ipc/devices/piranha/piranha.c | 340 ++++++++++ samsung-ipc/devices/piranha/piranha.h | 50 ++ samsung-ipc/devices/piranha/piranha_ipc.c | 368 ----------- samsung-ipc/devices/piranha/piranha_ipc.h | 50 -- samsung-ipc/devices/xmm6160/xmm6160.c | 30 +- samsung-ipc/devices/xmm6160/xmm6160.h | 6 +- samsung-ipc/devices/xmm6260/xmm6260.c | 10 +- samsung-ipc/devices/xmm6260/xmm6260.h | 4 +- samsung-ipc/devices/xmm6260/xmm6260_hsic.c | 91 ++- samsung-ipc/devices/xmm6260/xmm6260_hsic.h | 10 +- samsung-ipc/devices/xmm6260/xmm6260_mipi.c | 130 ++-- samsung-ipc/devices/xmm6260/xmm6260_mipi.h | 12 +- samsung-ipc/devices/xmm6260/xmm6260_sec_modem.c | 130 ++-- samsung-ipc/devices/xmm6260/xmm6260_sec_modem.h | 32 +- samsung-ipc/ipc.c | 232 +++---- samsung-ipc/ipc.h | 27 +- samsung-ipc/ipc_devices.c | 110 ++-- samsung-ipc/ipc_devices.h | 24 +- samsung-ipc/ipc_util.c | 516 --------------- samsung-ipc/ipc_utils.c | 531 +++++++++++++++ tools/modemctrl.c | 62 +- 49 files changed, 4672 insertions(+), 4857 deletions(-) create mode 100644 samsung-ipc/devices/aries/aries.c create mode 100644 samsung-ipc/devices/aries/aries.h delete mode 100644 samsung-ipc/devices/aries/aries_ipc.c delete mode 100644 samsung-ipc/devices/aries/aries_ipc.h create mode 100644 samsung-ipc/devices/crespo/crespo.c create mode 100644 samsung-ipc/devices/crespo/crespo.h delete mode 100644 samsung-ipc/devices/crespo/crespo_ipc.c delete mode 100644 samsung-ipc/devices/crespo/crespo_ipc.h create mode 100644 samsung-ipc/devices/galaxys2/galaxys2.c create mode 100644 samsung-ipc/devices/galaxys2/galaxys2.h delete mode 100644 samsung-ipc/devices/galaxys2/galaxys2_ipc.c delete mode 100644 samsung-ipc/devices/galaxys2/galaxys2_ipc.h create mode 100644 samsung-ipc/devices/i9300/i9300.c create mode 100644 samsung-ipc/devices/i9300/i9300.h delete mode 100644 samsung-ipc/devices/i9300/i9300_ipc.c delete mode 100644 samsung-ipc/devices/i9300/i9300_ipc.h create mode 100644 samsung-ipc/devices/maguro/maguro.c create mode 100644 samsung-ipc/devices/maguro/maguro.h delete mode 100644 samsung-ipc/devices/maguro/maguro_ipc.c delete mode 100644 samsung-ipc/devices/maguro/maguro_ipc.h create mode 100644 samsung-ipc/devices/n7100/n7100.c create mode 100644 samsung-ipc/devices/n7100/n7100.h delete mode 100644 samsung-ipc/devices/n7100/n7100_ipc.c delete mode 100644 samsung-ipc/devices/n7100/n7100_ipc.h create mode 100644 samsung-ipc/devices/piranha/piranha.c create mode 100644 samsung-ipc/devices/piranha/piranha.h delete mode 100644 samsung-ipc/devices/piranha/piranha_ipc.c delete mode 100644 samsung-ipc/devices/piranha/piranha_ipc.h delete mode 100644 samsung-ipc/ipc_util.c create mode 100644 samsung-ipc/ipc_utils.c diff --git a/Android.mk b/Android.mk index 8b6f445..cf55285 100644 --- a/Android.mk +++ b/Android.mk @@ -1,6 +1,6 @@ # This file is part of libsamsung-ipc. # -# Copyright (C) 2011-2013 Paul Kocialkowski +# Copyright (C) 2011-2014 Paul Kocialkowski # # libsamsung-ipc is free software: you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -50,19 +50,19 @@ endif LOCAL_SRC_FILES := \ samsung-ipc/ipc.c \ samsung-ipc/ipc_devices.c \ - samsung-ipc/ipc_util.c \ + samsung-ipc/ipc_utils.c \ samsung-ipc/devices/xmm6160/xmm6160.c \ samsung-ipc/devices/xmm6260/xmm6260.c \ samsung-ipc/devices/xmm6260/xmm6260_hsic.c \ samsung-ipc/devices/xmm6260/xmm6260_mipi.c \ samsung-ipc/devices/xmm6260/xmm6260_sec_modem.c \ - samsung-ipc/devices/crespo/crespo_ipc.c \ - samsung-ipc/devices/aries/aries_ipc.c \ - samsung-ipc/devices/galaxys2/galaxys2_ipc.c \ - samsung-ipc/devices/maguro/maguro_ipc.c \ - samsung-ipc/devices/piranha/piranha_ipc.c \ - samsung-ipc/devices/i9300/i9300_ipc.c \ - samsung-ipc/devices/n7100/n7100_ipc.c \ + samsung-ipc/devices/crespo/crespo.c \ + samsung-ipc/devices/aries/aries.c \ + samsung-ipc/devices/galaxys2/galaxys2.c \ + samsung-ipc/devices/maguro/maguro.c \ + samsung-ipc/devices/piranha/piranha.c \ + samsung-ipc/devices/i9300/i9300.c \ + samsung-ipc/devices/n7100/n7100.c \ samsung-ipc/utils.c \ samsung-ipc/call.c \ samsung-ipc/sms.c \ diff --git a/include/protocol.h b/include/protocol.h index 1de64df..d2b58d0 100644 --- a/include/protocol.h +++ b/include/protocol.h @@ -2,6 +2,7 @@ * This file is part of libsamsung-ipc. * * Copyright (C) 2010-2011 Joerie de Gram + * Copyright (C) 2014 Paul Kocialkowski * * libsamsung-ipc is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -66,9 +67,9 @@ * Macros */ -#define IPC_COMMAND(f) ((f->group << 8) | f->index) -#define IPC_GROUP(m) (m >> 8) -#define IPC_INDEX(m) (m & 0xff) +#define IPC_COMMAND(group, index) ((group << 8) | index) +#define IPC_GROUP(command) (command >> 8) +#define IPC_INDEX(command) (command & 0xff) /* * Structures diff --git a/include/samsung-ipc.h b/include/samsung-ipc.h index 13370c8..669d4d8 100644 --- a/include/samsung-ipc.h +++ b/include/samsung-ipc.h @@ -3,6 +3,7 @@ * * Copyright (C) 2010-2011 Joerie de Gram * Copyright (C) 2012 Simon Busch + * Copyright (C) 2014 Paul Kocialkowski * * libsamsung-ipc is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,67 +41,58 @@ struct ipc_handlers; struct ipc_fmt_header; struct ipc_rfs_header; -struct ipc_message_info { +struct ipc_message { unsigned char mseq; unsigned char aseq; - unsigned char group; - unsigned char index; - unsigned short cmd; + unsigned short command; unsigned char type; - unsigned int length; - unsigned char *data; + void *data; + size_t size; }; struct ipc_client_gprs_capabilities { - int port_list; - int cid_max; + int cid_count; }; /* * Helpers */ -struct ipc_client *ipc_client_create(int client_type); -int ipc_client_destroy(struct ipc_client *client); +int ipc_device_detect(void); -void ipc_client_log(struct ipc_client *client, const char *message, ...); -int ipc_client_set_log_callback(struct ipc_client *client, - void (*log_callback)(void *log_data, const char *message), void *log_data); +struct ipc_client *ipc_client_create(int type); +int ipc_client_destroy(struct ipc_client *client); -int ipc_client_set_transport_handlers(struct ipc_client *client, +int ipc_client_transport_handlers_register(struct ipc_client *client, int (*open)(void *transport_data, int type), int (*close)(void *transport_data), - int (*read)(void *transport_data, void *buffer, unsigned int length), - int (*write)(void *transport_data, void *buffer, unsigned int length), + int (*read)(void *transport_data, void *data, size_t size), + int (*write)(void *transport_data, const void *data, size_t size), int (*poll)(void *transport_data, struct timeval *timeout), void *transport_data); -int ipc_client_set_power_handlers(struct ipc_client *client, - int (*power_on)(void *power_data), - int (*power_off)(void *power_data), +int ipc_client_power_handlers_register(struct ipc_client *client, + int (*power_on)(void *power_data), int (*power_off)(void *power_data), void *power_data); -int ipc_client_set_gprs_handlers(struct ipc_client *client, +int ipc_client_gprs_handlers_register(struct ipc_client *client, int (*gprs_activate)(void *gprs_data, int cid), - int (*gprs_deactivate)(void *gprs_data, int cid), - void *gprs_data); + int (*gprs_deactivate)(void *gprs_data, int cid), void *gprs_data); + +void ipc_client_log(struct ipc_client *client, const char *message, ...); +int ipc_client_log_callback_register(struct ipc_client *client, + void (*log_callback)(void *log_data, const char *message), void *log_data); -int ipc_client_bootstrap(struct ipc_client *client); -int ipc_client_send(struct ipc_client *client, const unsigned short command, - const char type, unsigned char *data, const int length, unsigned char mseq); -int ipc_client_recv(struct ipc_client *client, - struct ipc_message_info *response); -void ipc_client_response_free(struct ipc_client *client, - struct ipc_message_info *response); +int ipc_client_boot(struct ipc_client *client); +int ipc_client_send(struct ipc_client *client, unsigned char mseq, + unsigned short command, unsigned char type, const void *data, size_t size); +int ipc_client_recv(struct ipc_client *client, struct ipc_message *message); int ipc_client_open(struct ipc_client *client); int ipc_client_close(struct ipc_client *client); int ipc_client_poll(struct ipc_client *client, struct timeval *timeout); - int ipc_client_power_on(struct ipc_client *client); int ipc_client_power_off(struct ipc_client *client); - int ipc_client_gprs_activate(struct ipc_client *client, int cid); int ipc_client_gprs_deactivate(struct ipc_client *client, int cid); - int ipc_client_data_create(struct ipc_client *client); int ipc_client_data_destroy(struct ipc_client *client); @@ -116,18 +108,24 @@ char *ipc_client_nv_data_secret(struct ipc_client *client); size_t ipc_client_nv_data_size(struct ipc_client *client); size_t ipc_client_nv_data_chunk_size(struct ipc_client *client); -const char *ipc_response_type_to_str(int type); -const char *ipc_request_type_to_str(int type); -const char *ipc_command_to_str(int command); -void ipc_client_hex_dump(struct ipc_client *client, void *data, int size); -void ipc_client_log_recv(struct ipc_client *client, - struct ipc_message_info *response, const char *prefix); -void ipc_client_log_send(struct ipc_client *client, - struct ipc_message_info *request, const char *prefix); -void ipc_fmt_header_fill(struct ipc_fmt_header *header, struct ipc_message_info *message); -void ipc_fmt_message_fill(struct ipc_fmt_header *header, struct ipc_message_info *message); -void ipc_rfs_header_fill(struct ipc_rfs_header *header, struct ipc_message_info *message); -void ipc_rfs_message_fill(struct ipc_rfs_header *header, struct ipc_message_info *message); +const char *ipc_request_type_string(unsigned char type); +const char *ipc_response_type_string(unsigned char type); +const char *ipc_command_string(unsigned short command); + +void ipc_hex_dump(struct ipc_client *client, const void *data, size_t size); +void ipc_client_log_recv(struct ipc_client *client, struct ipc_message *message, + const char *prefix); +void ipc_client_log_send(struct ipc_client *client, struct ipc_message *message, + const char *prefix); + +int ipc_fmt_header_setup(struct ipc_fmt_header *header, + const struct ipc_message *message); +int ipc_fmt_message_setup(const struct ipc_fmt_header *header, + struct ipc_message *message); +int ipc_rfs_header_setup(struct ipc_rfs_header *header, + const struct ipc_message *message); +int ipc_rfs_message_setup(const struct ipc_rfs_header *header, + struct ipc_message *message); /* * Samsung-IPC protocol diff --git a/samsung-ipc/Makefile.am b/samsung-ipc/Makefile.am index 4c0ba02..7d64b41 100644 --- a/samsung-ipc/Makefile.am +++ b/samsung-ipc/Makefile.am @@ -21,7 +21,7 @@ libsamsung_ipc_la_SOURCES = \ ipc.h \ ipc_devices.c \ ipc_devices.h \ - ipc_util.c \ + ipc_utils.c \ devices/xmm6160/xmm6160.c \ devices/xmm6160/xmm6160.h \ devices/xmm6260/xmm6260.c \ @@ -35,23 +35,23 @@ libsamsung_ipc_la_SOURCES = \ devices/xmm6260/modem.h \ devices/xmm6260/modem_link_device_hsic.h \ devices/xmm6260/modem_prj.h \ - devices/crespo/crespo_ipc.c \ - devices/crespo/crespo_ipc.h \ + devices/crespo/crespo.c \ + devices/crespo/crespo.h \ devices/crespo/crespo_modem_ctl.h \ - devices/aries/aries_ipc.c \ - devices/aries/aries_ipc.h \ + devices/aries/aries.c \ + devices/aries/aries.h \ devices/aries/onedram.h \ devices/aries/phonet.h \ - devices/galaxys2/galaxys2_ipc.c \ - devices/galaxys2/galaxys2_ipc.h \ - devices/maguro/maguro_ipc.c \ - devices/maguro/maguro_ipc.h \ - devices/piranha/piranha_ipc.c \ - devices/piranha/piranha_ipc.h \ - devices/i9300/i9300_ipc.c \ - devices/i9300/i9300_ipc.h \ - devices/n7100/n7100_ipc.c \ - devices/n7100/n7100_ipc.h \ + devices/galaxys2/galaxys2.c \ + devices/galaxys2/galaxys2.h \ + devices/maguro/maguro.c \ + devices/maguro/maguro.h \ + devices/piranha/piranha.c \ + devices/piranha/piranha.h \ + devices/i9300/i9300.c \ + devices/i9300/i9300.h \ + devices/n7100/n7100.c \ + devices/n7100/n7100.h \ utils.c \ utils.h \ call.c \ diff --git a/samsung-ipc/devices/aries/aries.c b/samsung-ipc/devices/aries/aries.c new file mode 100644 index 0000000..77fa4b6 --- /dev/null +++ b/samsung-ipc/devices/aries/aries.c @@ -0,0 +1,811 @@ +/* + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2011 Joerie de Gram + * Copyright (C) 2011 Simon Busch + * Copyright (C) 2011 Igor Almeida + * Copyright (C) 2011-2014 Paul Kocialkowski + * + * libsamsung-ipc 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 2 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc 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 libsamsung-ipc. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "onedram.h" +#include "phonet.h" + +#include "xmm6160.h" +#include "aries.h" + +int aries_boot(struct ipc_client *client) +{ + void *modem_image_data = NULL; + void *onedram_address = NULL; + unsigned int onedram_init; + unsigned int onedram_magic; + unsigned int onedram_deinit; + int onedram_fd = -1; + int serial_fd = -1; + struct timeval timeout; + fd_set fds; + unsigned char *p; + unsigned char *pp; + int rc; + int i; + + if (client == NULL || client->handlers == NULL || client->handlers->power_on == NULL || client->handlers->power_off == NULL) + return -1; + + ipc_client_log(client, "Starting aries modem boot"); + + modem_image_data = file_data_read(ARIES_MODEM_IMAGE_DEVICE, ARIES_MODEM_IMAGE_SIZE, 0x1000, 0); + if (modem_image_data == NULL) { + ipc_client_log(client, "Reading modem image data failed"); + goto error; + } + ipc_client_log(client, "Read modem image data"); + + onedram_fd = open(ARIES_ONEDRAM_DEVICE, O_RDWR); + if (onedram_fd < 0) { + ipc_client_log(client, "Opening onedram failed"); + goto error; + } + ipc_client_log(client, "Opened onedram"); + + rc = network_iface_down(ARIES_MODEM_IFACE, AF_PHONET, SOCK_DGRAM); + if (rc < 0) { + ipc_client_log(client, "Turning modem network iface down failed"); + goto error; + } + ipc_client_log(client, "Turned modem network iface down"); + + rc = client->handlers->power_on(client->handlers->power_data); + if (rc < 0) { + ipc_client_log(client, "Powering the modem off failed"); + goto error; + } + ipc_client_log(client, "Powered the modem off"); + + usleep(1000); + + rc = client->handlers->power_off(client->handlers->power_data); + if (rc < 0) { + ipc_client_log(client, "Powering the modem on failed"); + goto error; + } + ipc_client_log(client, "Powered the modem on"); + + serial_fd = open(ARIES_MODEM_SERIAL_DEVICE, O_RDWR | O_NDELAY); + if (serial_fd < 0) { + ipc_client_log(client, "Opening serial failed"); + goto error; + } + ipc_client_log(client, "Opened serial"); + + usleep(100000); + + p = (unsigned char *) modem_image_data; + + rc = xmm6160_psi_send(client, serial_fd, (void *) p, ARIES_PSI_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6160 PSI failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6160 PSI"); + + p += ARIES_PSI_SIZE; + + onedram_init = 0; + + FD_ZERO(&fds); + FD_SET(onedram_fd, &fds); + + timeout.tv_sec = 4; + timeout.tv_usec = 0; + + i = 0; + do { + rc = select(onedram_fd + 1, &fds, NULL, NULL, &timeout); + if (rc <= 0) { + ipc_client_log(client, "Reading onedram init failed"); + goto error; + } + + rc = read(onedram_fd, &onedram_init, sizeof(onedram_init)); + if (rc < (int) sizeof(onedram_init)) { + ipc_client_log(client, "Reading onedram init failed"); + goto error; + } + + if (i++ > 50) { + ipc_client_log(client, "Reading onedram init failed"); + goto error; + } + } while (onedram_init != ARIES_ONEDRAM_INIT); + ipc_client_log(client, "Read onedram init (0x%x)", onedram_init); + + onedram_address = mmap(NULL, ARIES_ONEDRAM_MEMORY_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, onedram_fd, 0); + if (onedram_address == NULL || onedram_address == (void *) 0xffffffff) { + ipc_client_log(client, "Mapping onedram to memory failed"); + goto error; + } + ipc_client_log(client, "Mapped onedram to memory"); + + pp = (unsigned char *) onedram_address; + + rc = xmm6160_firmware_send(client, -1, (void *) pp, (void *) p, ARIES_MODEM_IMAGE_SIZE - ARIES_PSI_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6160 firmware failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6160 firmware"); + + pp = (unsigned char *) onedram_address + ARIES_ONEDRAM_NV_DATA_OFFSET; + + rc = xmm6160_nv_data_send(client, -1, pp); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6160 nv_data failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6160 nv_data"); + + munmap(onedram_address, ARIES_ONEDRAM_MEMORY_SIZE); + onedram_address = NULL; + + rc = ioctl(onedram_fd, ONEDRAM_REL_SEM); + if (rc < 0) + goto error; + + onedram_magic = ARIES_ONEDRAM_MAGIC; + rc = write(onedram_fd, &onedram_magic, sizeof(onedram_magic)); + if (rc < (int) sizeof(onedram_magic)) { + ipc_client_log(client, "Writing onedram magic failed"); + goto error; + } + ipc_client_log(client, "Wrote onedram magic"); + + FD_ZERO(&fds); + FD_SET(onedram_fd, &fds); + + timeout.tv_sec = 4; + timeout.tv_usec = 0; + + i = 0; + do { + rc = select(onedram_fd + 1, &fds, NULL, NULL, &timeout); + if (rc <= 0) { + ipc_client_log(client, "Reading onedram deinit failed"); + goto error; + } + + rc = read(onedram_fd, &onedram_deinit, sizeof(onedram_deinit)); + if (rc < (int) sizeof(onedram_deinit)) { + ipc_client_log(client, "Reading onedram deinit failed"); + goto error; + } + + if (i++ > 50) { + ipc_client_log(client, "Reading onedram deinit failed"); + goto error; + } + } while (onedram_deinit != ARIES_ONEDRAM_DEINIT); + ipc_client_log(client, "Read onedram deinit (0x%x)", onedram_deinit); + + rc = 0; + goto complete; + +error: + rc = -1; + +complete: + if (modem_image_data != NULL) + free(modem_image_data); + + if (serial_fd >= 0) + close(serial_fd); + + if (onedram_address != NULL) + munmap(onedram_address, ARIES_ONEDRAM_MEMORY_SIZE); + + if (onedram_fd >= 0) + close(onedram_fd); + + return rc; +} + +int aries_fmt_send(struct ipc_client *client, struct ipc_message *message) +{ + struct ipc_fmt_header header; + void *buffer; + size_t length; + size_t count = 0; + size_t chunk; + unsigned char *p; + int rc; + + if (client == NULL || client->handlers == NULL || client->handlers->write == NULL || message == NULL) + return -1; + + ipc_fmt_header_setup(&header, message); + + length = header.length; + buffer = calloc(1, length); + + memcpy(buffer, &header, sizeof(struct ipc_fmt_header)); + + if (message->data != NULL && message->size > 0) { + p = (unsigned char *) buffer + sizeof(header); + memcpy(p, message->data, message->size); + } + + ipc_client_log_send(client, message, __func__); + + p = (unsigned char *) buffer; + + while (count < length) { + chunk = length - count < ARIES_BUFFER_LENGTH ? length - count : ARIES_BUFFER_LENGTH; + + rc = client->handlers->write(client->handlers->transport_data, p, chunk); + if (rc < 0) { + ipc_client_log(client, "Writing FMT data failed"); + goto error; + } + + count += rc; + p += rc; + } + + rc = 0; + goto complete; + +error: + rc = -1; + +complete: + if (buffer != NULL) + free(buffer); + + return rc; +} + +int aries_fmt_recv(struct ipc_client *client, struct ipc_message *message) +{ + struct ipc_fmt_header *header; + void *buffer; + size_t length; + size_t count = 0; + size_t chunk; + unsigned char *p; + int rc; + + if (client == NULL || client->handlers == NULL || client->handlers->read == NULL || message == NULL) + return -1; + + length = ARIES_BUFFER_LENGTH; + buffer = calloc(1, length); + + rc = client->handlers->read(client->handlers->transport_data, buffer, length); + if (rc < (int) sizeof(struct ipc_fmt_header)) { + ipc_client_log(client, "Reading FMT header failed"); + goto error; + } + + header = (struct ipc_fmt_header *) buffer; + + ipc_fmt_message_setup(header, message); + + length = header->length - sizeof(struct ipc_fmt_header); + if (length > 0) { + message->size = length; + message->data = calloc(1, length); + + count = rc - sizeof(struct ipc_fmt_header); + if (count > 0) { + p = (unsigned char *) buffer + sizeof(struct ipc_fmt_header); + memcpy(message->data, p, count); + } + } + + p = (unsigned char *) message->data + count; + + while (count < length) { + chunk = length - count < ARIES_BUFFER_LENGTH ? length - count : ARIES_BUFFER_LENGTH; + + rc = client->handlers->read(client->handlers->transport_data, p, chunk); + if (rc < 0) { + ipc_client_log(client, "Reading FMT data failed"); + goto error; + } + + count += rc; + p += rc; + } + + ipc_client_log_recv(client, message, __func__); + + rc = 0; + goto complete; + +error: + rc = -1; + +complete: + if (buffer != NULL) + free(buffer); + + return rc; +} + +int aries_rfs_send(struct ipc_client *client, struct ipc_message *message) +{ + struct ipc_rfs_header header; + void *buffer; + size_t length; + size_t count = 0; + size_t chunk; + unsigned char *p; + int rc; + + if (client == NULL || client->handlers == NULL || client->handlers->write == NULL || message == NULL) + return -1; + + ipc_rfs_header_setup(&header, message); + + length = header.length; + buffer = calloc(1, length); + + memcpy(buffer, &header, sizeof(header)); + if (message->data != NULL && message->size > 0) { + p = (unsigned char *) buffer + sizeof(header); + memcpy(p, message->data, message->size); + } + + ipc_client_log_send(client, message, __func__); + + p = (unsigned char *) buffer; + + while (count < length) { + chunk = length - count < ARIES_BUFFER_LENGTH ? length - count : ARIES_BUFFER_LENGTH; + + rc = client->handlers->write(client->handlers->transport_data, p, chunk); + if (rc < 0) { + ipc_client_log(client, "Writing RFS data failed"); + goto error; + } + + count += rc; + p += rc; + } + + rc = 0; + goto complete; + +error: + rc = -1; + +complete: + if (buffer != NULL) + free(buffer); + + return rc; +} + +int aries_rfs_recv(struct ipc_client *client, struct ipc_message *message) +{ + struct ipc_rfs_header *header; + void *buffer; + size_t length; + size_t count = 0; + size_t chunk; + unsigned char *p; + int rc; + + if (client == NULL || client->handlers == NULL || client->handlers->read == NULL || message == NULL) + return -1; + + length = ARIES_BUFFER_LENGTH; + buffer = calloc(1, length); + + rc = client->handlers->read(client->handlers->transport_data, buffer, length); + if (rc < (int) sizeof(struct ipc_rfs_header)) { + ipc_client_log(client, "Reading RFS header failed"); + goto error; + } + + header = (struct ipc_rfs_header *) buffer; + + ipc_rfs_message_setup(header, message); + + length = header->length - sizeof(struct ipc_rfs_header); + if (length > 0) { + message->size = length; + message->data = calloc(1, length); + + count = rc - sizeof(struct ipc_rfs_header); + if (count > 0) { + p = (unsigned char *) buffer + sizeof(struct ipc_rfs_header); + memcpy(message->data, p, count); + } + } + + p = (unsigned char *) message->data + count; + + while (count < length) { + chunk = length - count < ARIES_BUFFER_LENGTH ? length - count : ARIES_BUFFER_LENGTH; + + rc = client->handlers->read(client->handlers->transport_data, p, chunk); + if (rc < 0) { + ipc_client_log(client, "Reading RFS data failed"); + goto error; + } + + count += rc; + p += rc; + } + + ipc_client_log_recv(client, message, __func__); + + rc = 0; + goto complete; + +error: + rc = -1; + +complete: + if (buffer != NULL) + free(buffer); + + return rc; +} + +int aries_open(void *data, int type) +{ + struct aries_transport_data *transport_data; + struct sockaddr_pn *spn; + struct ifreq ifr; + int reuse; + int socket_rfs_magic; + int fd; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct aries_transport_data *) data; + memset(data, 0, sizeof(struct aries_transport_data)); + + spn = &transport_data->spn; + + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_name, ARIES_MODEM_IFACE, IFNAMSIZ); + + spn->spn_family = AF_PHONET; + spn->spn_dev = 0; + + switch (type) { + case IPC_CLIENT_TYPE_FMT: + spn->spn_resource = ARIES_MODEM_FMT_SPN; + break; + case IPC_CLIENT_TYPE_RFS: + spn->spn_resource = ARIES_MODEM_RFS_SPN; + break; + default: + break; + } + + fd = socket(AF_PHONET, SOCK_DGRAM, 0); + if (fd < 0) + return -1; + + rc = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifr.ifr_name, IFNAMSIZ); + if (rc < 0) + return -1; + + rc = ioctl(fd, SIOCGIFINDEX, &ifr); + if (rc < 0) + return -1; + + reuse = 1; + rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)); + if (rc < 0) + return -1; + + rc = bind(fd, (const struct sockaddr *) spn, sizeof(struct sockaddr_pn)); + if (rc < 0) + return -1; + + transport_data->fd = fd; + + if (type == IPC_CLIENT_TYPE_RFS) + { + socket_rfs_magic = ARIES_SOCKET_RFS_MAGIC; + rc = setsockopt(fd, SOL_SOCKET, SO_IPC_RFS, &socket_rfs_magic, sizeof(socket_rfs_magic)); + if (rc < 0) + return -1; + } + + rc = network_iface_up(ARIES_MODEM_IFACE, AF_PHONET, SOCK_DGRAM); + if (rc < 0) + return -1; + + return 0; +} + +int aries_close(void *data) +{ + struct aries_transport_data *transport_data; + int fd; + + if (data == NULL) + return -1; + + transport_data = (struct aries_transport_data *) data; + + fd = transport_data->fd; + if (fd < 0) + return -1; + + transport_data->fd = -1; + close(fd); + + return 0; +} + +int aries_read(void *data, void *buffer, size_t length) +{ + struct aries_transport_data *transport_data; + int spn_size; + int fd; + int rc; + + if (data == NULL || buffer == NULL || length == 0) + return -1; + + transport_data = (struct aries_transport_data *) data; + + fd = transport_data->fd; + if (fd < 0) + return -1; + + spn_size = sizeof(struct sockaddr_pn); + + rc = recvfrom(fd, buffer, length, 0, (struct sockaddr *) &transport_data->spn, &spn_size); + return rc; +} + +int aries_write(void *data, const void *buffer, size_t length) +{ + struct aries_transport_data *transport_data; + int spn_size; + int fd; + int rc; + + if (data == NULL || buffer == NULL || length == 0) + return -1; + + transport_data = (struct aries_transport_data *) data; + + fd = transport_data->fd; + if (fd < 0) + return -1; + + spn_size = sizeof(struct sockaddr_pn); + + rc = sendto(fd, buffer, length, 0, (const struct sockaddr *) &transport_data->spn, spn_size); + return rc; +} + +int aries_poll(void *data, struct timeval *timeout) +{ + struct aries_transport_data *transport_data; + fd_set fds; + int fd; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct aries_transport_data *) data; + + fd = transport_data->fd; + if (fd < 0) + return -1; + + FD_ZERO(&fds); + FD_SET(fd, &fds); + + rc = select(fd + 1, &fds, NULL, NULL, timeout); + return rc; +} + +int aries_power_on(void *data) +{ + char buffer[] = "on\n"; + int value; + int rc; + + value = sysfs_value_read(ARIES_MODEMCTL_STATUS_SYSFS); + if (value < 0) + return -1; + + // The modem is already on + if (value == 1) + return 0; + + rc = sysfs_string_write(ARIES_MODEMCTL_CONTROL_SYSFS, (char *) &buffer, strlen(buffer)); + if (rc < 0) + return -1; + + return 0; +} + +int aries_power_off(void *data) +{ + char buffer[] = "off\n"; + int value; + int rc; + + value = sysfs_value_read(ARIES_MODEMCTL_STATUS_SYSFS); + if (value < 0) + return -1; + + // The modem is already off + if (value == 0) + return 0; + + rc = sysfs_string_write(ARIES_MODEMCTL_CONTROL_SYSFS, (char *) &buffer, strlen(buffer)); + if (rc < 0) + return -1; + + return 0; +} + +int aries_data_create(void **transport_data, void **power_data, + void **gprs_data) +{ + if (transport_data == NULL) + return -1; + + *transport_data = calloc(1, sizeof(struct aries_transport_data)); + + return 0; +} + +int aries_data_destroy(void *transport_data, void *power_data, void *gprs_data) +{ + if (transport_data == NULL) + return -1; + + free(transport_data); + + return 0; +} + +int aries_gprs_activate(void *data, int cid) +{ + int rc; + + rc = sysfs_value_write(ARIES_MODEM_PDP_ACTIVATE_SYSFS, cid); + if (rc < 0) + return -1; + + return 0; +} + +int aries_gprs_deactivate(void *data, int cid) +{ + int rc; + + rc = sysfs_value_write(ARIES_MODEM_PDP_DEACTIVATE_SYSFS, cid); + if (rc < 0) + return -1; + + return 0; +} + +char *aries_gprs_get_iface(int cid) +{ + char *iface = NULL; + struct ifreq ifr; + int fd; + int rc; + int i; + + memset(&ifr, 0, sizeof(ifr)); + + fd = socket(AF_PHONET, SOCK_DGRAM, 0); + if (fd < 0) + return NULL; + + for (i = (ARIES_GPRS_IFACE_COUNT - 1); i >= 0; i--) { + sprintf(ifr.ifr_name, "%s%d", ARIES_GPRS_IFACE_PREFIX, i); + rc = ioctl(fd, SIOCGIFFLAGS, &ifr); + if (rc < 0 || ifr.ifr_flags & IFF_UP) { + continue; + } else { + asprintf(&iface, "%s%d", ARIES_GPRS_IFACE_PREFIX, i); + return iface; + } + } + + return NULL; +} + +int aries_gprs_get_capabilities(struct ipc_client_gprs_capabilities *capabilities) +{ + if (capabilities == NULL) + return -1; + + capabilities->cid_count = ARIES_GPRS_IFACE_COUNT; + + return 0; +} + +struct ipc_client_ops aries_fmt_ops = { + .boot = aries_boot, + .send = aries_fmt_send, + .recv = aries_fmt_recv, +}; + +struct ipc_client_ops aries_rfs_ops = { + .boot = NULL, + .send = aries_rfs_send, + .recv = aries_rfs_recv, +}; + +struct ipc_client_handlers aries_handlers = { + .open = aries_open, + .close = aries_close, + .read = aries_read, + .write = aries_write, + .poll = aries_poll, + .transport_data = NULL, + .power_on = aries_power_on, + .power_off = aries_power_off, + .power_data = NULL, + .gprs_activate = aries_gprs_activate, + .gprs_deactivate = aries_gprs_deactivate, + .gprs_data = NULL, + .data_create = aries_data_create, + .data_destroy = aries_data_destroy, +}; + +struct ipc_client_gprs_specs aries_gprs_specs = { + .gprs_get_iface = aries_gprs_get_iface, + .gprs_get_capabilities = aries_gprs_get_capabilities, +}; + +struct ipc_client_nv_data_specs aries_nv_data_specs = { + .nv_data_path = XMM6160_NV_DATA_PATH, + .nv_data_md5_path = XMM6160_NV_DATA_MD5_PATH, + .nv_data_backup_path = XMM6160_NV_DATA_BACKUP_PATH, + .nv_data_backup_md5_path = XMM6160_NV_DATA_BACKUP_MD5_PATH, + .nv_data_secret = XMM6160_NV_DATA_SECRET, + .nv_data_size = XMM6160_NV_DATA_SIZE, + .nv_data_chunk_size = XMM6160_NV_DATA_CHUNK_SIZE, +}; + +// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/aries/aries.h b/samsung-ipc/devices/aries/aries.h new file mode 100644 index 0000000..efa7870 --- /dev/null +++ b/samsung-ipc/devices/aries/aries.h @@ -0,0 +1,65 @@ +/* + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2011 Igor Almeida + * Copyright (C) 2011-2014 Paul Kocialkowski + * + * libsamsung-ipc 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 2 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc 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 libsamsung-ipc. If not, see . + */ + +#include "phonet.h" + +#ifndef __ARIES_H__ +#define __ARIES_H__ + +#define ARIES_MODEM_IMAGE_SIZE 0xA00000 +#define ARIES_PSI_SIZE 0x5000 +#define ARIES_ONEDRAM_NV_DATA_OFFSET 0xD80000 +#define ARIES_ONEDRAM_MEMORY_SIZE 0xFFF000 +#define ARIES_ONEDRAM_INIT 0x12341234 +#define ARIES_ONEDRAM_MAGIC 0x45674567 +#define ARIES_ONEDRAM_DEINIT 0xABCDABCD +#define ARIES_SOCKET_RFS_MAGIC 0x80000 +#define ARIES_BUFFER_LENGTH 4032 + +#define SO_IPC_RFS 0x21 +#define ARIES_MODEM_FMT_SPN 0x01 +#define ARIES_MODEM_RFS_SPN 0x41 + +#define ARIES_MODEM_IMAGE_DEVICE "/dev/block/bml12" +#define ARIES_MODEM_SERIAL_DEVICE "/dev/s3c2410_serial3" +#define ARIES_ONEDRAM_DEVICE "/dev/onedram" +#define ARIES_MODEMCTL_STATUS_SYSFS "/sys/class/modemctl/xmm/status" +#define ARIES_MODEMCTL_CONTROL_SYSFS "/sys/class/modemctl/xmm/control" +#define ARIES_MODEM_IFACE "svnet0" +#define ARIES_MODEM_PDP_ACTIVATE_SYSFS "/sys/class/net/svnet0/pdp/activate" +#define ARIES_MODEM_PDP_DEACTIVATE_SYSFS "/sys/class/net/svnet0/pdp/deactivate" + +#define ARIES_GPRS_IFACE_PREFIX "pdp" +#define ARIES_GPRS_IFACE_COUNT 3 + +struct aries_transport_data { + struct sockaddr_pn spn; + int fd; +}; + +extern struct ipc_client_ops aries_fmt_ops; +extern struct ipc_client_ops aries_rfs_ops; +extern struct ipc_client_handlers aries_handlers; +extern struct ipc_client_gprs_specs aries_gprs_specs; +extern struct ipc_client_nv_data_specs aries_nv_data_specs; + +#endif + +// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/aries/aries_ipc.c b/samsung-ipc/devices/aries/aries_ipc.c deleted file mode 100644 index aede718..0000000 --- a/samsung-ipc/devices/aries/aries_ipc.c +++ /dev/null @@ -1,816 +0,0 @@ -/* - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2011 Joerie de Gram - * Copyright (C) 2011 Simon Busch - * Copyright (C) 2011 Igor Almeida - * Copyright (C) 2011-2014 Paul Kocialkowski - * - * libsamsung-ipc 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 2 of the License, or - * (at your option) any later version. - * - * libsamsung-ipc 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 libsamsung-ipc. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "onedram.h" -#include "phonet.h" - -#include "xmm6160.h" -#include "aries_ipc.h" - -int aries_ipc_bootstrap(struct ipc_client *client) -{ - void *modem_image_data = NULL; - void *onedram_address = NULL; - unsigned int onedram_init; - unsigned int onedram_magic; - unsigned int onedram_deinit; - - int onedram_fd = -1; - int serial_fd = -1; - - struct timeval timeout; - fd_set fds; - - unsigned char *p; - unsigned char *pp; - int rc; - int i; - - if (client == NULL || client->handlers == NULL || client->handlers->power_on == NULL || client->handlers->power_off == NULL) - return -1; - - ipc_client_log(client, "Starting aries modem bootstrap"); - - modem_image_data = file_data_read(ARIES_MODEM_IMAGE_DEVICE, ARIES_MODEM_IMAGE_SIZE, 0x1000, 0); - if (modem_image_data == NULL) { - ipc_client_log(client, "Reading modem image data failed"); - goto error; - } - ipc_client_log(client, "Read modem image data"); - - onedram_fd = open(ARIES_ONEDRAM_DEVICE, O_RDWR); - if (onedram_fd < 0) { - ipc_client_log(client, "Opening onedram failed"); - goto error; - } - ipc_client_log(client, "Opened onedram"); - - rc = network_iface_down(ARIES_MODEM_IFACE, AF_PHONET, SOCK_DGRAM); - if (rc < 0) { - ipc_client_log(client, "Turning modem network iface down failed"); - goto error; - } - ipc_client_log(client, "Turned modem network iface down"); - - rc = client->handlers->power_on(client->handlers->power_data); - if (rc < 0) { - ipc_client_log(client, "Powering the modem off failed"); - goto error; - } - ipc_client_log(client, "Powered the modem off"); - - usleep(1000); - - rc = client->handlers->power_off(client->handlers->power_data); - if (rc < 0) { - ipc_client_log(client, "Powering the modem on failed"); - goto error; - } - ipc_client_log(client, "Powered the modem on"); - - serial_fd = open(ARIES_MODEM_SERIAL_DEVICE, O_RDWR | O_NDELAY); - if (serial_fd < 0) { - ipc_client_log(client, "Opening serial failed"); - goto error; - } - ipc_client_log(client, "Opened serial"); - - usleep(100000); - - p = (unsigned char *) modem_image_data; - - rc = xmm6160_psi_send(client, serial_fd, (void *) p, ARIES_PSI_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6160 PSI failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6160 PSI"); - - p += ARIES_PSI_SIZE; - - onedram_init = 0; - - FD_ZERO(&fds); - FD_SET(onedram_fd, &fds); - - timeout.tv_sec = 4; - timeout.tv_usec = 0; - - i = 0; - do { - rc = select(onedram_fd + 1, &fds, NULL, NULL, &timeout); - if (rc <= 0) { - ipc_client_log(client, "Reading onedram init failed"); - goto error; - } - - rc = read(onedram_fd, &onedram_init, sizeof(onedram_init)); - if (rc < (int) sizeof(onedram_init)) { - ipc_client_log(client, "Reading onedram init failed"); - goto error; - } - - if (i++ > 50) { - ipc_client_log(client, "Reading onedram init failed"); - goto error; - } - } while (onedram_init != ARIES_ONEDRAM_INIT); - ipc_client_log(client, "Read onedram init (0x%x)", onedram_init); - - onedram_address = mmap(NULL, ARIES_ONEDRAM_MEMORY_SIZE, PROT_READ|PROT_WRITE, MAP_SHARED, onedram_fd, 0); - if (onedram_address == NULL || onedram_address == (void *) 0xffffffff) { - ipc_client_log(client, "Mapping onedram to memory failed"); - goto error; - } - ipc_client_log(client, "Mapped onedram to memory"); - - pp = (unsigned char *) onedram_address; - - rc = xmm6160_firmware_send(client, -1, (void *) pp, (void *) p, ARIES_MODEM_IMAGE_SIZE - ARIES_PSI_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6160 firmware failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6160 firmware"); - - pp = (unsigned char *) onedram_address + ARIES_ONEDRAM_NV_DATA_OFFSET; - - rc = xmm6160_nv_data_send(client, -1, pp); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6160 nv_data failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6160 nv_data"); - - munmap(onedram_address, ARIES_ONEDRAM_MEMORY_SIZE); - onedram_address = NULL; - - rc = ioctl(onedram_fd, ONEDRAM_REL_SEM); - if (rc < 0) - goto error; - - onedram_magic = ARIES_ONEDRAM_MAGIC; - rc = write(onedram_fd, &onedram_magic, sizeof(onedram_magic)); - if (rc < (int) sizeof(onedram_magic)) { - ipc_client_log(client, "Writing onedram magic failed"); - goto error; - } - ipc_client_log(client, "Wrote onedram magic"); - - FD_ZERO(&fds); - FD_SET(onedram_fd, &fds); - - timeout.tv_sec = 4; - timeout.tv_usec = 0; - - i = 0; - do { - rc = select(onedram_fd + 1, &fds, NULL, NULL, &timeout); - if (rc <= 0) { - ipc_client_log(client, "Reading onedram deinit failed"); - goto error; - } - - rc = read(onedram_fd, &onedram_deinit, sizeof(onedram_deinit)); - if (rc < (int) sizeof(onedram_deinit)) { - ipc_client_log(client, "Reading onedram deinit failed"); - goto error; - } - - if (i++ > 50) { - ipc_client_log(client, "Reading onedram deinit failed"); - goto error; - } - } while (onedram_deinit != ARIES_ONEDRAM_DEINIT); - ipc_client_log(client, "Read onedram deinit (0x%x)", onedram_deinit); - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (modem_image_data != NULL) - free(modem_image_data); - - if (serial_fd >= 0) - close(serial_fd); - - if (onedram_address != NULL) - munmap(onedram_address, ARIES_ONEDRAM_MEMORY_SIZE); - - if (onedram_fd >= 0) - close(onedram_fd); - - return rc; -} - -int aries_ipc_fmt_send(struct ipc_client *client, struct ipc_message_info *request) -{ - struct ipc_fmt_header header; - void *buffer = NULL; - unsigned char *p; - int length = 0; - int count = 0; - int chunk; - int rc; - - if (client == NULL || client->handlers == NULL || client->handlers->write == NULL || request == NULL) - return -1; - - ipc_fmt_header_fill(&header, request); - - length = header.length; - buffer = malloc(header.length); - - memcpy(buffer, &header, sizeof(struct ipc_fmt_header)); - if (request->data != NULL && request->length > 0) { - p = (unsigned char *) buffer + sizeof(header); - memcpy(p, request->data, request->length); - } - - ipc_client_log_send(client, request, __func__); - - p = (unsigned char *) buffer; - - while (count < length) { - chunk = length - count < ARIES_BUFFER_LENGTH ? length - count : ARIES_BUFFER_LENGTH; - - rc = client->handlers->write(client->handlers->transport_data, p, chunk); - if (rc < 0) { - ipc_client_log(client, "Writing FMT data to the modem failed"); - goto error; - } - - count += rc; - p += rc; - } - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (buffer != NULL) - free(buffer); - - return rc; -} - -int aries_ipc_fmt_recv(struct ipc_client *client, struct ipc_message_info *response) -{ - struct ipc_fmt_header *header; - void *buffer = NULL; - unsigned char *p; - int length = 0; - int count = 0; - int chunk; - int rc; - - if (client == NULL || client->handlers == NULL || client->handlers->read == NULL || response == NULL) - return -1; - - length = ARIES_BUFFER_LENGTH; - buffer = malloc(length); - - rc = client->handlers->read(client->handlers->transport_data, buffer, length); - if (rc < (int) sizeof(struct ipc_fmt_header)) { - ipc_client_log(client, "Reading FMT header from the modem failed"); - goto error; - } - - header = (struct ipc_fmt_header *) buffer; - - ipc_fmt_message_fill(header, response); - - length = header->length - sizeof(struct ipc_fmt_header); - if (length > 0) { - response->length = length; - response->data = malloc(length); - - count = rc - sizeof(struct ipc_fmt_header); - if (count > 0) { - p = (unsigned char *) buffer + sizeof(struct ipc_fmt_header); - memcpy(response->data, p, count); - } - } - - p = (unsigned char *) response->data + count; - - while (count < length) { - chunk = length - count < ARIES_BUFFER_LENGTH ? length - count : ARIES_BUFFER_LENGTH; - - rc = client->handlers->read(client->handlers->transport_data, p, chunk); - if (rc < 0) { - ipc_client_log(client, "Reading FMT data from the modem failed"); - goto error; - } - - count += rc; - p += rc; - } - - ipc_client_log_recv(client, response, __func__); - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (buffer != NULL) - free(buffer); - - return rc; -} - -int aries_ipc_rfs_send(struct ipc_client *client, struct ipc_message_info *request) -{ - struct ipc_rfs_header header; - void *buffer = NULL; - unsigned char *p; - int length = 0; - int count = 0; - int chunk; - int rc; - - if (client == NULL || client->handlers == NULL || client->handlers->write == NULL || request == NULL) - return -1; - - ipc_rfs_header_fill(&header, request); - - length = header.length; - buffer = malloc(length); - - memcpy(buffer, &header, sizeof(header)); - if (request->data != NULL && request->length > 0) { - p = (unsigned char *) buffer + sizeof(header); - memcpy(p, request->data, request->length); - } - - ipc_client_log_send(client, request, __func__); - - p = (unsigned char *) buffer; - - while (count < length) { - chunk = length - count < ARIES_BUFFER_LENGTH ? length - count : ARIES_BUFFER_LENGTH; - - rc = client->handlers->write(client->handlers->transport_data, p, chunk); - if (rc < 0) { - ipc_client_log(client, "Writing RFS data to the modem failed"); - goto error; - } - - count += rc; - p += rc; - } - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (buffer != NULL) - free(buffer); - - return rc; -} - -int aries_ipc_rfs_recv(struct ipc_client *client, struct ipc_message_info *response) -{ - struct ipc_rfs_header *header; - void *buffer = NULL; - unsigned char *p; - int length = 0; - int count = 0; - int chunk; - int rc; - - if (client == NULL || client->handlers == NULL || client->handlers->read == NULL || response == NULL) - return -1; - - length = ARIES_BUFFER_LENGTH; - buffer = malloc(length); - - rc = client->handlers->read(client->handlers->transport_data, buffer, length); - if (rc < (int) sizeof(struct ipc_rfs_header)) { - ipc_client_log(client, "Reading RFS header from the modem failed"); - goto error; - } - - header = (struct ipc_rfs_header *) buffer; - - ipc_rfs_message_fill(header, response); - - length = header->length - sizeof(struct ipc_rfs_header); - if (length > 0) { - response->length = length; - response->data = malloc(length); - - count = rc - sizeof(struct ipc_rfs_header); - if (count > 0) { - p = (unsigned char *) buffer + sizeof(struct ipc_rfs_header); - memcpy(response->data, p, count); - } - } - - p = (unsigned char *) response->data + count; - - while (count < length) { - chunk = length - count < ARIES_BUFFER_LENGTH ? length - count : ARIES_BUFFER_LENGTH; - - rc = client->handlers->read(client->handlers->transport_data, p, chunk); - if (rc < 0) { - ipc_client_log(client, "Reading RFS data from the modem failed"); - goto error; - } - - count += rc; - p += rc; - } - - ipc_client_log_recv(client, response, __func__); - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (buffer != NULL) - free(buffer); - - return rc; -} - -int aries_ipc_open(void *data, int type) -{ - struct aries_ipc_transport_data *transport_data; - struct sockaddr_pn *spn; - struct ifreq ifr; - - int reuse; - int socket_rfs_magic; - - int fd; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct aries_ipc_transport_data *) data; - memset(data, 0, sizeof(struct aries_ipc_transport_data)); - - spn = &transport_data->spn; - - memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, ARIES_MODEM_IFACE, IFNAMSIZ); - - spn->spn_family = AF_PHONET; - spn->spn_dev = 0; - - switch (type) { - case IPC_CLIENT_TYPE_FMT: - spn->spn_resource = ARIES_MODEM_FMT_SPN; - break; - case IPC_CLIENT_TYPE_RFS: - spn->spn_resource = ARIES_MODEM_RFS_SPN; - break; - default: - break; - } - - fd = socket(AF_PHONET, SOCK_DGRAM, 0); - if (fd < 0) - return -1; - - rc = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifr.ifr_name, IFNAMSIZ); - if (rc < 0) - return -1; - - rc = ioctl(fd, SIOCGIFINDEX, &ifr); - if (rc < 0) - return -1; - - reuse = 1; - rc = setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &reuse, sizeof(reuse)); - if (rc < 0) - return -1; - - rc = bind(fd, (const struct sockaddr *) spn, sizeof(struct sockaddr_pn)); - if (rc < 0) - return -1; - - transport_data->fd = fd; - - if (type == IPC_CLIENT_TYPE_RFS) - { - socket_rfs_magic = ARIES_SOCKET_RFS_MAGIC; - rc = setsockopt(fd, SOL_SOCKET, SO_IPC_RFS, &socket_rfs_magic, sizeof(socket_rfs_magic)); - if (rc < 0) - return -1; - } - - rc = network_iface_up(ARIES_MODEM_IFACE, AF_PHONET, SOCK_DGRAM); - if (rc < 0) - return -1; - - return 0; -} - -int aries_ipc_close(void *data) -{ - struct aries_ipc_transport_data *transport_data; - int fd; - - if (data == NULL) - return -1; - - transport_data = (struct aries_ipc_transport_data *) data; - - fd = transport_data->fd; - if (fd < 0) - return -1; - - transport_data->fd = -1; - close(fd); - - return 0; -} - -int aries_ipc_read(void *data, void *buffer, unsigned int length) -{ - struct aries_ipc_transport_data *transport_data; - int spn_size; - int fd; - int rc; - - if (data == NULL || buffer == NULL || length == 0) - return -1; - - transport_data = (struct aries_ipc_transport_data *) data; - - fd = transport_data->fd; - if (fd < 0) - return -1; - - spn_size = sizeof(struct sockaddr_pn); - - rc = recvfrom(fd, buffer, length, 0, (const struct sockaddr *) &transport_data->spn, &spn_size); - return rc; -} - -int aries_ipc_write(void *data, void *buffer, unsigned int length) -{ - struct aries_ipc_transport_data *transport_data; - int spn_size; - int fd; - int rc; - - if (data == NULL || buffer == NULL || length == 0) - return -1; - - transport_data = (struct aries_ipc_transport_data *) data; - - fd = transport_data->fd; - if (fd < 0) - return -1; - - spn_size = sizeof(struct sockaddr_pn); - - rc = sendto(fd, buffer, length, 0, (const struct sockaddr *) &transport_data->spn, spn_size); - return rc; -} - -int aries_ipc_poll(void *data, struct timeval *timeout) -{ - struct aries_ipc_transport_data *transport_data; - fd_set fds; - int fd; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct aries_ipc_transport_data *) data; - - fd = transport_data->fd; - if (fd < 0) - return -1; - - FD_ZERO(&fds); - FD_SET(fd, &fds); - - rc = select(fd + 1, &fds, NULL, NULL, timeout); - return rc; -} - -int aries_ipc_power_on(void *data) -{ - char buffer[] = "on\n"; - int value; - int rc; - - value = sysfs_value_read(ARIES_MODEMCTL_STATUS_SYSFS); - if (value < 0) - return -1; - - // The modem is already on - if (value == 1) - return 0; - - rc = sysfs_string_write(ARIES_MODEMCTL_CONTROL_SYSFS, (char *) &buffer, strlen(buffer)); - if (rc < 0) - return -1; - - return 0; -} - -int aries_ipc_power_off(void *data) -{ - char buffer[] = "off\n"; - int value; - int rc; - - value = sysfs_value_read(ARIES_MODEMCTL_STATUS_SYSFS); - if (value < 0) - return -1; - - // The modem is already off - if (value == 0) - return 0; - - rc = sysfs_string_write(ARIES_MODEMCTL_CONTROL_SYSFS, (char *) &buffer, strlen(buffer)); - if (rc < 0) - return -1; - - return 0; -} - -int aries_ipc_data_create(void **transport_data, void **power_data, void **gprs_data) -{ - if (transport_data == NULL) - return -1; - - *transport_data = (void *) malloc(sizeof(struct aries_ipc_transport_data)); - memset(*transport_data, 0, sizeof(struct aries_ipc_transport_data)); - - return 0; -} - -int aries_ipc_data_destroy(void *transport_data, void *power_data, void *gprs_data) -{ - if (transport_data == NULL) - return -1; - - free(transport_data); - - return 0; -} - -int aries_ipc_gprs_activate(void *data, int cid) -{ - int rc; - - rc = sysfs_value_write(ARIES_MODEM_PDP_ACTIVATE_SYSFS, cid); - if (rc < 0) - return -1; - - return 0; -} - -int aries_ipc_gprs_deactivate(void *data, int cid) -{ - int rc; - - rc = sysfs_value_write(ARIES_MODEM_PDP_DEACTIVATE_SYSFS, cid); - if (rc < 0) - return -1; - - return 0; -} - -char *aries_ipc_gprs_get_iface(int cid) -{ - struct ifreq ifr; - char *iface = NULL; - int fd; - int rc; - int i; - - memset(&ifr, 0, sizeof(ifr)); - - fd = socket(AF_PHONET, SOCK_DGRAM, 0); - if (fd < 0) - return NULL; - - for (i = (ARIES_GPRS_IFACE_COUNT - 1); i >= 0; i--) { - sprintf(ifr.ifr_name, "%s%d", ARIES_GPRS_IFACE_PREFIX, i); - rc = ioctl(fd, SIOCGIFFLAGS, &ifr); - if (rc < 0 || ifr.ifr_flags & IFF_UP) { - continue; - } else { - asprintf(&iface, "%s%d", ARIES_GPRS_IFACE_PREFIX, i); - return iface; - } - } - - return NULL; -} - -int aries_ipc_gprs_get_capabilities(struct ipc_client_gprs_capabilities *capabilities) -{ - if (capabilities == NULL) - return -1; - - capabilities->port_list = 1; - capabilities->cid_max = ARIES_GPRS_IFACE_COUNT; - - return 0; -} - -struct ipc_ops aries_ipc_fmt_ops = { - .bootstrap = aries_ipc_bootstrap, - .send = aries_ipc_fmt_send, - .recv = aries_ipc_fmt_recv, -}; - -struct ipc_ops aries_ipc_rfs_ops = { - .bootstrap = NULL, - .send = aries_ipc_rfs_send, - .recv = aries_ipc_rfs_recv, -}; - -struct ipc_handlers aries_ipc_handlers = { - .open = aries_ipc_open, - .close = aries_ipc_close, - .read = aries_ipc_read, - .write = aries_ipc_write, - .poll = aries_ipc_poll, - .transport_data = NULL, - .power_on = aries_ipc_power_on, - .power_off = aries_ipc_power_off, - .power_data = NULL, - .gprs_activate = aries_ipc_gprs_activate, - .gprs_deactivate = aries_ipc_gprs_deactivate, - .gprs_data = NULL, - .data_create = aries_ipc_data_create, - .data_destroy = aries_ipc_data_destroy, -}; - -struct ipc_gprs_specs aries_ipc_gprs_specs = { - .gprs_get_iface = aries_ipc_gprs_get_iface, - .gprs_get_capabilities = aries_ipc_gprs_get_capabilities, -}; - -struct ipc_nv_data_specs aries_ipc_nv_data_specs = { - .nv_data_path = XMM6160_NV_DATA_PATH, - .nv_data_md5_path = XMM6160_NV_DATA_MD5_PATH, - .nv_data_backup_path = XMM6160_NV_DATA_BACKUP_PATH, - .nv_data_backup_md5_path = XMM6160_NV_DATA_BACKUP_MD5_PATH, - .nv_data_secret = XMM6160_NV_DATA_SECRET, - .nv_data_size = XMM6160_NV_DATA_SIZE, - .nv_data_chunk_size = XMM6160_NV_DATA_CHUNK_SIZE, -}; - -// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/aries/aries_ipc.h b/samsung-ipc/devices/aries/aries_ipc.h deleted file mode 100644 index bb42f27..0000000 --- a/samsung-ipc/devices/aries/aries_ipc.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2011 Igor Almeida - * Copyright (C) 2011-2014 Paul Kocialkowski - * - * libsamsung-ipc 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 2 of the License, or - * (at your option) any later version. - * - * libsamsung-ipc 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 libsamsung-ipc. If not, see . - */ - -#include "phonet.h" - -#ifndef __ARIES_IPC_H__ -#define __ARIES_IPC_H__ - -#define ARIES_MODEM_IMAGE_SIZE 0xA00000 -#define ARIES_PSI_SIZE 0x5000 -#define ARIES_ONEDRAM_NV_DATA_OFFSET 0xD80000 -#define ARIES_ONEDRAM_MEMORY_SIZE 0xFFF000 -#define ARIES_ONEDRAM_INIT 0x12341234 -#define ARIES_ONEDRAM_MAGIC 0x45674567 -#define ARIES_ONEDRAM_DEINIT 0xABCDABCD -#define ARIES_SOCKET_RFS_MAGIC 0x80000 -#define ARIES_BUFFER_LENGTH 4032 - -#define SO_IPC_RFS 0x21 -#define ARIES_MODEM_FMT_SPN 0x01 -#define ARIES_MODEM_RFS_SPN 0x41 - -#define ARIES_MODEM_IMAGE_DEVICE "/dev/block/bml12" -#define ARIES_MODEM_SERIAL_DEVICE "/dev/s3c2410_serial3" -#define ARIES_ONEDRAM_DEVICE "/dev/onedram" -#define ARIES_MODEMCTL_STATUS_SYSFS "/sys/class/modemctl/xmm/status" -#define ARIES_MODEMCTL_CONTROL_SYSFS "/sys/class/modemctl/xmm/control" -#define ARIES_MODEM_IFACE "svnet0" -#define ARIES_MODEM_PDP_ACTIVATE_SYSFS "/sys/class/net/svnet0/pdp/activate" -#define ARIES_MODEM_PDP_DEACTIVATE_SYSFS "/sys/class/net/svnet0/pdp/deactivate" - -#define ARIES_GPRS_IFACE_PREFIX "pdp" -#define ARIES_GPRS_IFACE_COUNT 3 - -struct aries_ipc_transport_data { - struct sockaddr_pn spn; - int fd; -}; - -extern struct ipc_ops aries_ipc_fmt_ops; -extern struct ipc_ops aries_ipc_rfs_ops; -extern struct ipc_handlers aries_ipc_handlers; -extern struct ipc_gprs_specs aries_ipc_gprs_specs; -extern struct ipc_nv_data_specs aries_ipc_nv_data_specs; - -#endif - -// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/crespo/crespo.c b/samsung-ipc/devices/crespo/crespo.c new file mode 100644 index 0000000..fe50012 --- /dev/null +++ b/samsung-ipc/devices/crespo/crespo.c @@ -0,0 +1,564 @@ +/* + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2011 Joerie de Gram + * Copyright (C) 2011 Simon Busch + * Copyright (C) 2011-2014 Paul Kocialkowski + * + * libsamsung-ipc 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 2 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc 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 libsamsung-ipc. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "crespo_modem_ctl.h" + +#include "xmm6160.h" +#include "crespo.h" + +int crespo_boot(struct ipc_client *client) +{ + void *modem_image_data = NULL; + int modem_ctl_fd = -1; + int serial_fd = -1; + unsigned char *p; + int rc; + + if (client == NULL) + return -1; + + ipc_client_log(client, "Starting crespo modem boot"); + + modem_image_data = file_data_read(CRESPO_MODEM_IMAGE_DEVICE, CRESPO_MODEM_IMAGE_SIZE, 0x1000, 0); + if (modem_image_data == NULL) { + ipc_client_log(client, "Reading modem image data failed"); + goto error; + } + ipc_client_log(client, "Read modem image data"); + + modem_ctl_fd = open(CRESPO_MODEM_CTL_DEVICE, O_RDWR | O_NDELAY); + if (modem_ctl_fd < 0) { + ipc_client_log(client, "Opening modem ctl failed"); + goto error; + } + ipc_client_log(client, "Opened modem ctl"); + + rc = ioctl(modem_ctl_fd, IOCTL_MODEM_RESET); + if (rc < 0) { + ipc_client_log(client, "Resetting modem failed"); + goto error; + } + ipc_client_log(client, "Reset modem"); + + serial_fd = open(CRESPO_MODEM_SERIAL_DEVICE, O_RDWR | O_NDELAY); + if (serial_fd < 0) { + ipc_client_log(client, "Opening serial failed"); + goto error; + } + ipc_client_log(client, "Opened serial"); + + usleep(100000); + + p = (unsigned char *) modem_image_data; + + rc = xmm6160_psi_send(client, serial_fd, (void *) p, CRESPO_PSI_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6160 PSI failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6160 PSI"); + + p += CRESPO_PSI_SIZE; + + lseek(modem_ctl_fd, 0, SEEK_SET); + + rc = xmm6160_firmware_send(client, modem_ctl_fd, NULL, (void *) p, CRESPO_MODEM_IMAGE_SIZE - CRESPO_PSI_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6160 firmware failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6160 firmware"); + + lseek(modem_ctl_fd, CRESPO_MODEM_CTL_NV_DATA_OFFSET, SEEK_SET); + + rc = xmm6160_nv_data_send(client, modem_ctl_fd, NULL); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6160 nv_data failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6160 nv_data"); + + rc = 0; + goto complete; + +error: + rc = -1; + +complete: + if (modem_image_data != NULL) + free(modem_image_data); + + if (serial_fd >= 0) + close(serial_fd); + + if (modem_ctl_fd >= 0) + close(modem_ctl_fd); + + return rc; +} + +int crespo_fmt_send(struct ipc_client *client, struct ipc_message *message) +{ + struct ipc_fmt_header header; + struct modem_io mio; + int rc; + + if (client == NULL || client->handlers == NULL || client->handlers->write == NULL || message == NULL) + return -1; + + ipc_fmt_header_setup(&header, message); + + memset(&mio, 0, sizeof(struct modem_io)); + mio.size = message->size + sizeof(struct ipc_fmt_header); + mio.data = calloc(1, mio.size); + + memcpy(mio.data, &header, sizeof(struct ipc_fmt_header)); + if (message->data != NULL && message->size > 0) + memcpy((void *) ((unsigned char *) mio.data + sizeof(struct ipc_fmt_header)), message->data, message->size); + + ipc_client_log_send(client, message, __func__); + + rc = client->handlers->write(client->handlers->transport_data, (void *) &mio, sizeof(struct modem_io)); + if (rc < 0) { + ipc_client_log(client, "Writing FMT data failed"); + goto error; + } + + rc = 0; + goto complete; + +error: + rc = -1; + +complete: + if (mio.data != NULL) + free(mio.data); + + return rc; +} + +int crespo_fmt_recv(struct ipc_client *client, struct ipc_message *message) +{ + struct ipc_fmt_header *header; + struct modem_io mio; + int rc; + + if (client == NULL || client->handlers == NULL || client->handlers->read == NULL || message == NULL) + return -1; + + memset(&mio, 0, sizeof(struct modem_io)); + mio.size = CRESPO_BUFFER_LENGTH; + mio.data = calloc(1, mio.size); + + rc = client->handlers->read(client->handlers->transport_data, &mio, sizeof(struct modem_io) + mio.size); + if (rc < 0 || mio.data == NULL || mio.size < sizeof(struct ipc_fmt_header)) { + ipc_client_log(client, "Reading FMT data failed"); + goto error; + } + + header = (struct ipc_fmt_header *) mio.data; + + ipc_fmt_message_setup(header, message); + + if (mio.size > sizeof(struct ipc_fmt_header)) { + message->size = mio.size - sizeof(struct ipc_fmt_header); + message->data = calloc(1, message->size); + + memcpy(message->data, (void *) ((unsigned char *) mio.data + sizeof(struct ipc_fmt_header)), message->size); + } + + ipc_client_log_recv(client, message, __func__); + + rc = 0; + goto complete; + +error: + rc = -1; + +complete: + if (mio.data != NULL) + free(mio.data); + + return rc; +} + +int crespo_rfs_send(struct ipc_client *client, struct ipc_message *message) +{ + struct modem_io mio; + int rc; + + if (client == NULL || client->handlers == NULL || client->handlers->write == NULL || message == NULL) + return -1; + + memset(&mio, 0, sizeof(struct modem_io)); + mio.id = message->mseq; + mio.cmd = IPC_INDEX(message->command); + mio.size = message->size; + + if (message->data != NULL && message->size > 0) { + mio.data = calloc(1, mio.size); + + memcpy(mio.data, message->data, message->size); + } + + ipc_client_log_send(client, message, __func__); + + rc = client->handlers->write(client->handlers->transport_data, (void *) &mio, sizeof(struct modem_io)); + if (rc < 0) { + ipc_client_log(client, "Writing RFS data failed"); + goto error; + } + + rc = 0; + goto complete; + +error: + rc = -1; + +complete: + if (mio.data != NULL) + free(mio.data); + + return rc; +} + +int crespo_rfs_recv(struct ipc_client *client, struct ipc_message *message) +{ + struct modem_io mio; + int rc; + + if (client == NULL || client->handlers == NULL || client->handlers->read == NULL || message == NULL) + return -1; + + memset(&mio, 0, sizeof(struct modem_io)); + mio.size = CRESPO_BUFFER_LENGTH; + mio.data = calloc(1, mio.size); + + rc = client->handlers->read(client->handlers->transport_data, &mio, sizeof(struct modem_io) + mio.size); + if (rc < 0 || mio.data == NULL || mio.size <= 0) { + ipc_client_log(client, "Reading RFS data failed"); + goto error; + } + + memset(message, 0, sizeof(struct ipc_message)); + message->aseq = mio.id; + message->command = IPC_COMMAND(IPC_GROUP_RFS, mio.cmd); + + if (mio.size > 0) { + message->size = mio.size; + message->data = calloc(1, message->size); + + memcpy(message->data, mio.data, message->size); + } + + ipc_client_log_recv(client, message, __func__); + + rc = 0; + goto complete; + +error: + rc = -1; + +complete: + if (mio.data != NULL) + free(mio.data); + + return rc; +} + +int crespo_open(void *data, int type) +{ + struct crespo_transport_data *transport_data; + int fd; + + if (data == NULL) + return -1; + + transport_data = (struct crespo_transport_data *) data; + + switch (type) { + case IPC_CLIENT_TYPE_FMT: + fd = open(CRESPO_MODEM_FMT_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + break; + case IPC_CLIENT_TYPE_RFS: + fd = open(CRESPO_MODEM_RFS_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + break; + default: + return -1; + } + + if (fd < 0) + return -1; + + transport_data->fd = fd; + + return 0; +} + +int crespo_close(void *data) +{ + struct crespo_transport_data *transport_data; + int fd; + + if (data == NULL) + return -1; + + transport_data = (struct crespo_transport_data *) data; + + fd = transport_data->fd; + if (fd < 0) + return -1; + + transport_data->fd = -1; + close(fd); + + return 0; +} + +int crespo_read(void *data, void *buffer, size_t length) +{ + struct crespo_transport_data *transport_data; + int fd; + int rc; + + if (data == NULL || buffer == NULL || length == 0) + return -1; + + transport_data = (struct crespo_transport_data *) data; + + fd = transport_data->fd; + if (fd < 0) + return -1; + + rc = ioctl(fd, IOCTL_MODEM_RECV, buffer); + if (rc < 0) + return -1; + + return 0; +} + +int crespo_write(void *data, const void *buffer, size_t length) +{ + struct crespo_transport_data *transport_data; + int fd; + int rc; + + if (data == NULL || buffer == NULL || length == 0) + return -1; + + transport_data = (struct crespo_transport_data *) data; + + fd = transport_data->fd; + if (fd < 0) + return -1; + + rc = ioctl(fd, IOCTL_MODEM_SEND, buffer); + if (rc < 0) + return -1; + + return 0; +} + +int crespo_poll(void *data, struct timeval *timeout) +{ + struct crespo_transport_data *transport_data; + fd_set fds; + int fd; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct crespo_transport_data *) data; + + fd = transport_data->fd; + if (fd < 0) + return -1; + + FD_ZERO(&fds); + FD_SET(fd, &fds); + + rc = select(fd + 1, &fds, NULL, NULL, timeout); + return rc; +} + +int crespo_power_on(void *data) +{ + int fd; + int rc; + + fd = open(CRESPO_MODEM_CTL_DEVICE, O_RDWR); + if (fd < 0) + return -1; + + rc = ioctl(fd, IOCTL_MODEM_START); + + close(fd); + + if (rc < 0) + return -1; + + return 0; +} + +int crespo_power_off(void *data) +{ + int fd; + int rc; + + fd = open(CRESPO_MODEM_CTL_DEVICE, O_RDWR); + if (fd < 0) + return -1; + + rc = ioctl(fd, IOCTL_MODEM_OFF); + + close(fd); + + if (rc < 0) + return -1; + + return 0; +} + +int crespo_data_create(void **transport_data, void **power_data, + void **gprs_data) +{ + if (transport_data == NULL) + return -1; + + *transport_data = calloc(1, sizeof(struct crespo_transport_data)); + + return 0; +} + +int crespo_data_destroy(void *transport_data, void *power_data, void *gprs_data) +{ + if (transport_data == NULL) + return -1; + + free(transport_data); + + return 0; +} + +char *crespo_gprs_get_iface_single(int cid) +{ + char *iface = NULL; + + asprintf(&iface, "%s%d", CRESPO_GPRS_IFACE_PREFIX, 0); + + return iface; +} + +int crespo_gprs_get_capabilities_single(struct ipc_client_gprs_capabilities *capabilities) +{ + if (capabilities == NULL) + return -1; + + capabilities->cid_count = 1; + + return 0; +} + +char *crespo_gprs_get_iface(int cid) +{ + char *iface = NULL; + + if (cid > CRESPO_GPRS_IFACE_COUNT) + return NULL; + + asprintf(&iface, "%s%d", CRESPO_GPRS_IFACE_PREFIX, cid - 1); + + return iface; +} + +int crespo_gprs_get_capabilities(struct ipc_client_gprs_capabilities *capabilities) +{ + if (capabilities == NULL) + return -1; + + capabilities->cid_count = CRESPO_GPRS_IFACE_COUNT; + + return 0; +} + +struct ipc_client_ops crespo_fmt_ops = { + .boot = crespo_boot, + .send = crespo_fmt_send, + .recv = crespo_fmt_recv, +}; + +struct ipc_client_ops crespo_rfs_ops = { + .boot = NULL, + .send = crespo_rfs_send, + .recv = crespo_rfs_recv, +}; + +struct ipc_client_handlers crespo_handlers = { + .open = crespo_open, + .close = crespo_close, + .read = crespo_read, + .write = crespo_write, + .poll = crespo_poll, + .transport_data = NULL, + .power_on = crespo_power_on, + .power_off = crespo_power_off, + .power_data = NULL, + .gprs_activate = NULL, + .gprs_deactivate = NULL, + .gprs_data = NULL, + .data_create = crespo_data_create, + .data_destroy = crespo_data_destroy, +}; + +struct ipc_client_gprs_specs crespo_gprs_specs_single = { + .gprs_get_iface = crespo_gprs_get_iface_single, + .gprs_get_capabilities = crespo_gprs_get_capabilities_single, +}; + +struct ipc_client_gprs_specs crespo_gprs_specs = { + .gprs_get_iface = crespo_gprs_get_iface, + .gprs_get_capabilities = crespo_gprs_get_capabilities, +}; + +struct ipc_client_nv_data_specs crespo_nv_data_specs = { + .nv_data_path = XMM6160_NV_DATA_PATH, + .nv_data_md5_path = XMM6160_NV_DATA_MD5_PATH, + .nv_data_backup_path = XMM6160_NV_DATA_BACKUP_PATH, + .nv_data_backup_md5_path = XMM6160_NV_DATA_BACKUP_MD5_PATH, + .nv_data_secret = XMM6160_NV_DATA_SECRET, + .nv_data_size = XMM6160_NV_DATA_SIZE, + .nv_data_chunk_size = XMM6160_NV_DATA_CHUNK_SIZE, +}; + +// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/crespo/crespo.h b/samsung-ipc/devices/crespo/crespo.h new file mode 100644 index 0000000..97dff96 --- /dev/null +++ b/samsung-ipc/devices/crespo/crespo.h @@ -0,0 +1,50 @@ +/* + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2011-2014 Paul Kocialkowski + * + * libsamsung-ipc 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 2 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc 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 libsamsung-ipc. If not, see . + */ + +#ifndef __CRESPO_H__ +#define __CRESPO_H__ + +#define CRESPO_MODEM_IMAGE_SIZE 0xD80000 +#define CRESPO_PSI_SIZE 0x5000 +#define CRESPO_MODEM_CTL_NV_DATA_OFFSET 0xD80000 +#define CRESPO_BUFFER_LENGTH 0x50000 + +#define CRESPO_MODEM_IMAGE_DEVICE "/dev/mtd/mtd5ro" +#define CRESPO_MODEM_SERIAL_DEVICE "/dev/s3c2410_serial3" +#define CRESPO_MODEM_CTL_DEVICE "/dev/modem_ctl" +#define CRESPO_MODEM_FMT_DEVICE "/dev/modem_fmt" +#define CRESPO_MODEM_RFS_DEVICE "/dev/modem_rfs" + +#define CRESPO_GPRS_IFACE_PREFIX "rmnet" +#define CRESPO_GPRS_IFACE_COUNT 3 + +struct crespo_transport_data { + int fd; +}; + +extern struct ipc_client_ops crespo_fmt_ops; +extern struct ipc_client_ops crespo_rfs_ops; +extern struct ipc_client_handlers crespo_handlers; +extern struct ipc_client_gprs_specs crespo_gprs_specs_single; +extern struct ipc_client_gprs_specs crespo_gprs_specs; +extern struct ipc_client_nv_data_specs crespo_nv_data_specs; + +#endif + +// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/crespo/crespo_ipc.c b/samsung-ipc/devices/crespo/crespo_ipc.c deleted file mode 100644 index 94dc695..0000000 --- a/samsung-ipc/devices/crespo/crespo_ipc.c +++ /dev/null @@ -1,569 +0,0 @@ -/* - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2011 Joerie de Gram - * Copyright (C) 2011 Simon Busch - * Copyright (C) 2011-2013 Paul Kocialkowski - * - * libsamsung-ipc 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 2 of the License, or - * (at your option) any later version. - * - * libsamsung-ipc 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 libsamsung-ipc. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "crespo_modem_ctl.h" - -#include "xmm6160.h" -#include "crespo_ipc.h" - -int crespo_ipc_bootstrap(struct ipc_client *client) -{ - void *modem_image_data = NULL; - - int modem_ctl_fd = -1; - int serial_fd = -1; - - unsigned char *p; - int rc; - - if (client == NULL) - return -1; - - ipc_client_log(client, "Starting crespo modem bootstrap"); - - modem_image_data = file_data_read(CRESPO_MODEM_IMAGE_DEVICE, CRESPO_MODEM_IMAGE_SIZE, 0x1000, 0); - if (modem_image_data == NULL) { - ipc_client_log(client, "Reading modem image data failed"); - goto error; - } - ipc_client_log(client, "Read modem image data"); - - modem_ctl_fd = open(CRESPO_MODEM_CTL_DEVICE, O_RDWR | O_NDELAY); - if (modem_ctl_fd < 0) { - ipc_client_log(client, "Opening modem ctl failed"); - goto error; - } - ipc_client_log(client, "Opened modem ctl"); - - rc = ioctl(modem_ctl_fd, IOCTL_MODEM_RESET); - if (rc < 0) { - ipc_client_log(client, "Resetting modem failed"); - goto error; - } - ipc_client_log(client, "Reset modem"); - - serial_fd = open(CRESPO_MODEM_SERIAL_DEVICE, O_RDWR | O_NDELAY); - if (serial_fd < 0) { - ipc_client_log(client, "Opening serial failed"); - goto error; - } - ipc_client_log(client, "Opened serial"); - - usleep(100000); - - p = (unsigned char *) modem_image_data; - - rc = xmm6160_psi_send(client, serial_fd, (void *) p, CRESPO_PSI_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6160 PSI failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6160 PSI"); - - p += CRESPO_PSI_SIZE; - - lseek(modem_ctl_fd, 0, SEEK_SET); - - rc = xmm6160_firmware_send(client, modem_ctl_fd, NULL, (void *) p, CRESPO_MODEM_IMAGE_SIZE - CRESPO_PSI_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6160 firmware failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6160 firmware"); - - lseek(modem_ctl_fd, CRESPO_MODEM_CTL_NV_DATA_OFFSET, SEEK_SET); - - rc = xmm6160_nv_data_send(client, modem_ctl_fd, NULL); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6160 nv_data failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6160 nv_data"); - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (modem_image_data != NULL) - free(modem_image_data); - - if (serial_fd >= 0) - close(serial_fd); - - if (modem_ctl_fd >= 0) - close(modem_ctl_fd); - - return rc; -} - -int crespo_ipc_fmt_send(struct ipc_client *client, struct ipc_message_info *request) -{ - struct ipc_fmt_header header; - struct modem_io mio; - int rc; - - if (client == NULL || client->handlers == NULL || client->handlers->write == NULL || request == NULL) - return -1; - - ipc_fmt_header_fill(&header, request); - - memset(&mio, 0, sizeof(struct modem_io)); - mio.size = request->length + sizeof(struct ipc_fmt_header); - mio.data = malloc(mio.size); - - memcpy(mio.data, &header, sizeof(struct ipc_fmt_header)); - if (request->data != NULL && request->length > 0) - memcpy((void *) ((unsigned char *) mio.data + sizeof(struct ipc_fmt_header)), request->data, request->length); - - ipc_client_log_send(client, request, __func__); - - rc = client->handlers->write(client->handlers->transport_data, (void *) &mio, sizeof(struct modem_io)); - if (rc < 0) { - ipc_client_log(client, "Writing FMT data to the modem failed"); - goto error; - } - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (mio.data != NULL) - free(mio.data); - - return rc; -} - -int crespo_ipc_fmt_recv(struct ipc_client *client, struct ipc_message_info *response) -{ - struct ipc_fmt_header *header; - struct modem_io mio; - int rc; - - if (client == NULL || client->handlers == NULL || client->handlers->read == NULL || response == NULL) - return -1; - - memset(&mio, 0, sizeof(struct modem_io)); - mio.size = CRESPO_BUFFER_LENGTH; - mio.data = malloc(mio.size); - - rc = client->handlers->read(client->handlers->transport_data, &mio, sizeof(struct modem_io) + mio.size); - if (rc < 0 || mio.data == NULL || mio.size < sizeof(struct ipc_fmt_header)) { - ipc_client_log(client, "Reading FMT data from the modem failed"); - goto error; - } - - header = (struct ipc_fmt_header *) mio.data; - - ipc_fmt_message_fill(header, response); - - if (mio.size > sizeof(struct ipc_fmt_header)) { - response->length = mio.size - sizeof(struct ipc_fmt_header); - response->data = malloc(response->length); - - memcpy(response->data, (void *) ((unsigned char *) mio.data + sizeof(struct ipc_fmt_header)), response->length); - } - - ipc_client_log_recv(client, response, __func__); - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (mio.data != NULL) - free(mio.data); - - return rc; -} - -int crespo_ipc_rfs_send(struct ipc_client *client, struct ipc_message_info *request) -{ - struct modem_io mio; - int rc; - - if (client == NULL || client->handlers == NULL || client->handlers->write == NULL || request == NULL) - return -1; - - memset(&mio, 0, sizeof(struct modem_io)); - mio.id = request->mseq; - mio.cmd = request->index; - mio.size = request->length; - - if (request->data != NULL && request->length > 0) { - mio.data = malloc(mio.size); - - memcpy(mio.data, request->data, request->length); - } - - ipc_client_log_send(client, request, __func__); - - rc = client->handlers->write(client->handlers->transport_data, (void *) &mio, sizeof(struct modem_io)); - if (rc < 0) { - ipc_client_log(client, "Writing RFS data to the modem failed"); - goto error; - } - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (mio.data != NULL) - free(mio.data); - - return rc; -} - -int crespo_ipc_rfs_recv(struct ipc_client *client, struct ipc_message_info *response) -{ - struct modem_io mio; - int rc; - - if (client == NULL || client->handlers == NULL || client->handlers->read == NULL || response == NULL) - return -1; - - memset(&mio, 0, sizeof(struct modem_io)); - mio.size = CRESPO_BUFFER_LENGTH; - mio.data = malloc(mio.size); - - rc = client->handlers->read(client->handlers->transport_data, &mio, sizeof(struct modem_io) + mio.size); - if (rc < 0 || mio.data == NULL || mio.size <= 0) { - ipc_client_log(client, "Reading RFS data from the modem failed"); - goto error; - } - - memset(response, 0, sizeof(struct ipc_message_info)); - response->aseq = mio.id; - response->group = IPC_GROUP_RFS; - response->index = mio.cmd; - - if (mio.size > 0) { - response->length = mio.size; - response->data = malloc(response->length); - - memcpy(response->data, mio.data, response->length); - } - - ipc_client_log_recv(client, response, __func__); - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (mio.data != NULL) - free(mio.data); - - return rc; -} - -int crespo_ipc_open(void *data, int type) -{ - struct crespo_ipc_transport_data *transport_data; - int fd; - - if (data == NULL) - return -1; - - transport_data = (struct crespo_ipc_transport_data *) data; - - switch (type) { - case IPC_CLIENT_TYPE_FMT: - fd = open(CRESPO_MODEM_FMT_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); - break; - case IPC_CLIENT_TYPE_RFS: - fd = open(CRESPO_MODEM_RFS_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); - break; - default: - return -1; - } - - if (fd < 0) - return -1; - - transport_data->fd = fd; - - return 0; -} - -int crespo_ipc_close(void *data) -{ - struct crespo_ipc_transport_data *transport_data; - int fd; - - if (data == NULL) - return -1; - - transport_data = (struct crespo_ipc_transport_data *) data; - - fd = transport_data->fd; - if (fd < 0) - return -1; - - transport_data->fd = -1; - close(fd); - - return 0; -} - -int crespo_ipc_read(void *data, void *buffer, unsigned int length) -{ - struct crespo_ipc_transport_data *transport_data; - int fd; - int rc; - - if (data == NULL || buffer == NULL || length == 0) - return -1; - - transport_data = (struct crespo_ipc_transport_data *) data; - - fd = transport_data->fd; - if (fd < 0) - return -1; - - rc = ioctl(fd, IOCTL_MODEM_RECV, buffer); - if (rc < 0) - return -1; - - return 0; -} - -int crespo_ipc_write(void *data, void *buffer, unsigned int length) -{ - struct crespo_ipc_transport_data *transport_data; - int fd; - int rc; - - if (data == NULL || buffer == NULL || length == 0) - return -1; - - transport_data = (struct crespo_ipc_transport_data *) data; - - fd = transport_data->fd; - if (fd < 0) - return -1; - - rc = ioctl(fd, IOCTL_MODEM_SEND, buffer); - if (rc < 0) - return -1; - - return 0; -} - -int crespo_ipc_poll(void *data, struct timeval *timeout) -{ - struct crespo_ipc_transport_data *transport_data; - fd_set fds; - int fd; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct crespo_ipc_transport_data *) data; - - fd = transport_data->fd; - if (fd < 0) - return -1; - - FD_ZERO(&fds); - FD_SET(fd, &fds); - - rc = select(fd + 1, &fds, NULL, NULL, timeout); - return rc; -} - -int crespo_ipc_power_on(void *data) -{ - int fd; - int rc; - - fd = open(CRESPO_MODEM_CTL_DEVICE, O_RDWR); - if (fd < 0) - return -1; - - rc = ioctl(fd, IOCTL_MODEM_START); - - close(fd); - - if (rc < 0) - return -1; - - return 0; -} - -int crespo_ipc_power_off(void *data) -{ - int fd; - int rc; - - fd = open(CRESPO_MODEM_CTL_DEVICE, O_RDWR); - if (fd < 0) - return -1; - - rc = ioctl(fd, IOCTL_MODEM_OFF); - - close(fd); - - if (rc < 0) - return -1; - - return 0; -} - -int crespo_ipc_data_create(void **transport_data, void **power_data, void **gprs_data) -{ - if (transport_data == NULL) - return -1; - - *transport_data = (void *) malloc(sizeof(struct crespo_ipc_transport_data)); - memset(*transport_data, 0, sizeof(struct crespo_ipc_transport_data)); - - return 0; -} - -int crespo_ipc_data_destroy(void *transport_data, void *power_data, void *gprs_data) -{ - if (transport_data == NULL) - return -1; - - free(transport_data); - - return 0; -} - -char *crespo_ipc_gprs_get_iface_single(int cid) -{ - char *iface = NULL; - - asprintf(&iface, "%s%d", CRESPO_GPRS_IFACE_PREFIX, 0); - - return iface; -} - -int crespo_ipc_gprs_get_capabilities_single(struct ipc_client_gprs_capabilities *capabilities) -{ - if (capabilities == NULL) - return -1; - - capabilities->port_list = 0; - capabilities->cid_max = 1; - - return 0; -} - -char *crespo_ipc_gprs_get_iface(int cid) -{ - char *iface = NULL; - - if (cid > CRESPO_GPRS_IFACE_COUNT) - return NULL; - - asprintf(&iface, "%s%d", CRESPO_GPRS_IFACE_PREFIX, cid - 1); - - return iface; -} - -int crespo_ipc_gprs_get_capabilities(struct ipc_client_gprs_capabilities *capabilities) -{ - if (capabilities == NULL) - return -1; - - capabilities->port_list = 0; - capabilities->cid_max = CRESPO_GPRS_IFACE_COUNT; - - return 0; -} - -struct ipc_ops crespo_ipc_fmt_ops = { - .bootstrap = crespo_ipc_bootstrap, - .send = crespo_ipc_fmt_send, - .recv = crespo_ipc_fmt_recv, -}; - -struct ipc_ops crespo_ipc_rfs_ops = { - .bootstrap = NULL, - .send = crespo_ipc_rfs_send, - .recv = crespo_ipc_rfs_recv, -}; - -struct ipc_handlers crespo_ipc_handlers = { - .open = crespo_ipc_open, - .close = crespo_ipc_close, - .read = crespo_ipc_read, - .write = crespo_ipc_write, - .poll = crespo_ipc_poll, - .transport_data = NULL, - .power_on = crespo_ipc_power_on, - .power_off = crespo_ipc_power_off, - .power_data = NULL, - .gprs_activate = NULL, - .gprs_deactivate = NULL, - .gprs_data = NULL, - .data_create = crespo_ipc_data_create, - .data_destroy = crespo_ipc_data_destroy, -}; - -struct ipc_gprs_specs crespo_ipc_gprs_specs_single = { - .gprs_get_iface = crespo_ipc_gprs_get_iface_single, - .gprs_get_capabilities = crespo_ipc_gprs_get_capabilities_single, -}; - -struct ipc_gprs_specs crespo_ipc_gprs_specs = { - .gprs_get_iface = crespo_ipc_gprs_get_iface, - .gprs_get_capabilities = crespo_ipc_gprs_get_capabilities, -}; - -struct ipc_nv_data_specs crespo_ipc_nv_data_specs = { - .nv_data_path = XMM6160_NV_DATA_PATH, - .nv_data_md5_path = XMM6160_NV_DATA_MD5_PATH, - .nv_data_backup_path = XMM6160_NV_DATA_BACKUP_PATH, - .nv_data_backup_md5_path = XMM6160_NV_DATA_BACKUP_MD5_PATH, - .nv_data_secret = XMM6160_NV_DATA_SECRET, - .nv_data_size = XMM6160_NV_DATA_SIZE, - .nv_data_chunk_size = XMM6160_NV_DATA_CHUNK_SIZE, -}; - -// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/crespo/crespo_ipc.h b/samsung-ipc/devices/crespo/crespo_ipc.h deleted file mode 100644 index ff984d8..0000000 --- a/samsung-ipc/devices/crespo/crespo_ipc.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2011-2013 Paul Kocialkowski - * - * libsamsung-ipc 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 2 of the License, or - * (at your option) any later version. - * - * libsamsung-ipc 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 libsamsung-ipc. If not, see . - */ - -#ifndef __CRESPO_IPC_H__ -#define __CRESPO_IPC_H__ - -#define CRESPO_MODEM_IMAGE_SIZE 0xD80000 -#define CRESPO_PSI_SIZE 0x5000 -#define CRESPO_MODEM_CTL_NV_DATA_OFFSET 0xD80000 -#define CRESPO_BUFFER_LENGTH 0x50000 - -#define CRESPO_MODEM_IMAGE_DEVICE "/dev/mtd/mtd5ro" -#define CRESPO_MODEM_SERIAL_DEVICE "/dev/s3c2410_serial3" -#define CRESPO_MODEM_CTL_DEVICE "/dev/modem_ctl" -#define CRESPO_MODEM_FMT_DEVICE "/dev/modem_fmt" -#define CRESPO_MODEM_RFS_DEVICE "/dev/modem_rfs" - -#define CRESPO_GPRS_IFACE_PREFIX "rmnet" -#define CRESPO_GPRS_IFACE_COUNT 3 - -struct crespo_ipc_transport_data { - int fd; -}; - -extern struct ipc_ops crespo_ipc_fmt_ops; -extern struct ipc_ops crespo_ipc_rfs_ops; -extern struct ipc_handlers crespo_ipc_handlers; -extern struct ipc_gprs_specs crespo_ipc_gprs_specs_single; -extern struct ipc_gprs_specs crespo_ipc_gprs_specs; -extern struct ipc_nv_data_specs crespo_ipc_nv_data_specs; - -#endif - -// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/galaxys2/galaxys2.c b/samsung-ipc/devices/galaxys2/galaxys2.c new file mode 100644 index 0000000..7070376 --- /dev/null +++ b/samsung-ipc/devices/galaxys2/galaxys2.c @@ -0,0 +1,398 @@ +/* + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2013-2014 Paul Kocialkowski + * + * libsamsung-ipc 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 2 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc 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 libsamsung-ipc. If not, see . + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include "xmm6260.h" +#include "xmm6260_hsic.h" +#include "xmm6260_sec_modem.h" +#include "galaxys2.h" + +int galaxys2_boot(struct ipc_client *client) +{ + void *modem_image_data = NULL; + int modem_image_fd = -1; + int modem_boot_fd = -1; + int modem_link_fd = -1; + unsigned char *p; + int rc; + + if (client == NULL) + return -1; + + ipc_client_log(client, "Starting galaxys2 modem boot"); + + modem_image_fd = open(GALAXYS2_MODEM_IMAGE_DEVICE, O_RDONLY); + if (modem_image_fd < 0) { + ipc_client_log(client, "Opening modem image device failed"); + goto error; + } + ipc_client_log(client, "Opened modem image device"); + + modem_image_data = mmap(0, GALAXYS2_MODEM_IMAGE_SIZE, PROT_READ, MAP_SHARED, modem_image_fd, 0); + if (modem_image_data == NULL || modem_image_data == (void *) 0xffffffff) { + ipc_client_log(client, "Mapping modem image data to memory failed"); + goto error; + } + ipc_client_log(client, "Mapped modem image data to memory"); + + modem_boot_fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (modem_boot_fd < 0) { + ipc_client_log(client, "Opening modem boot device failed"); + goto error; + } + ipc_client_log(client, "Opened modem boot device"); + + modem_link_fd = open(XMM6260_SEC_MODEM_LINK_PM_DEVICE, O_RDWR); + if (modem_link_fd < 0) { + ipc_client_log(client, "Opening modem link device failed"); + goto error; + } + ipc_client_log(client, "Opened modem link device"); + + rc = xmm6260_sec_modem_power(modem_boot_fd, 0); + rc |= xmm6260_sec_modem_link_control_enable(modem_link_fd, 0); + rc |= xmm6260_sec_modem_hci_power(0); + rc |= xmm6260_sec_modem_link_control_active(modem_link_fd, 0); + + if (rc < 0) { + ipc_client_log(client, "Turning the modem off failed"); + goto error; + } + ipc_client_log(client, "Turned the modem off"); + + rc = xmm6260_sec_modem_power(modem_boot_fd, 1); + rc |= xmm6260_sec_modem_link_control_enable(modem_link_fd, 1); + rc |= xmm6260_sec_modem_hci_power(1); + rc |= xmm6260_sec_modem_link_control_active(modem_link_fd, 1); + + if (rc < 0) { + ipc_client_log(client, "Turning the modem on failed"); + goto error; + } + ipc_client_log(client, "Turned the modem on"); + + rc = xmm6260_sec_modem_link_connected_wait(modem_link_fd); + if (rc < 0) { + ipc_client_log(client, "Waiting for link connected failed"); + goto error; + } + ipc_client_log(client, "Waited for link connected"); + + p = (unsigned char *) modem_image_data + GALAXYS2_PSI_OFFSET; + + rc = xmm6260_hsic_psi_send(client, modem_boot_fd, (void *) p, GALAXYS2_PSI_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC PSI failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC PSI"); + + p = (unsigned char *) modem_image_data + GALAXYS2_EBL_OFFSET; + + rc = xmm6260_hsic_ebl_send(client, modem_boot_fd, (void *) p, GALAXYS2_EBL_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC EBL failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC EBL"); + + rc = xmm6260_hsic_port_config_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC port config failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC port config"); + + p = (unsigned char *) modem_image_data + GALAXYS2_SEC_START_OFFSET; + + rc = xmm6260_hsic_sec_start_send(client, modem_boot_fd, (void *) p, GALAXYS2_SEC_START_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC SEC start failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC SEC start"); + + p = (unsigned char *) modem_image_data + GALAXYS2_FIRMWARE_OFFSET; + + rc = xmm6260_hsic_firmware_send(client, modem_boot_fd, (void *) p, GALAXYS2_FIRMWARE_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC firmware failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC firmware"); + + rc = xmm6260_hsic_nv_data_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC nv_data failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC nv_data"); + + rc = xmm6260_hsic_sec_end_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC SEC end failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC SEC end"); + + rc = xmm6260_hsic_hw_reset_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC HW reset failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC HW reset"); + + usleep(300000); + + rc = xmm6260_sec_modem_link_get_hostwake_wait(modem_link_fd); + if (rc < 0) { + ipc_client_log(client, "Waiting for host wake failed"); + } + + rc = xmm6260_sec_modem_link_control_enable(modem_link_fd, 0); + rc |= xmm6260_sec_modem_hci_power(0); + rc |= xmm6260_sec_modem_link_control_active(modem_link_fd, 0); + + if (rc < 0) { + ipc_client_log(client, "Turning the modem off failed"); + goto error; + } + + rc = xmm6260_sec_modem_link_get_hostwake_wait(modem_link_fd); + if (rc < 0) { + ipc_client_log(client, "Waiting for host wake failed"); + goto error; + } + ipc_client_log(client, "Waited for host wake"); + + rc = xmm6260_sec_modem_link_control_enable(modem_link_fd, 1); + rc |= xmm6260_sec_modem_hci_power(1); + rc |= xmm6260_sec_modem_link_control_active(modem_link_fd, 1); + + if (rc < 0) { + ipc_client_log(client, "Turning the modem on failed"); + goto error; + } + + rc = xmm6260_sec_modem_link_connected_wait(modem_link_fd); + if (rc < 0) { + ipc_client_log(client, "Waiting for link connected failed"); + goto error; + } + ipc_client_log(client, "Waited for link connected"); + + usleep(300000); + + rc = 0; + goto complete; + +error: + rc = -1; + +complete: + if (modem_image_data != NULL) + munmap(modem_image_data, GALAXYS2_MODEM_IMAGE_SIZE); + + if (modem_image_fd >= 0) + close(modem_image_fd); + + if (modem_boot_fd >= 0) + close(modem_boot_fd); + + if (modem_link_fd >= 0) + close(modem_link_fd); + + return rc; +} + +int galaxys2_open(void *data, int type) +{ + struct galaxys2_transport_data *transport_data; + + if (data == NULL) + return -1; + + transport_data = (struct galaxys2_transport_data *) data; + + transport_data->fd = xmm6260_sec_modem_open(type); + if (transport_data->fd < 0) + return -1; + + return 0; +} + +int galaxys2_close(void *data) +{ + struct galaxys2_transport_data *transport_data; + + if (data == NULL) + return -1; + + transport_data = (struct galaxys2_transport_data *) data; + + xmm6260_sec_modem_close(transport_data->fd); + transport_data->fd = -1; + + return 0; +} + +int galaxys2_read(void *data, void *buffer, size_t length) +{ + struct galaxys2_transport_data *transport_data; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct galaxys2_transport_data *) data; + + rc = xmm6260_sec_modem_read(transport_data->fd, buffer, length); + + return rc; +} + +int galaxys2_write(void *data, const void *buffer, size_t length) +{ + struct galaxys2_transport_data *transport_data; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct galaxys2_transport_data *) data; + + rc = xmm6260_sec_modem_write(transport_data->fd, buffer, length); + + return rc; +} + +int galaxys2_poll(void *data, struct timeval *timeout) +{ + struct galaxys2_transport_data *transport_data; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct galaxys2_transport_data *) data; + + rc = xmm6260_sec_modem_poll(transport_data->fd, timeout); + + return rc; +} + +int galaxys2_power_on(void *data) +{ + return 0; +} + +int galaxys2_power_off(void *data) +{ + int fd; + int rc; + + fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (fd < 0) + return -1; + + rc = xmm6260_sec_modem_power(fd, 0); + + close(fd); + + if (rc < 0) + return -1; + + return 0; +} + +int galaxys2_data_create(void **transport_data, void **power_data, + void **gprs_data) +{ + if (transport_data == NULL) + return -1; + + *transport_data = calloc(1, sizeof(struct galaxys2_transport_data)); + + return 0; +} + +int galaxys2_data_destroy(void *transport_data, void *power_data, + void *gprs_data) +{ + if (transport_data == NULL) + return -1; + + free(transport_data); + + return 0; +} + +struct ipc_client_ops galaxys2_fmt_ops = { + .boot = galaxys2_boot, + .send = xmm6260_sec_modem_fmt_send, + .recv = xmm6260_sec_modem_fmt_recv, +}; + +struct ipc_client_ops galaxys2_rfs_ops = { + .boot = NULL, + .send = xmm6260_sec_modem_rfs_send, + .recv = xmm6260_sec_modem_rfs_recv, +}; + +struct ipc_client_handlers galaxys2_handlers = { + .read = galaxys2_read, + .write = galaxys2_write, + .open = galaxys2_open, + .close = galaxys2_close, + .poll = galaxys2_poll, + .transport_data = NULL, + .power_on = galaxys2_power_on, + .power_off = galaxys2_power_off, + .power_data = NULL, + .gprs_activate = NULL, + .gprs_deactivate = NULL, + .gprs_data = NULL, + .data_create = galaxys2_data_create, + .data_destroy = galaxys2_data_destroy, +}; + +struct ipc_client_gprs_specs galaxys2_gprs_specs = { + .gprs_get_iface = xmm6260_sec_modem_gprs_get_iface, + .gprs_get_capabilities = xmm6260_sec_modem_gprs_get_capabilities, +}; + +struct ipc_client_nv_data_specs galaxys2_nv_data_specs = { + .nv_data_path = XMM6260_NV_DATA_PATH, + .nv_data_md5_path = XMM6260_NV_DATA_MD5_PATH, + .nv_data_backup_path = XMM6260_NV_DATA_BACKUP_PATH, + .nv_data_backup_md5_path = XMM6260_NV_DATA_BACKUP_MD5_PATH, + .nv_data_secret = XMM6260_NV_DATA_SECRET, + .nv_data_size = XMM6260_NV_DATA_SIZE, + .nv_data_chunk_size = XMM6260_NV_DATA_CHUNK_SIZE, +}; + +// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/galaxys2/galaxys2.h b/samsung-ipc/devices/galaxys2/galaxys2.h new file mode 100644 index 0000000..5d315c6 --- /dev/null +++ b/samsung-ipc/devices/galaxys2/galaxys2.h @@ -0,0 +1,49 @@ +/* + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2013-2014 Paul Kocialkowski + * + * libsamsung-ipc 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 2 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc 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 libsamsung-ipc. If not, see . + */ + +#ifndef __GALAXYS2_H__ +#define __GALAXYS2_H__ + +#define GALAXYS2_MODEM_IMAGE_SIZE 0x1000000 +#define GALAXYS2_PSI_OFFSET 0 +#define GALAXYS2_PSI_SIZE 0xF000 +#define GALAXYS2_EBL_OFFSET 0xF000 +#define GALAXYS2_EBL_SIZE 0x19000 +#define GALAXYS2_SEC_START_OFFSET 0x9FF800 +#define GALAXYS2_SEC_START_SIZE 0x800 +#define GALAXYS2_FIRMWARE_OFFSET 0x28000 +#define GALAXYS2_FIRMWARE_SIZE 0x9D8000 +#define GALAXYS2_NV_DATA_OFFSET 0xA00000 +#define GALAXYS2_NV_DATA_SIZE 0x200000 + +#define GALAXYS2_MODEM_IMAGE_DEVICE "/dev/block/mmcblk0p8" + +struct galaxys2_transport_data { + int fd; +}; + +extern struct ipc_client_ops galaxys2_fmt_ops; +extern struct ipc_client_ops galaxys2_rfs_ops; +extern struct ipc_client_handlers galaxys2_handlers; +extern struct ipc_client_gprs_specs galaxys2_gprs_specs; +extern struct ipc_client_nv_data_specs galaxys2_nv_data_specs; + +#endif + +// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/galaxys2/galaxys2_ipc.c b/samsung-ipc/devices/galaxys2/galaxys2_ipc.c deleted file mode 100644 index 44a315b..0000000 --- a/samsung-ipc/devices/galaxys2/galaxys2_ipc.c +++ /dev/null @@ -1,427 +0,0 @@ -/* - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2013 Paul Kocialkowski - * - * libsamsung-ipc 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 2 of the License, or - * (at your option) any later version. - * - * libsamsung-ipc 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 libsamsung-ipc. If not, see . - */ - -#include -#include -#include -#include -#include - -#include -#include - -#include "xmm6260.h" -#include "xmm6260_hsic.h" -#include "xmm6260_sec_modem.h" -#include "galaxys2_ipc.h" - -int galaxys2_ipc_bootstrap(struct ipc_client *client) -{ - void *modem_image_data = NULL; - int modem_image_fd = -1; - int modem_boot_fd = -1; - int modem_link_fd = -1; - - unsigned char *p; - int rc; - - if (client == NULL) - return -1; - - ipc_client_log(client, "Starting galaxys2 modem bootstrap"); - - modem_image_fd = open(GALAXYS2_MODEM_IMAGE_DEVICE, O_RDONLY); - if (modem_image_fd < 0) { - ipc_client_log(client, "Opening modem image device failed"); - goto error; - } - ipc_client_log(client, "Opened modem image device"); - - modem_image_data = mmap(0, GALAXYS2_MODEM_IMAGE_SIZE, PROT_READ, MAP_SHARED, modem_image_fd, 0); - if (modem_image_data == NULL || modem_image_data == (void *) 0xffffffff) { - ipc_client_log(client, "Mapping modem image data to memory failed"); - goto error; - } - ipc_client_log(client, "Mapped modem image data to memory"); - - modem_boot_fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); - if (modem_boot_fd < 0) { - ipc_client_log(client, "Opening modem boot device failed"); - goto error; - } - ipc_client_log(client, "Opened modem boot device"); - - modem_link_fd = open(XMM6260_SEC_MODEM_LINK_PM_DEVICE, O_RDWR); - if (modem_link_fd < 0) { - ipc_client_log(client, "Opening modem link device failed"); - goto error; - } - ipc_client_log(client, "Opened modem link device"); - - rc = xmm6260_sec_modem_power(modem_boot_fd, 0); - rc |= xmm6260_sec_modem_link_control_enable(modem_link_fd, 0); - rc |= xmm6260_sec_modem_hci_power(0); - rc |= xmm6260_sec_modem_link_control_active(modem_link_fd, 0); - - if (rc < 0) { - ipc_client_log(client, "Turning the modem off failed"); - goto error; - } - ipc_client_log(client, "Turned the modem off"); - - rc = xmm6260_sec_modem_power(modem_boot_fd, 1); - rc |= xmm6260_sec_modem_link_control_enable(modem_link_fd, 1); - rc |= xmm6260_sec_modem_hci_power(1); - rc |= xmm6260_sec_modem_link_control_active(modem_link_fd, 1); - - if (rc < 0) { - ipc_client_log(client, "Turning the modem on failed"); - goto error; - } - ipc_client_log(client, "Turned the modem on"); - - rc = xmm6260_sec_modem_link_connected_wait(modem_link_fd); - if (rc < 0) { - ipc_client_log(client, "Waiting for link connected failed"); - goto error; - } - ipc_client_log(client, "Waited for link connected"); - - p = (unsigned char *) modem_image_data + GALAXYS2_PSI_OFFSET; - - rc = xmm6260_hsic_psi_send(client, modem_boot_fd, (void *) p, GALAXYS2_PSI_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC PSI failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC PSI"); - - p = (unsigned char *) modem_image_data + GALAXYS2_EBL_OFFSET; - - rc = xmm6260_hsic_ebl_send(client, modem_boot_fd, (void *) p, GALAXYS2_EBL_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC EBL failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC EBL"); - - rc = xmm6260_hsic_port_config_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC port config failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC port config"); - - p = (unsigned char *) modem_image_data + GALAXYS2_SEC_START_OFFSET; - - rc = xmm6260_hsic_sec_start_send(client, modem_boot_fd, (void *) p, GALAXYS2_SEC_START_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC SEC start failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC SEC start"); - - p = (unsigned char *) modem_image_data + GALAXYS2_FIRMWARE_OFFSET; - - rc = xmm6260_hsic_firmware_send(client, modem_boot_fd, (void *) p, GALAXYS2_FIRMWARE_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC firmware failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC firmware"); - - rc = xmm6260_hsic_nv_data_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC nv_data failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC nv_data"); - - rc = xmm6260_hsic_sec_end_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC SEC end failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC SEC end"); - - rc = xmm6260_hsic_hw_reset_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC HW reset failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC HW reset"); - - usleep(300000); - - rc = xmm6260_sec_modem_link_get_hostwake_wait(modem_link_fd); - if (rc < 0) { - ipc_client_log(client, "Waiting for host wake failed"); - } - - rc = xmm6260_sec_modem_link_control_enable(modem_link_fd, 0); - rc |= xmm6260_sec_modem_hci_power(0); - rc |= xmm6260_sec_modem_link_control_active(modem_link_fd, 0); - - if (rc < 0) { - ipc_client_log(client, "Turning the modem off failed"); - goto error; - } - - rc = xmm6260_sec_modem_link_get_hostwake_wait(modem_link_fd); - if (rc < 0) { - ipc_client_log(client, "Waiting for host wake failed"); - goto error; - } - ipc_client_log(client, "Waited for host wake"); - - rc = xmm6260_sec_modem_link_control_enable(modem_link_fd, 1); - rc |= xmm6260_sec_modem_hci_power(1); - rc |= xmm6260_sec_modem_link_control_active(modem_link_fd, 1); - - if (rc < 0) { - ipc_client_log(client, "Turning the modem on failed"); - goto error; - } - - rc = xmm6260_sec_modem_link_connected_wait(modem_link_fd); - if (rc < 0) { - ipc_client_log(client, "Waiting for link connected failed"); - goto error; - } - ipc_client_log(client, "Waited for link connected"); - - usleep(300000); - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (modem_image_data != NULL) - munmap(modem_image_data, GALAXYS2_MODEM_IMAGE_SIZE); - - if (modem_image_fd >= 0) - close(modem_image_fd); - - if (modem_boot_fd >= 0) - close(modem_boot_fd); - - if (modem_link_fd >= 0) - close(modem_link_fd); - - return rc; -} - - -int galaxys2_ipc_fmt_send(struct ipc_client *client, struct ipc_message_info *request) -{ - return xmm6260_sec_modem_ipc_fmt_send(client, request); -} - -int galaxys2_ipc_fmt_recv(struct ipc_client *client, struct ipc_message_info *response) -{ - return xmm6260_sec_modem_ipc_fmt_recv(client, response); -} - -int galaxys2_ipc_rfs_send(struct ipc_client *client, struct ipc_message_info *request) -{ - return xmm6260_sec_modem_ipc_rfs_send(client, request); -} - -int galaxys2_ipc_rfs_recv(struct ipc_client *client, struct ipc_message_info *response) -{ - return xmm6260_sec_modem_ipc_rfs_recv(client, response); -} - -int galaxys2_ipc_open(void *data, int type) -{ - struct galaxys2_ipc_transport_data *transport_data; - - if (data == NULL) - return -1; - - transport_data = (struct galaxys2_ipc_transport_data *) data; - - transport_data->fd = xmm6260_sec_modem_ipc_open(type); - if (transport_data->fd < 0) - return -1; - - return 0; -} - -int galaxys2_ipc_close(void *data) -{ - struct galaxys2_ipc_transport_data *transport_data; - - if (data == NULL) - return -1; - - transport_data = (struct galaxys2_ipc_transport_data *) data; - - xmm6260_sec_modem_ipc_close(transport_data->fd); - transport_data->fd = -1; - - return 0; -} - -int galaxys2_ipc_read(void *data, void *buffer, unsigned int length) -{ - struct galaxys2_ipc_transport_data *transport_data; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct galaxys2_ipc_transport_data *) data; - - rc = xmm6260_sec_modem_ipc_read(transport_data->fd, buffer, length); - return rc; -} - -int galaxys2_ipc_write(void *data, void *buffer, unsigned int length) -{ - struct galaxys2_ipc_transport_data *transport_data; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct galaxys2_ipc_transport_data *) data; - - rc = xmm6260_sec_modem_ipc_write(transport_data->fd, buffer, length); - return rc; -} - -int galaxys2_ipc_poll(void *data, struct timeval *timeout) -{ - struct galaxys2_ipc_transport_data *transport_data; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct galaxys2_ipc_transport_data *) data; - - rc = xmm6260_sec_modem_ipc_poll(transport_data->fd, timeout); - return rc; -} - -int galaxys2_ipc_power_on(void *data) -{ - return 0; -} - -int galaxys2_ipc_power_off(void *data) -{ - int fd; - int rc; - - fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); - if (fd < 0) - return -1; - - rc = xmm6260_sec_modem_power(fd, 0); - - close(fd); - - if (rc < 0) - return -1; - - return 0; -} - -int galaxys2_ipc_data_create(void **transport_data, void **power_data, void **gprs_data) -{ - if (transport_data == NULL) - return -1; - - *transport_data = (void *) malloc(sizeof(struct galaxys2_ipc_transport_data)); - memset(*transport_data, 0, sizeof(struct galaxys2_ipc_transport_data)); - - return 0; -} - -int galaxys2_ipc_data_destroy(void *transport_data, void *power_data, void *gprs_data) -{ - if (transport_data == NULL) - return -1; - - free(transport_data); - - return 0; -} - -char *galaxys2_ipc_gprs_get_iface(int cid) -{ - return xmm6260_sec_modem_ipc_gprs_get_iface(cid); -} - - -int galaxys2_ipc_gprs_get_capabilities(struct ipc_client_gprs_capabilities *capabilities) -{ - return xmm6260_sec_modem_ipc_gprs_get_capabilities(capabilities); -} - -struct ipc_ops galaxys2_ipc_fmt_ops = { - .bootstrap = galaxys2_ipc_bootstrap, - .send = galaxys2_ipc_fmt_send, - .recv = galaxys2_ipc_fmt_recv, -}; - -struct ipc_ops galaxys2_ipc_rfs_ops = { - .bootstrap = NULL, - .send = galaxys2_ipc_rfs_send, - .recv = galaxys2_ipc_rfs_recv, -}; - -struct ipc_handlers galaxys2_ipc_handlers = { - .read = galaxys2_ipc_read, - .write = galaxys2_ipc_write, - .open = galaxys2_ipc_open, - .close = galaxys2_ipc_close, - .poll = galaxys2_ipc_poll, - .transport_data = NULL, - .power_on = galaxys2_ipc_power_on, - .power_off = galaxys2_ipc_power_off, - .power_data = NULL, - .gprs_activate = NULL, - .gprs_deactivate = NULL, - .gprs_data = NULL, - .data_create = galaxys2_ipc_data_create, - .data_destroy = galaxys2_ipc_data_destroy, -}; - -struct ipc_gprs_specs galaxys2_ipc_gprs_specs = { - .gprs_get_iface = galaxys2_ipc_gprs_get_iface, - .gprs_get_capabilities = galaxys2_ipc_gprs_get_capabilities, -}; - -struct ipc_nv_data_specs galaxys2_ipc_nv_data_specs = { - .nv_data_path = XMM6260_NV_DATA_PATH, - .nv_data_md5_path = XMM6260_NV_DATA_MD5_PATH, - .nv_data_backup_path = XMM6260_NV_DATA_BACKUP_PATH, - .nv_data_backup_md5_path = XMM6260_NV_DATA_BACKUP_MD5_PATH, - .nv_data_secret = XMM6260_NV_DATA_SECRET, - .nv_data_size = XMM6260_NV_DATA_SIZE, - .nv_data_chunk_size = XMM6260_NV_DATA_CHUNK_SIZE, -}; - -// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/galaxys2/galaxys2_ipc.h b/samsung-ipc/devices/galaxys2/galaxys2_ipc.h deleted file mode 100644 index 7d68465..0000000 --- a/samsung-ipc/devices/galaxys2/galaxys2_ipc.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2013 Paul Kocialkowski - * - * libsamsung-ipc 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 2 of the License, or - * (at your option) any later version. - * - * libsamsung-ipc 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 libsamsung-ipc. If not, see . - */ - -#ifndef __GALAXYS2_IPC_H__ -#define __GALAXYS2_IPC_H__ - -#define GALAXYS2_MODEM_IMAGE_SIZE 0x1000000 -#define GALAXYS2_PSI_OFFSET 0 -#define GALAXYS2_PSI_SIZE 0xF000 -#define GALAXYS2_EBL_OFFSET 0xF000 -#define GALAXYS2_EBL_SIZE 0x19000 -#define GALAXYS2_SEC_START_OFFSET 0x9FF800 -#define GALAXYS2_SEC_START_SIZE 0x800 -#define GALAXYS2_FIRMWARE_OFFSET 0x28000 -#define GALAXYS2_FIRMWARE_SIZE 0x9D8000 -#define GALAXYS2_NV_DATA_OFFSET 0xA00000 -#define GALAXYS2_NV_DATA_SIZE 0x200000 - -#define GALAXYS2_MODEM_IMAGE_DEVICE "/dev/block/mmcblk0p8" - -struct galaxys2_ipc_transport_data { - int fd; -}; - -extern struct ipc_ops galaxys2_ipc_fmt_ops; -extern struct ipc_ops galaxys2_ipc_rfs_ops; -extern struct ipc_handlers galaxys2_ipc_handlers; -extern struct ipc_gprs_specs galaxys2_ipc_gprs_specs; -extern struct ipc_nv_data_specs galaxys2_ipc_nv_data_specs; - -#endif - -// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/i9300/i9300.c b/samsung-ipc/devices/i9300/i9300.c new file mode 100644 index 0000000..a3c22bd --- /dev/null +++ b/samsung-ipc/devices/i9300/i9300.c @@ -0,0 +1,391 @@ +/* + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2013-2014 Paul Kocialkowski + * + * libsamsung-ipc 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 2 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc 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 libsamsung-ipc. If not, see . + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include "xmm6260.h" +#include "xmm6260_hsic.h" +#include "xmm6260_sec_modem.h" +#include "i9300.h" + +int i9300_boot(struct ipc_client *client) +{ + void *modem_image_data = NULL; + int modem_image_fd = -1; + int modem_boot_fd = -1; + int modem_link_fd = -1; + unsigned char *p; + int rc; + + if (client == NULL) + return -1; + + ipc_client_log(client, "Starting i9300 modem boot"); + + modem_image_fd = open(I9300_MODEM_IMAGE_DEVICE, O_RDONLY); + if (modem_image_fd < 0) { + ipc_client_log(client, "Opening modem image device failed"); + goto error; + } + ipc_client_log(client, "Opened modem image device"); + + modem_image_data = mmap(0, I9300_MODEM_IMAGE_SIZE, PROT_READ, MAP_SHARED, modem_image_fd, 0); + if (modem_image_data == NULL || modem_image_data == (void *) 0xffffffff) { + ipc_client_log(client, "Mapping modem image data to memory failed"); + goto error; + } + ipc_client_log(client, "Mapped modem image data to memory"); + + modem_boot_fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (modem_boot_fd < 0) { + ipc_client_log(client, "Opening modem boot device failed"); + goto error; + } + ipc_client_log(client, "Opened modem boot device"); + + modem_link_fd = open(XMM6260_SEC_MODEM_LINK_PM_DEVICE, O_RDWR); + if (modem_link_fd < 0) { + ipc_client_log(client, "Opening modem link device failed"); + goto error; + } + ipc_client_log(client, "Opened modem link device"); + + rc = xmm6260_sec_modem_hci_power(0); + if (rc < 0) { + ipc_client_log(client, "Turning the modem off failed"); + goto error; + } + ipc_client_log(client, "Turned the modem off"); + + rc = xmm6260_sec_modem_power(modem_boot_fd, 1); + rc |= xmm6260_sec_modem_hci_power(1); + + if (rc < 0) { + ipc_client_log(client, "Turning the modem on failed"); + goto error; + } + ipc_client_log(client, "Turned the modem on"); + + rc = xmm6260_sec_modem_link_connected_wait(modem_link_fd); + if (rc < 0) { + ipc_client_log(client, "Waiting for link connected failed"); + goto error; + } + ipc_client_log(client, "Waited for link connected"); + + p = (unsigned char *) modem_image_data + I9300_PSI_OFFSET; + + rc = xmm6260_hsic_psi_send(client, modem_boot_fd, (void *) p, I9300_PSI_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC PSI failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC PSI"); + + p = (unsigned char *) modem_image_data + I9300_EBL_OFFSET; + + rc = xmm6260_hsic_ebl_send(client, modem_boot_fd, (void *) p, I9300_EBL_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC EBL failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC EBL"); + + rc = xmm6260_hsic_port_config_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC port config failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC port config"); + + p = (unsigned char *) modem_image_data + I9300_SEC_START_OFFSET; + + rc = xmm6260_hsic_sec_start_send(client, modem_boot_fd, (void *) p, I9300_SEC_START_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC SEC start failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC SEC start"); + + p = (unsigned char *) modem_image_data + I9300_FIRMWARE_OFFSET; + + rc = xmm6260_hsic_firmware_send(client, modem_boot_fd, (void *) p, I9300_FIRMWARE_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC firmware failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC firmware"); + + rc = xmm6260_hsic_nv_data_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC nv_data failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC nv_data"); + + rc = xmm6260_hsic_sec_end_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC SEC end failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC SEC end"); + + rc = xmm6260_hsic_hw_reset_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC HW reset failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC HW reset"); + + usleep(300000); + + rc = xmm6260_sec_modem_link_get_hostwake_wait(modem_link_fd); + if (rc < 0) { + ipc_client_log(client, "Waiting for host wake failed"); + } + + rc = xmm6260_sec_modem_link_control_enable(modem_link_fd, 0); + rc |= xmm6260_sec_modem_hci_power(0); + rc |= xmm6260_sec_modem_link_control_active(modem_link_fd, 0); + + if (rc < 0) { + ipc_client_log(client, "Turning the modem off failed"); + goto error; + } + + rc = xmm6260_sec_modem_link_get_hostwake_wait(modem_link_fd); + if (rc < 0) { + ipc_client_log(client, "Waiting for host wake failed"); + goto error; + } + ipc_client_log(client, "Waited for host wake"); + + rc = xmm6260_sec_modem_link_control_enable(modem_link_fd, 1); + rc |= xmm6260_sec_modem_hci_power(1); + rc |= xmm6260_sec_modem_link_control_active(modem_link_fd, 1); + + if (rc < 0) { + ipc_client_log(client, "Turning the modem on failed"); + goto error; + } + + rc = xmm6260_sec_modem_link_connected_wait(modem_link_fd); + if (rc < 0) { + ipc_client_log(client, "Waiting for link connected failed"); + goto error; + } + ipc_client_log(client, "Waited for link connected"); + + usleep(300000); + + rc = 0; + goto complete; + +error: + rc = -1; + +complete: + if (modem_image_data != NULL) + munmap(modem_image_data, I9300_MODEM_IMAGE_SIZE); + + if (modem_image_fd >= 0) + close(modem_image_fd); + + if (modem_boot_fd >= 0) + close(modem_boot_fd); + + if (modem_link_fd >= 0) + close(modem_link_fd); + + return rc; +} + +int i9300_open(void *data, int type) +{ + struct i9300_transport_data *transport_data; + + if (data == NULL) + return -1; + + transport_data = (struct i9300_transport_data *) data; + + transport_data->fd = xmm6260_sec_modem_open(type); + if (transport_data->fd < 0) + return -1; + + return 0; +} + +int i9300_close(void *data) +{ + struct i9300_transport_data *transport_data; + + if (data == NULL) + return -1; + + transport_data = (struct i9300_transport_data *) data; + + xmm6260_sec_modem_close(transport_data->fd); + transport_data->fd = -1; + + return 0; +} + +int i9300_read(void *data, void *buffer, size_t length) +{ + struct i9300_transport_data *transport_data; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct i9300_transport_data *) data; + + rc = xmm6260_sec_modem_read(transport_data->fd, buffer, length); + + return rc; +} + +int i9300_write(void *data, const void *buffer, size_t length) +{ + struct i9300_transport_data *transport_data; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct i9300_transport_data *) data; + + rc = xmm6260_sec_modem_write(transport_data->fd, buffer, length); + + return rc; +} + +int i9300_poll(void *data, struct timeval *timeout) +{ + struct i9300_transport_data *transport_data; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct i9300_transport_data *) data; + + rc = xmm6260_sec_modem_poll(transport_data->fd, timeout); + + return rc; +} + +int i9300_power_on(void *data) +{ + return 0; +} + +int i9300_power_off(void *data) +{ + int fd; + int rc; + + fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (fd < 0) + return -1; + + rc = xmm6260_sec_modem_power(fd, 0); + + close(fd); + + if (rc < 0) + return -1; + + return 0; +} + +int i9300_data_create(void **transport_data, void **power_data, + void **gprs_data) +{ + if (transport_data == NULL) + return -1; + + *transport_data = calloc(1, sizeof(struct i9300_transport_data)); + + return 0; +} + +int i9300_data_destroy(void *transport_data, void *power_data, void *gprs_data) +{ + if (transport_data == NULL) + return -1; + + free(transport_data); + + return 0; +} + +struct ipc_client_ops i9300_fmt_ops = { + .boot = i9300_boot, + .send = xmm6260_sec_modem_fmt_send, + .recv = xmm6260_sec_modem_fmt_recv, +}; + +struct ipc_client_ops i9300_rfs_ops = { + .boot = NULL, + .send = xmm6260_sec_modem_rfs_send, + .recv = xmm6260_sec_modem_rfs_recv, +}; + +struct ipc_client_handlers i9300_handlers = { + .read = i9300_read, + .write = i9300_write, + .open = i9300_open, + .close = i9300_close, + .poll = i9300_poll, + .transport_data = NULL, + .power_on = i9300_power_on, + .power_off = i9300_power_off, + .power_data = NULL, + .gprs_activate = NULL, + .gprs_deactivate = NULL, + .gprs_data = NULL, + .data_create = i9300_data_create, + .data_destroy = i9300_data_destroy, +}; + +struct ipc_client_gprs_specs i9300_gprs_specs = { + .gprs_get_iface = xmm6260_sec_modem_gprs_get_iface, + .gprs_get_capabilities = xmm6260_sec_modem_gprs_get_capabilities, +}; + +struct ipc_client_nv_data_specs i9300_nv_data_specs = { + .nv_data_path = XMM6260_NV_DATA_PATH, + .nv_data_md5_path = XMM6260_NV_DATA_MD5_PATH, + .nv_data_backup_path = XMM6260_NV_DATA_BACKUP_PATH, + .nv_data_backup_md5_path = XMM6260_NV_DATA_BACKUP_MD5_PATH, + .nv_data_secret = XMM6260_NV_DATA_SECRET, + .nv_data_size = XMM6260_NV_DATA_SIZE, + .nv_data_chunk_size = XMM6260_NV_DATA_CHUNK_SIZE, +}; + +// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/i9300/i9300.h b/samsung-ipc/devices/i9300/i9300.h new file mode 100644 index 0000000..9e63c4b --- /dev/null +++ b/samsung-ipc/devices/i9300/i9300.h @@ -0,0 +1,49 @@ +/* + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2013-2014 Paul Kocialkowski + * + * libsamsung-ipc 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 2 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc 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 libsamsung-ipc. If not, see . + */ + +#ifndef __I9300_H__ +#define __I9300_H__ + +#define I9300_MODEM_IMAGE_SIZE 0x1000000 +#define I9300_PSI_OFFSET 0x1000 +#define I9300_PSI_SIZE 0xE000 +#define I9300_EBL_OFFSET 0xF000 +#define I9300_EBL_SIZE 0x19000 +#define I9300_SEC_START_OFFSET 0x9FF800 +#define I9300_SEC_START_SIZE 0x800 +#define I9300_FIRMWARE_OFFSET 0x28000 +#define I9300_FIRMWARE_SIZE 0x9D7800 +#define I9300_NV_DATA_OFFSET 0xA00000 +#define I9300_NV_DATA_SIZE 0x200000 + +#define I9300_MODEM_IMAGE_DEVICE "/dev/block/mmcblk0p7" + +struct i9300_transport_data { + int fd; +}; + +extern struct ipc_client_ops i9300_fmt_ops; +extern struct ipc_client_ops i9300_rfs_ops; +extern struct ipc_client_handlers i9300_handlers; +extern struct ipc_client_gprs_specs i9300_gprs_specs; +extern struct ipc_client_nv_data_specs i9300_nv_data_specs; + +#endif + +// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/i9300/i9300_ipc.c b/samsung-ipc/devices/i9300/i9300_ipc.c deleted file mode 100644 index b7364df..0000000 --- a/samsung-ipc/devices/i9300/i9300_ipc.c +++ /dev/null @@ -1,421 +0,0 @@ -/* - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2013 Paul Kocialkowski - * - * libsamsung-ipc 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 2 of the License, or - * (at your option) any later version. - * - * libsamsung-ipc 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 libsamsung-ipc. If not, see . - */ - -#include -#include -#include -#include -#include - -#include -#include - -#include "xmm6260.h" -#include "xmm6260_hsic.h" -#include "xmm6260_sec_modem.h" -#include "i9300_ipc.h" - -int i9300_ipc_bootstrap(struct ipc_client *client) -{ - void *modem_image_data = NULL; - int modem_image_fd = -1; - int modem_boot_fd = -1; - int modem_link_fd = -1; - - unsigned char *p; - int rc; - - if (client == NULL) - return -1; - - ipc_client_log(client, "Starting i9300 modem bootstrap"); - - modem_image_fd = open(I9300_MODEM_IMAGE_DEVICE, O_RDONLY); - if (modem_image_fd < 0) { - ipc_client_log(client, "Opening modem image device failed"); - goto error; - } - ipc_client_log(client, "Opened modem image device"); - - modem_image_data = mmap(0, I9300_MODEM_IMAGE_SIZE, PROT_READ, MAP_SHARED, modem_image_fd, 0); - if (modem_image_data == NULL || modem_image_data == (void *) 0xffffffff) { - ipc_client_log(client, "Mapping modem image data to memory failed"); - goto error; - } - ipc_client_log(client, "Mapped modem image data to memory"); - - modem_boot_fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); - if (modem_boot_fd < 0) { - ipc_client_log(client, "Opening modem boot device failed"); - goto error; - } - ipc_client_log(client, "Opened modem boot device"); - - modem_link_fd = open(XMM6260_SEC_MODEM_LINK_PM_DEVICE, O_RDWR); - if (modem_link_fd < 0) { - ipc_client_log(client, "Opening modem link device failed"); - goto error; - } - ipc_client_log(client, "Opened modem link device"); - - rc = xmm6260_sec_modem_hci_power(0); - if (rc < 0) { - ipc_client_log(client, "Turning the modem off failed"); - goto error; - } - ipc_client_log(client, "Turned the modem off"); - - rc = xmm6260_sec_modem_power(modem_boot_fd, 1); - rc |= xmm6260_sec_modem_hci_power(1); - - if (rc < 0) { - ipc_client_log(client, "Turning the modem on failed"); - goto error; - } - ipc_client_log(client, "Turned the modem on"); - - rc = xmm6260_sec_modem_link_connected_wait(modem_link_fd); - if (rc < 0) { - ipc_client_log(client, "Waiting for link connected failed"); - goto error; - } - ipc_client_log(client, "Waited for link connected"); - - p = (unsigned char *) modem_image_data + I9300_PSI_OFFSET; - - rc = xmm6260_hsic_psi_send(client, modem_boot_fd, (void *) p, I9300_PSI_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC PSI failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC PSI"); - - p = (unsigned char *) modem_image_data + I9300_EBL_OFFSET; - - rc = xmm6260_hsic_ebl_send(client, modem_boot_fd, (void *) p, I9300_EBL_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC EBL failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC EBL"); - - rc = xmm6260_hsic_port_config_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC port config failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC port config"); - - p = (unsigned char *) modem_image_data + I9300_SEC_START_OFFSET; - - rc = xmm6260_hsic_sec_start_send(client, modem_boot_fd, (void *) p, I9300_SEC_START_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC SEC start failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC SEC start"); - - p = (unsigned char *) modem_image_data + I9300_FIRMWARE_OFFSET; - - rc = xmm6260_hsic_firmware_send(client, modem_boot_fd, (void *) p, I9300_FIRMWARE_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC firmware failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC firmware"); - - rc = xmm6260_hsic_nv_data_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC nv_data failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC nv_data"); - - rc = xmm6260_hsic_sec_end_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC SEC end failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC SEC end"); - - rc = xmm6260_hsic_hw_reset_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC HW reset failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC HW reset"); - - usleep(300000); - - rc = xmm6260_sec_modem_link_get_hostwake_wait(modem_link_fd); - if (rc < 0) { - ipc_client_log(client, "Waiting for host wake failed"); - } - - rc = xmm6260_sec_modem_link_control_enable(modem_link_fd, 0); - rc |= xmm6260_sec_modem_hci_power(0); - rc |= xmm6260_sec_modem_link_control_active(modem_link_fd, 0); - - if (rc < 0) { - ipc_client_log(client, "Turning the modem off failed"); - goto error; - } - - rc = xmm6260_sec_modem_link_get_hostwake_wait(modem_link_fd); - if (rc < 0) { - ipc_client_log(client, "Waiting for host wake failed"); - goto error; - } - ipc_client_log(client, "Waited for host wake"); - - rc = xmm6260_sec_modem_link_control_enable(modem_link_fd, 1); - rc |= xmm6260_sec_modem_hci_power(1); - rc |= xmm6260_sec_modem_link_control_active(modem_link_fd, 1); - - if (rc < 0) { - ipc_client_log(client, "Turning the modem on failed"); - goto error; - } - - rc = xmm6260_sec_modem_link_connected_wait(modem_link_fd); - if (rc < 0) { - ipc_client_log(client, "Waiting for link connected failed"); - goto error; - } - ipc_client_log(client, "Waited for link connected"); - - usleep(300000); - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (modem_image_data != NULL) - munmap(modem_image_data, I9300_MODEM_IMAGE_SIZE); - - if (modem_image_fd >= 0) - close(modem_image_fd); - - if (modem_boot_fd >= 0) - close(modem_boot_fd); - - if (modem_link_fd >= 0) - close(modem_link_fd); - - return rc; -} - - -int i9300_ipc_fmt_send(struct ipc_client *client, struct ipc_message_info *request) -{ - return xmm6260_sec_modem_ipc_fmt_send(client, request); -} - -int i9300_ipc_fmt_recv(struct ipc_client *client, struct ipc_message_info *response) -{ - return xmm6260_sec_modem_ipc_fmt_recv(client, response); -} - -int i9300_ipc_rfs_send(struct ipc_client *client, struct ipc_message_info *request) -{ - return xmm6260_sec_modem_ipc_rfs_send(client, request); -} - -int i9300_ipc_rfs_recv(struct ipc_client *client, struct ipc_message_info *response) -{ - return xmm6260_sec_modem_ipc_rfs_recv(client, response); -} - -int i9300_ipc_open(void *data, int type) -{ - struct i9300_ipc_transport_data *transport_data; - - if (data == NULL) - return -1; - - transport_data = (struct i9300_ipc_transport_data *) data; - - transport_data->fd = xmm6260_sec_modem_ipc_open(type); - if (transport_data->fd < 0) - return -1; - - return 0; -} - -int i9300_ipc_close(void *data) -{ - struct i9300_ipc_transport_data *transport_data; - - if (data == NULL) - return -1; - - transport_data = (struct i9300_ipc_transport_data *) data; - - xmm6260_sec_modem_ipc_close(transport_data->fd); - transport_data->fd = -1; - - return 0; -} - -int i9300_ipc_read(void *data, void *buffer, unsigned int length) -{ - struct i9300_ipc_transport_data *transport_data; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct i9300_ipc_transport_data *) data; - - rc = xmm6260_sec_modem_ipc_read(transport_data->fd, buffer, length); - return rc; -} - -int i9300_ipc_write(void *data, void *buffer, unsigned int length) -{ - struct i9300_ipc_transport_data *transport_data; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct i9300_ipc_transport_data *) data; - - rc = xmm6260_sec_modem_ipc_write(transport_data->fd, buffer, length); - return rc; -} - -int i9300_ipc_poll(void *data, struct timeval *timeout) -{ - struct i9300_ipc_transport_data *transport_data; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct i9300_ipc_transport_data *) data; - - rc = xmm6260_sec_modem_ipc_poll(transport_data->fd, timeout); - return rc; -} - -int i9300_ipc_power_on(void *data) -{ - return 0; -} - -int i9300_ipc_power_off(void *data) -{ - int fd; - int rc; - - fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); - if (fd < 0) - return -1; - - rc = xmm6260_sec_modem_power(fd, 0); - - close(fd); - - if (rc < 0) - return -1; - - return 0; -} - -int i9300_ipc_data_create(void **transport_data, void **power_data, void **gprs_data) -{ - if (transport_data == NULL) - return -1; - - *transport_data = (void *) malloc(sizeof(struct i9300_ipc_transport_data)); - memset(*transport_data, 0, sizeof(struct i9300_ipc_transport_data)); - - return 0; -} - -int i9300_ipc_data_destroy(void *transport_data, void *power_data, void *gprs_data) -{ - if (transport_data == NULL) - return -1; - - free(transport_data); - - return 0; -} - -char *i9300_ipc_gprs_get_iface(int cid) -{ - return xmm6260_sec_modem_ipc_gprs_get_iface(cid); -} - - -int i9300_ipc_gprs_get_capabilities(struct ipc_client_gprs_capabilities *capabilities) -{ - return xmm6260_sec_modem_ipc_gprs_get_capabilities(capabilities); -} - -struct ipc_ops i9300_ipc_fmt_ops = { - .bootstrap = i9300_ipc_bootstrap, - .send = i9300_ipc_fmt_send, - .recv = i9300_ipc_fmt_recv, -}; - -struct ipc_ops i9300_ipc_rfs_ops = { - .bootstrap = NULL, - .send = i9300_ipc_rfs_send, - .recv = i9300_ipc_rfs_recv, -}; - -struct ipc_handlers i9300_ipc_handlers = { - .read = i9300_ipc_read, - .write = i9300_ipc_write, - .open = i9300_ipc_open, - .close = i9300_ipc_close, - .poll = i9300_ipc_poll, - .transport_data = NULL, - .power_on = i9300_ipc_power_on, - .power_off = i9300_ipc_power_off, - .power_data = NULL, - .gprs_activate = NULL, - .gprs_deactivate = NULL, - .gprs_data = NULL, - .data_create = i9300_ipc_data_create, - .data_destroy = i9300_ipc_data_destroy, -}; - -struct ipc_gprs_specs i9300_ipc_gprs_specs = { - .gprs_get_iface = i9300_ipc_gprs_get_iface, - .gprs_get_capabilities = i9300_ipc_gprs_get_capabilities, -}; - -struct ipc_nv_data_specs i9300_ipc_nv_data_specs = { - .nv_data_path = XMM6260_NV_DATA_PATH, - .nv_data_md5_path = XMM6260_NV_DATA_MD5_PATH, - .nv_data_backup_path = XMM6260_NV_DATA_BACKUP_PATH, - .nv_data_backup_md5_path = XMM6260_NV_DATA_BACKUP_MD5_PATH, - .nv_data_secret = XMM6260_NV_DATA_SECRET, - .nv_data_size = XMM6260_NV_DATA_SIZE, - .nv_data_chunk_size = XMM6260_NV_DATA_CHUNK_SIZE, -}; - -// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/i9300/i9300_ipc.h b/samsung-ipc/devices/i9300/i9300_ipc.h deleted file mode 100644 index 901c28d..0000000 --- a/samsung-ipc/devices/i9300/i9300_ipc.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2013 Paul Kocialkowski - * - * libsamsung-ipc 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 2 of the License, or - * (at your option) any later version. - * - * libsamsung-ipc 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 libsamsung-ipc. If not, see . - */ - -#ifndef __I9300_IPC_H__ -#define __I9300_IPC_H__ - -#define I9300_MODEM_IMAGE_SIZE 0x1000000 -#define I9300_PSI_OFFSET 0x1000 -#define I9300_PSI_SIZE 0xE000 -#define I9300_EBL_OFFSET 0xF000 -#define I9300_EBL_SIZE 0x19000 -#define I9300_SEC_START_OFFSET 0x9FF800 -#define I9300_SEC_START_SIZE 0x800 -#define I9300_FIRMWARE_OFFSET 0x28000 -#define I9300_FIRMWARE_SIZE 0x9D7800 -#define I9300_NV_DATA_OFFSET 0xA00000 -#define I9300_NV_DATA_SIZE 0x200000 - -#define I9300_MODEM_IMAGE_DEVICE "/dev/block/mmcblk0p7" - -struct i9300_ipc_transport_data { - int fd; -}; - -extern struct ipc_ops i9300_ipc_fmt_ops; -extern struct ipc_ops i9300_ipc_rfs_ops; -extern struct ipc_handlers i9300_ipc_handlers; -extern struct ipc_gprs_specs i9300_ipc_gprs_specs; -extern struct ipc_nv_data_specs i9300_ipc_nv_data_specs; - -#endif - -// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/maguro/maguro.c b/samsung-ipc/devices/maguro/maguro.c new file mode 100644 index 0000000..f157883 --- /dev/null +++ b/samsung-ipc/devices/maguro/maguro.c @@ -0,0 +1,374 @@ +/* + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2012 Alexander Tarasikov + * Copyright (C) 2013-2014 Paul Kocialkowski + * + * libsamsung-ipc 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 2 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc 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 libsamsung-ipc. If not, see . + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +#include "xmm6260.h" +#include "xmm6260_mipi.h" +#include "xmm6260_sec_modem.h" +#include "maguro.h" + +int maguro_boot(struct ipc_client *client) +{ + void *modem_image_data = NULL; + int modem_image_fd = -1; + int modem_boot_fd = -1; + void *mps_data = NULL; + unsigned char *p; + int rc; + + if (client == NULL) + return -1; + + ipc_client_log(client, "Starting maguro modem boot"); + + modem_image_fd = open(MAGURO_MODEM_IMAGE_DEVICE, O_RDONLY); + if (modem_image_fd < 0) { + ipc_client_log(client, "Opening modem image device failed"); + goto error; + } + ipc_client_log(client, "Opened modem image device"); + + modem_image_data = mmap(0, MAGURO_MODEM_IMAGE_SIZE, PROT_READ, MAP_SHARED, modem_image_fd, 0); + if (modem_image_data == NULL || modem_image_data == (void *) 0xffffffff) { + ipc_client_log(client, "Mapping modem image data to memory failed"); + goto error; + } + ipc_client_log(client, "Mapped modem image data to memory"); + + modem_boot_fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (modem_boot_fd < 0) { + ipc_client_log(client, "Opening modem boot device failed"); + goto error; + } + ipc_client_log(client, "Opened modem boot device"); + + rc = xmm6260_sec_modem_power(modem_boot_fd, 0); + if (rc < 0) { + ipc_client_log(client, "Turning the modem off failed"); + goto error; + } + ipc_client_log(client, "Turned the modem off"); + + rc = xmm6260_sec_modem_power(modem_boot_fd, 1); + if (rc < 0) { + ipc_client_log(client, "Turning the modem on failed"); + goto error; + } + ipc_client_log(client, "Turned the modem on"); + + p = (unsigned char *) modem_image_data + MAGURO_PSI_OFFSET; + + rc = xmm6260_mipi_psi_send(client, modem_boot_fd, (void *) p, MAGURO_PSI_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI PSI failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI PSI"); + + close(modem_boot_fd); + + modem_boot_fd = open(XMM6260_SEC_MODEM_BOOT1_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (modem_boot_fd < 0) { + ipc_client_log(client, "Opening modem boot device failed"); + goto error; + } + ipc_client_log(client, "Opened modem boot device"); + + p = (unsigned char *) modem_image_data + MAGURO_EBL_OFFSET; + + rc = xmm6260_mipi_ebl_send(client, modem_boot_fd, (void *) p, MAGURO_EBL_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI EBL failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI EBL"); + + rc = xmm6260_mipi_port_config_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI port config failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI port config"); + + p = (unsigned char *) modem_image_data + MAGURO_SEC_START_OFFSET; + + rc = xmm6260_mipi_sec_start_send(client, modem_boot_fd, (void *) p, MAGURO_SEC_START_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI SEC start failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI SEC start"); + + p = (unsigned char *) modem_image_data + MAGURO_FIRMWARE_OFFSET; + + rc = xmm6260_mipi_firmware_send(client, modem_boot_fd, (void *) p, MAGURO_FIRMWARE_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI firmware failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI firmware"); + + rc = xmm6260_mipi_nv_data_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI nv_data failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI nv_data"); + + mps_data = file_data_read(MAGURO_MPS_DATA_DEVICE, MAGURO_MPS_DATA_SIZE, MAGURO_MPS_DATA_SIZE, 0); + if (mps_data == NULL) { + ipc_client_log(client, "Reading MPS data failed"); + goto error; + } + ipc_client_log(client, "Read MPS data"); + + rc = xmm6260_mipi_mps_data_send(client, modem_boot_fd, mps_data, MAGURO_MPS_DATA_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI MPS data failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI MPS data"); + + rc = xmm6260_mipi_sec_end_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI SEC end failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI SEC end"); + + rc = xmm6260_mipi_hw_reset_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI HW reset failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI HW reset"); + + rc = xmm6260_sec_modem_status_online_wait(modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Waiting for online status failed"); + goto error; + } + ipc_client_log(client, "Waited for online status"); + + rc = xmm6260_sec_modem_boot_power(modem_boot_fd, 0); + if (rc < 0) { + ipc_client_log(client, "Turning modem boot off failed"); + goto error; + } + ipc_client_log(client, "Turned modem boot off"); + + rc = 0; + goto complete; + +error: + rc = -1; + +complete: + if (mps_data != NULL) + free(mps_data); + + if (modem_image_data != NULL) + munmap(modem_image_data, MAGURO_MODEM_IMAGE_SIZE); + + if (modem_image_fd >= 0) + close(modem_image_fd); + + if (modem_boot_fd >= 0) + close(modem_boot_fd); + + return rc; +} + +int maguro_open(void *data, int type) +{ + struct maguro_transport_data *transport_data; + + if (data == NULL) + return -1; + + transport_data = (struct maguro_transport_data *) data; + + transport_data->fd = xmm6260_sec_modem_open(type); + if (transport_data->fd < 0) + return -1; + + return 0; +} + +int maguro_close(void *data) +{ + struct maguro_transport_data *transport_data; + + if (data == NULL) + return -1; + + transport_data = (struct maguro_transport_data *) data; + + xmm6260_sec_modem_close(transport_data->fd); + transport_data->fd = -1; + + return 0; +} + +int maguro_read(void *data, void *buffer, size_t length) +{ + struct maguro_transport_data *transport_data; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct maguro_transport_data *) data; + + rc = xmm6260_sec_modem_read(transport_data->fd, buffer, length); + + return rc; +} + +int maguro_write(void *data, const void *buffer, size_t length) +{ + struct maguro_transport_data *transport_data; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct maguro_transport_data *) data; + + rc = xmm6260_sec_modem_write(transport_data->fd, buffer, length); + + return rc; +} + +int maguro_poll(void *data, struct timeval *timeout) +{ + struct maguro_transport_data *transport_data; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct maguro_transport_data *) data; + + rc = xmm6260_sec_modem_poll(transport_data->fd, timeout); + + return rc; +} + +int maguro_power_on(void *data) +{ + return 0; +} + +int maguro_power_off(void *data) +{ + int fd; + int rc; + + fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (fd < 0) + return -1; + + rc = xmm6260_sec_modem_power(fd, 0); + + close(fd); + + if (rc < 0) + return -1; + + return 0; +} + +int maguro_data_create(void **transport_data, void **power_data, + void **gprs_data) +{ + if (transport_data == NULL) + return -1; + + *transport_data = calloc(1, sizeof(struct maguro_transport_data)); + + return 0; +} + +int maguro_data_destroy(void *transport_data, void *power_data, + void *gprs_data) +{ + if (transport_data == NULL) + return -1; + + free(transport_data); + + return 0; +} + +struct ipc_client_ops maguro_fmt_ops = { + .boot = maguro_boot, + .send = xmm6260_sec_modem_fmt_send, + .recv = xmm6260_sec_modem_fmt_recv, +}; + +struct ipc_client_ops maguro_rfs_ops = { + .boot = NULL, + .send = xmm6260_sec_modem_rfs_send, + .recv = xmm6260_sec_modem_rfs_recv, +}; + +struct ipc_client_handlers maguro_handlers = { + .read = maguro_read, + .write = maguro_write, + .open = maguro_open, + .close = maguro_close, + .poll = maguro_poll, + .transport_data = NULL, + .power_on = maguro_power_on, + .power_off = maguro_power_off, + .power_data = NULL, + .gprs_activate = NULL, + .gprs_deactivate = NULL, + .gprs_data = NULL, + .data_create = maguro_data_create, + .data_destroy = maguro_data_destroy, +}; + +struct ipc_client_gprs_specs maguro_gprs_specs = { + .gprs_get_iface = xmm6260_sec_modem_gprs_get_iface, + .gprs_get_capabilities = xmm6260_sec_modem_gprs_get_capabilities, +}; + +struct ipc_client_nv_data_specs maguro_nv_data_specs = { + .nv_data_path = MAGURO_NV_DATA_PATH, + .nv_data_md5_path = MAGURO_NV_DATA_MD5_PATH, + .nv_data_backup_path = MAGURO_NV_DATA_BACKUP_PATH, + .nv_data_backup_md5_path = MAGURO_NV_DATA_BACKUP_MD5_PATH, + .nv_data_secret = XMM6260_NV_DATA_SECRET, + .nv_data_size = XMM6260_NV_DATA_SIZE, + .nv_data_chunk_size = XMM6260_NV_DATA_CHUNK_SIZE, +}; + +// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/maguro/maguro.h b/samsung-ipc/devices/maguro/maguro.h new file mode 100644 index 0000000..cc15bd6 --- /dev/null +++ b/samsung-ipc/devices/maguro/maguro.h @@ -0,0 +1,56 @@ +/* + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2013-2014 Paul Kocialkowski + * + * libsamsung-ipc 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 2 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc 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 libsamsung-ipc. If not, see . + */ + +#ifndef __MAGURO_H__ +#define __MAGURO_H__ + +#define MAGURO_MODEM_IMAGE_SIZE 0x1000000 +#define MAGURO_PSI_OFFSET 0 +#define MAGURO_PSI_SIZE 0xF000 +#define MAGURO_EBL_OFFSET 0xF000 +#define MAGURO_EBL_SIZE 0x19000 +#define MAGURO_SEC_START_OFFSET 0x9FF800 +#define MAGURO_SEC_START_SIZE 0x800 +#define MAGURO_FIRMWARE_OFFSET 0x28000 +#define MAGURO_FIRMWARE_SIZE 0x9D8000 +#define MAGURO_NV_DATA_OFFSET 0xA00000 +#define MAGURO_NV_DATA_SIZE 0x200000 +#define MAGURO_MPS_DATA_SIZE 3 + +#define MAGURO_MODEM_IMAGE_DEVICE "/dev/block/platform/omap/omap_hsmmc.0/by-name/radio" +#define MAGURO_MPS_DATA_DEVICE "/factory/imei/mps_code.dat" + +#define MAGURO_NV_DATA_PATH "/factory/nv_data.bin" +#define MAGURO_NV_DATA_MD5_PATH "/factory/nv_data.bin.md5" +#define MAGURO_NV_DATA_BACKUP_PATH "/factory/.nv_data.bak" +#define MAGURO_NV_DATA_BACKUP_MD5_PATH "/factory/.nv_data.bak.md5" + +struct maguro_transport_data { + int fd; +}; + +extern struct ipc_client_ops maguro_fmt_ops; +extern struct ipc_client_ops maguro_rfs_ops; +extern struct ipc_client_handlers maguro_handlers; +extern struct ipc_client_gprs_specs maguro_gprs_specs; +extern struct ipc_client_nv_data_specs maguro_nv_data_specs; + +#endif + +// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/maguro/maguro_ipc.c b/samsung-ipc/devices/maguro/maguro_ipc.c deleted file mode 100644 index 632cd3b..0000000 --- a/samsung-ipc/devices/maguro/maguro_ipc.c +++ /dev/null @@ -1,403 +0,0 @@ -/* - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2012 Alexander Tarasikov - * Copyright (C) 2013 Paul Kocialkowski - * - * libsamsung-ipc 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 2 of the License, or - * (at your option) any later version. - * - * libsamsung-ipc 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 libsamsung-ipc. If not, see . - */ - -#include -#include -#include -#include -#include - -#include -#include -#include - -#include "xmm6260.h" -#include "xmm6260_mipi.h" -#include "xmm6260_sec_modem.h" -#include "maguro_ipc.h" - -int maguro_ipc_bootstrap(struct ipc_client *client) -{ - void *modem_image_data = NULL; - int modem_image_fd = -1; - int modem_boot_fd = -1; - void *mps_data = NULL; - - unsigned char *p; - int rc; - - if (client == NULL) - return -1; - - ipc_client_log(client, "Starting maguro modem bootstrap"); - - modem_image_fd = open(MAGURO_MODEM_IMAGE_DEVICE, O_RDONLY); - if (modem_image_fd < 0) { - ipc_client_log(client, "Opening modem image device failed"); - goto error; - } - ipc_client_log(client, "Opened modem image device"); - - modem_image_data = mmap(0, MAGURO_MODEM_IMAGE_SIZE, PROT_READ, MAP_SHARED, modem_image_fd, 0); - if (modem_image_data == NULL || modem_image_data == (void *) 0xffffffff) { - ipc_client_log(client, "Mapping modem image data to memory failed"); - goto error; - } - ipc_client_log(client, "Mapped modem image data to memory"); - - modem_boot_fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); - if (modem_boot_fd < 0) { - ipc_client_log(client, "Opening modem boot device failed"); - goto error; - } - ipc_client_log(client, "Opened modem boot device"); - - rc = xmm6260_sec_modem_power(modem_boot_fd, 0); - if (rc < 0) { - ipc_client_log(client, "Turning the modem off failed"); - goto error; - } - ipc_client_log(client, "Turned the modem off"); - - rc = xmm6260_sec_modem_power(modem_boot_fd, 1); - if (rc < 0) { - ipc_client_log(client, "Turning the modem on failed"); - goto error; - } - ipc_client_log(client, "Turned the modem on"); - - p = (unsigned char *) modem_image_data + MAGURO_PSI_OFFSET; - - rc = xmm6260_mipi_psi_send(client, modem_boot_fd, (void *) p, MAGURO_PSI_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI PSI failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI PSI"); - - close(modem_boot_fd); - - modem_boot_fd = open(XMM6260_SEC_MODEM_BOOT1_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); - if (modem_boot_fd < 0) { - ipc_client_log(client, "Opening modem boot device failed"); - goto error; - } - ipc_client_log(client, "Opened modem boot device"); - - p = (unsigned char *) modem_image_data + MAGURO_EBL_OFFSET; - - rc = xmm6260_mipi_ebl_send(client, modem_boot_fd, (void *) p, MAGURO_EBL_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI EBL failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI EBL"); - - rc = xmm6260_mipi_port_config_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI port config failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI port config"); - - p = (unsigned char *) modem_image_data + MAGURO_SEC_START_OFFSET; - - rc = xmm6260_mipi_sec_start_send(client, modem_boot_fd, (void *) p, MAGURO_SEC_START_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI SEC start failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI SEC start"); - - p = (unsigned char *) modem_image_data + MAGURO_FIRMWARE_OFFSET; - - rc = xmm6260_mipi_firmware_send(client, modem_boot_fd, (void *) p, MAGURO_FIRMWARE_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI firmware failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI firmware"); - - rc = xmm6260_mipi_nv_data_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI nv_data failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI nv_data"); - - mps_data = file_data_read(MAGURO_MPS_DATA_DEVICE, MAGURO_MPS_DATA_SIZE, MAGURO_MPS_DATA_SIZE, 0); - if (mps_data == NULL) { - ipc_client_log(client, "Reading MPS data failed"); - goto error; - } - ipc_client_log(client, "Read MPS data"); - - rc = xmm6260_mipi_mps_data_send(client, modem_boot_fd, mps_data, MAGURO_MPS_DATA_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI MPS data failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI MPS data"); - - rc = xmm6260_mipi_sec_end_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI SEC end failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI SEC end"); - - rc = xmm6260_mipi_hw_reset_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI HW reset failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI HW reset"); - - rc = xmm6260_sec_modem_status_online_wait(modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Waiting for online status failed"); - goto error; - } - ipc_client_log(client, "Waited for online status"); - - rc = xmm6260_sec_modem_boot_power(modem_boot_fd, 0); - if (rc < 0) { - ipc_client_log(client, "Turning modem boot off failed"); - goto error; - } - ipc_client_log(client, "Turned modem boot off"); - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (mps_data != NULL) - free(mps_data); - - if (modem_image_data != NULL) - munmap(modem_image_data, MAGURO_MODEM_IMAGE_SIZE); - - if (modem_image_fd >= 0) - close(modem_image_fd); - - if (modem_boot_fd >= 0) - close(modem_boot_fd); - - return rc; -} - - -int maguro_ipc_fmt_send(struct ipc_client *client, struct ipc_message_info *request) -{ - return xmm6260_sec_modem_ipc_fmt_send(client, request); -} - -int maguro_ipc_fmt_recv(struct ipc_client *client, struct ipc_message_info *response) -{ - return xmm6260_sec_modem_ipc_fmt_recv(client, response); -} - -int maguro_ipc_rfs_send(struct ipc_client *client, struct ipc_message_info *request) -{ - return xmm6260_sec_modem_ipc_rfs_send(client, request); -} - -int maguro_ipc_rfs_recv(struct ipc_client *client, struct ipc_message_info *response) -{ - return xmm6260_sec_modem_ipc_rfs_recv(client, response); -} - -int maguro_ipc_open(void *data, int type) -{ - struct maguro_ipc_transport_data *transport_data; - - if (data == NULL) - return -1; - - transport_data = (struct maguro_ipc_transport_data *) data; - - transport_data->fd = xmm6260_sec_modem_ipc_open(type); - if (transport_data->fd < 0) - return -1; - - return 0; -} - -int maguro_ipc_close(void *data) -{ - struct maguro_ipc_transport_data *transport_data; - - if (data == NULL) - return -1; - - transport_data = (struct maguro_ipc_transport_data *) data; - - xmm6260_sec_modem_ipc_close(transport_data->fd); - transport_data->fd = -1; - - return 0; -} - -int maguro_ipc_read(void *data, void *buffer, unsigned int length) -{ - struct maguro_ipc_transport_data *transport_data; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct maguro_ipc_transport_data *) data; - - rc = xmm6260_sec_modem_ipc_read(transport_data->fd, buffer, length); - return rc; -} - -int maguro_ipc_write(void *data, void *buffer, unsigned int length) -{ - struct maguro_ipc_transport_data *transport_data; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct maguro_ipc_transport_data *) data; - - rc = xmm6260_sec_modem_ipc_write(transport_data->fd, buffer, length); - return rc; -} - -int maguro_ipc_poll(void *data, struct timeval *timeout) -{ - struct maguro_ipc_transport_data *transport_data; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct maguro_ipc_transport_data *) data; - - rc = xmm6260_sec_modem_ipc_poll(transport_data->fd, timeout); - return rc; -} - -int maguro_ipc_power_on(void *data) -{ - return 0; -} - -int maguro_ipc_power_off(void *data) -{ - int fd; - int rc; - - fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); - if (fd < 0) - return -1; - - rc = xmm6260_sec_modem_power(fd, 0); - - close(fd); - - if (rc < 0) - return -1; - - return 0; -} - -int maguro_ipc_data_create(void **transport_data, void **power_data, void **gprs_data) -{ - if (transport_data == NULL) - return -1; - - *transport_data = (void *) malloc(sizeof(struct maguro_ipc_transport_data)); - memset(*transport_data, 0, sizeof(struct maguro_ipc_transport_data)); - - return 0; -} - -int maguro_ipc_data_destroy(void *transport_data, void *power_data, void *gprs_data) -{ - if (transport_data == NULL) - return -1; - - free(transport_data); - - return 0; -} - -char *maguro_ipc_gprs_get_iface(int cid) -{ - return xmm6260_sec_modem_ipc_gprs_get_iface(cid); -} - - -int maguro_ipc_gprs_get_capabilities(struct ipc_client_gprs_capabilities *capabilities) -{ - return xmm6260_sec_modem_ipc_gprs_get_capabilities(capabilities); -} - -struct ipc_ops maguro_ipc_fmt_ops = { - .bootstrap = maguro_ipc_bootstrap, - .send = maguro_ipc_fmt_send, - .recv = maguro_ipc_fmt_recv, -}; - -struct ipc_ops maguro_ipc_rfs_ops = { - .bootstrap = NULL, - .send = maguro_ipc_rfs_send, - .recv = maguro_ipc_rfs_recv, -}; - -struct ipc_handlers maguro_ipc_handlers = { - .read = maguro_ipc_read, - .write = maguro_ipc_write, - .open = maguro_ipc_open, - .close = maguro_ipc_close, - .poll = maguro_ipc_poll, - .transport_data = NULL, - .power_on = maguro_ipc_power_on, - .power_off = maguro_ipc_power_off, - .power_data = NULL, - .gprs_activate = NULL, - .gprs_deactivate = NULL, - .gprs_data = NULL, - .data_create = maguro_ipc_data_create, - .data_destroy = maguro_ipc_data_destroy, -}; - -struct ipc_gprs_specs maguro_ipc_gprs_specs = { - .gprs_get_iface = maguro_ipc_gprs_get_iface, - .gprs_get_capabilities = maguro_ipc_gprs_get_capabilities, -}; - -struct ipc_nv_data_specs maguro_ipc_nv_data_specs = { - .nv_data_path = MAGURO_NV_DATA_PATH, - .nv_data_md5_path = MAGURO_NV_DATA_MD5_PATH, - .nv_data_backup_path = MAGURO_NV_DATA_BACKUP_PATH, - .nv_data_backup_md5_path = MAGURO_NV_DATA_BACKUP_MD5_PATH, - .nv_data_secret = XMM6260_NV_DATA_SECRET, - .nv_data_size = XMM6260_NV_DATA_SIZE, - .nv_data_chunk_size = XMM6260_NV_DATA_CHUNK_SIZE, -}; - -// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/maguro/maguro_ipc.h b/samsung-ipc/devices/maguro/maguro_ipc.h deleted file mode 100644 index c58178c..0000000 --- a/samsung-ipc/devices/maguro/maguro_ipc.h +++ /dev/null @@ -1,56 +0,0 @@ -/* - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2013 Paul Kocialkowski - * - * libsamsung-ipc 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 2 of the License, or - * (at your option) any later version. - * - * libsamsung-ipc 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 libsamsung-ipc. If not, see . - */ - -#ifndef __MAGURO_IPC_H__ -#define __MAGURO_IPC_H__ - -#define MAGURO_MODEM_IMAGE_SIZE 0x1000000 -#define MAGURO_PSI_OFFSET 0 -#define MAGURO_PSI_SIZE 0xF000 -#define MAGURO_EBL_OFFSET 0xF000 -#define MAGURO_EBL_SIZE 0x19000 -#define MAGURO_SEC_START_OFFSET 0x9FF800 -#define MAGURO_SEC_START_SIZE 0x800 -#define MAGURO_FIRMWARE_OFFSET 0x28000 -#define MAGURO_FIRMWARE_SIZE 0x9D8000 -#define MAGURO_NV_DATA_OFFSET 0xA00000 -#define MAGURO_NV_DATA_SIZE 0x200000 -#define MAGURO_MPS_DATA_SIZE 3 - -#define MAGURO_MODEM_IMAGE_DEVICE "/dev/block/platform/omap/omap_hsmmc.0/by-name/radio" -#define MAGURO_MPS_DATA_DEVICE "/factory/imei/mps_code.dat" - -#define MAGURO_NV_DATA_PATH "/factory/nv_data.bin" -#define MAGURO_NV_DATA_MD5_PATH "/factory/nv_data.bin.md5" -#define MAGURO_NV_DATA_BACKUP_PATH "/factory/.nv_data.bak" -#define MAGURO_NV_DATA_BACKUP_MD5_PATH "/factory/.nv_data.bak.md5" - -struct maguro_ipc_transport_data { - int fd; -}; - -extern struct ipc_ops maguro_ipc_fmt_ops; -extern struct ipc_ops maguro_ipc_rfs_ops; -extern struct ipc_handlers maguro_ipc_handlers; -extern struct ipc_gprs_specs maguro_ipc_gprs_specs; -extern struct ipc_nv_data_specs maguro_ipc_nv_data_specs; - -#endif - -// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/n7100/n7100.c b/samsung-ipc/devices/n7100/n7100.c new file mode 100644 index 0000000..c72dcdd --- /dev/null +++ b/samsung-ipc/devices/n7100/n7100.c @@ -0,0 +1,392 @@ +/* + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2013-2014 Paul Kocialkowski + * + * libsamsung-ipc 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 2 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc 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 libsamsung-ipc. If not, see . + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include "xmm6260.h" +#include "xmm6260_hsic.h" +#include "xmm6260_sec_modem.h" +#include "n7100.h" + +int n7100_boot(struct ipc_client *client) +{ + void *modem_image_data = NULL; + int modem_image_fd = -1; + int modem_boot_fd = -1; + int modem_link_fd = -1; + unsigned char *p; + int rc; + + if (client == NULL) + return -1; + + ipc_client_log(client, "Starting n7100 modem boot"); + + modem_image_fd = open(N7100_MODEM_IMAGE_DEVICE, O_RDONLY); + if (modem_image_fd < 0) { + ipc_client_log(client, "Opening modem image device failed"); + goto error; + } + ipc_client_log(client, "Opened modem image device"); + + modem_image_data = mmap(0, N7100_MODEM_IMAGE_SIZE, PROT_READ, MAP_SHARED, modem_image_fd, 0); + if (modem_image_data == NULL || modem_image_data == (void *) 0xffffffff) { + ipc_client_log(client, "Mapping modem image data to memory failed"); + goto error; + } + ipc_client_log(client, "Mapped modem image data to memory"); + + modem_boot_fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (modem_boot_fd < 0) { + ipc_client_log(client, "Opening modem boot device failed"); + goto error; + } + ipc_client_log(client, "Opened modem boot device"); + + modem_link_fd = open(XMM6260_SEC_MODEM_LINK_PM_DEVICE, O_RDWR); + if (modem_link_fd < 0) { + ipc_client_log(client, "Opening modem link device failed"); + goto error; + } + ipc_client_log(client, "Opened modem link device"); + + rc = xmm6260_sec_modem_hci_power(0); + if (rc < 0) { + ipc_client_log(client, "Turning the modem off failed"); + goto error; + } + ipc_client_log(client, "Turned the modem off"); + + rc = xmm6260_sec_modem_power(modem_boot_fd, 1); + rc |= xmm6260_sec_modem_hci_power(1); + + if (rc < 0) { + ipc_client_log(client, "Turning the modem on failed"); + goto error; + } + ipc_client_log(client, "Turned the modem on"); + + rc = xmm6260_sec_modem_link_connected_wait(modem_link_fd); + if (rc < 0) { + ipc_client_log(client, "Waiting for link connected failed"); + goto error; + } + ipc_client_log(client, "Waited for link connected"); + + p = (unsigned char *) modem_image_data + N7100_PSI_OFFSET; + + rc = xmm6260_hsic_psi_send(client, modem_boot_fd, (void *) p, N7100_PSI_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC PSI failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC PSI"); + + p = (unsigned char *) modem_image_data + N7100_EBL_OFFSET; + + rc = xmm6260_hsic_ebl_send(client, modem_boot_fd, (void *) p, N7100_EBL_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC EBL failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC EBL"); + + rc = xmm6260_hsic_port_config_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC port config failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC port config"); + + p = (unsigned char *) modem_image_data + N7100_SEC_START_OFFSET; + + rc = xmm6260_hsic_sec_start_send(client, modem_boot_fd, (void *) p, N7100_SEC_START_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC SEC start failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC SEC start"); + + p = (unsigned char *) modem_image_data + N7100_FIRMWARE_OFFSET; + + rc = xmm6260_hsic_firmware_send(client, modem_boot_fd, (void *) p, N7100_FIRMWARE_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC firmware failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC firmware"); + + rc = xmm6260_hsic_nv_data_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC nv_data failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC nv_data"); + + rc = xmm6260_hsic_sec_end_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC SEC end failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC SEC end"); + + rc = xmm6260_hsic_hw_reset_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 HSIC HW reset failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 HSIC HW reset"); + + usleep(300000); + + rc = xmm6260_sec_modem_link_get_hostwake_wait(modem_link_fd); + if (rc < 0) { + ipc_client_log(client, "Waiting for host wake failed"); + } + + rc = xmm6260_sec_modem_link_control_enable(modem_link_fd, 0); + rc |= xmm6260_sec_modem_hci_power(0); + rc |= xmm6260_sec_modem_link_control_active(modem_link_fd, 0); + + if (rc < 0) { + ipc_client_log(client, "Turning the modem off failed"); + goto error; + } + + rc = xmm6260_sec_modem_link_get_hostwake_wait(modem_link_fd); + if (rc < 0) { + ipc_client_log(client, "Waiting for host wake failed"); + goto error; + } + ipc_client_log(client, "Waited for host wake"); + + rc = xmm6260_sec_modem_link_control_enable(modem_link_fd, 1); + rc |= xmm6260_sec_modem_hci_power(1); + rc |= xmm6260_sec_modem_link_control_active(modem_link_fd, 1); + + if (rc < 0) { + ipc_client_log(client, "Turning the modem on failed"); + goto error; + } + + rc = xmm6260_sec_modem_link_connected_wait(modem_link_fd); + if (rc < 0) { + ipc_client_log(client, "Waiting for link connected failed"); + goto error; + } + ipc_client_log(client, "Waited for link connected"); + + usleep(300000); + + rc = 0; + goto complete; + +error: + rc = -1; + +complete: + if (modem_image_data != NULL) + munmap(modem_image_data, N7100_MODEM_IMAGE_SIZE); + + if (modem_image_fd >= 0) + close(modem_image_fd); + + if (modem_boot_fd >= 0) + close(modem_boot_fd); + + if (modem_link_fd >= 0) + close(modem_link_fd); + + return rc; +} + +int n7100_open(void *data, int type) +{ + struct n7100_transport_data *transport_data; + + if (data == NULL) + return -1; + + transport_data = (struct n7100_transport_data *) data; + + transport_data->fd = xmm6260_sec_modem_open(type); + if (transport_data->fd < 0) + return -1; + + return 0; +} + +int n7100_close(void *data) +{ + struct n7100_transport_data *transport_data; + + if (data == NULL) + return -1; + + transport_data = (struct n7100_transport_data *) data; + + xmm6260_sec_modem_close(transport_data->fd); + transport_data->fd = -1; + + return 0; +} + +int n7100_read(void *data, void *buffer, size_t length) +{ + struct n7100_transport_data *transport_data; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct n7100_transport_data *) data; + + rc = xmm6260_sec_modem_read(transport_data->fd, buffer, length); + + return rc; +} + +int n7100_write(void *data, const void *buffer, size_t length) +{ + struct n7100_transport_data *transport_data; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct n7100_transport_data *) data; + + rc = xmm6260_sec_modem_write(transport_data->fd, buffer, length); + + return rc; +} + +int n7100_poll(void *data, struct timeval *timeout) +{ + struct n7100_transport_data *transport_data; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct n7100_transport_data *) data; + + rc = xmm6260_sec_modem_poll(transport_data->fd, timeout); + + return rc; +} + +int n7100_power_on(void *data) +{ + return 0; +} + +int n7100_power_off(void *data) +{ + int fd; + int rc; + + fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (fd < 0) + return -1; + + rc = xmm6260_sec_modem_power(fd, 0); + + close(fd); + + if (rc < 0) + return -1; + + return 0; +} + +int n7100_data_create(void **transport_data, void **power_data, + void **gprs_data) +{ + if (transport_data == NULL) + return -1; + + *transport_data = calloc(1, sizeof(struct n7100_transport_data)); + + return 0; +} + +int n7100_data_destroy(void *transport_data, void *power_data, + void *gprs_data) +{ + if (transport_data == NULL) + return -1; + + free(transport_data); + + return 0; +} + +struct ipc_client_ops n7100_fmt_ops = { + .boot = n7100_boot, + .send = xmm6260_sec_modem_fmt_send, + .recv = xmm6260_sec_modem_fmt_recv, +}; + +struct ipc_client_ops n7100_rfs_ops = { + .boot = NULL, + .send = xmm6260_sec_modem_rfs_send, + .recv = xmm6260_sec_modem_rfs_recv, +}; + +struct ipc_client_handlers n7100_handlers = { + .read = n7100_read, + .write = n7100_write, + .open = n7100_open, + .close = n7100_close, + .poll = n7100_poll, + .transport_data = NULL, + .power_on = n7100_power_on, + .power_off = n7100_power_off, + .power_data = NULL, + .gprs_activate = NULL, + .gprs_deactivate = NULL, + .gprs_data = NULL, + .data_create = n7100_data_create, + .data_destroy = n7100_data_destroy, +}; + +struct ipc_client_gprs_specs n7100_gprs_specs = { + .gprs_get_iface = xmm6260_sec_modem_gprs_get_iface, + .gprs_get_capabilities = xmm6260_sec_modem_gprs_get_capabilities, +}; + +struct ipc_client_nv_data_specs n7100_nv_data_specs = { + .nv_data_path = XMM6260_NV_DATA_PATH, + .nv_data_md5_path = XMM6260_NV_DATA_MD5_PATH, + .nv_data_backup_path = XMM6260_NV_DATA_BACKUP_PATH, + .nv_data_backup_md5_path = XMM6260_NV_DATA_BACKUP_MD5_PATH, + .nv_data_secret = XMM6260_NV_DATA_SECRET, + .nv_data_size = XMM6260_NV_DATA_SIZE, + .nv_data_chunk_size = XMM6260_NV_DATA_CHUNK_SIZE, +}; + +// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/n7100/n7100.h b/samsung-ipc/devices/n7100/n7100.h new file mode 100644 index 0000000..5ffd353 --- /dev/null +++ b/samsung-ipc/devices/n7100/n7100.h @@ -0,0 +1,49 @@ +/* + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2013-2014 Paul Kocialkowski + * + * libsamsung-ipc 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 2 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc 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 libsamsung-ipc. If not, see . + */ + +#ifndef __N7100_H__ +#define __N7100_H__ + +#define N7100_MODEM_IMAGE_SIZE 0x1000000 +#define N7100_PSI_OFFSET 0x1000 +#define N7100_PSI_SIZE 0xE000 +#define N7100_EBL_OFFSET 0xF000 +#define N7100_EBL_SIZE 0x19000 +#define N7100_SEC_START_OFFSET 0x9FF800 +#define N7100_SEC_START_SIZE 0x800 +#define N7100_FIRMWARE_OFFSET 0x28000 +#define N7100_FIRMWARE_SIZE 0x9D7800 +#define N7100_NV_DATA_OFFSET 0xA00000 +#define N7100_NV_DATA_SIZE 0x200000 + +#define N7100_MODEM_IMAGE_DEVICE "/dev/block/mmcblk0p10" + +struct n7100_transport_data { + int fd; +}; + +extern struct ipc_client_ops n7100_fmt_ops; +extern struct ipc_client_ops n7100_rfs_ops; +extern struct ipc_client_handlers n7100_handlers; +extern struct ipc_client_gprs_specs n7100_gprs_specs; +extern struct ipc_client_nv_data_specs n7100_nv_data_specs; + +#endif + +// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/n7100/n7100_ipc.c b/samsung-ipc/devices/n7100/n7100_ipc.c deleted file mode 100644 index ad118da..0000000 --- a/samsung-ipc/devices/n7100/n7100_ipc.c +++ /dev/null @@ -1,421 +0,0 @@ -/* - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2013 Paul Kocialkowski - * - * libsamsung-ipc 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 2 of the License, or - * (at your option) any later version. - * - * libsamsung-ipc 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 libsamsung-ipc. If not, see . - */ - -#include -#include -#include -#include -#include - -#include -#include - -#include "xmm6260.h" -#include "xmm6260_hsic.h" -#include "xmm6260_sec_modem.h" -#include "n7100_ipc.h" - -int n7100_ipc_bootstrap(struct ipc_client *client) -{ - void *modem_image_data = NULL; - int modem_image_fd = -1; - int modem_boot_fd = -1; - int modem_link_fd = -1; - - unsigned char *p; - int rc; - - if (client == NULL) - return -1; - - ipc_client_log(client, "Starting n7100 modem bootstrap"); - - modem_image_fd = open(N7100_MODEM_IMAGE_DEVICE, O_RDONLY); - if (modem_image_fd < 0) { - ipc_client_log(client, "Opening modem image device failed"); - goto error; - } - ipc_client_log(client, "Opened modem image device"); - - modem_image_data = mmap(0, N7100_MODEM_IMAGE_SIZE, PROT_READ, MAP_SHARED, modem_image_fd, 0); - if (modem_image_data == NULL || modem_image_data == (void *) 0xffffffff) { - ipc_client_log(client, "Mapping modem image data to memory failed"); - goto error; - } - ipc_client_log(client, "Mapped modem image data to memory"); - - modem_boot_fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); - if (modem_boot_fd < 0) { - ipc_client_log(client, "Opening modem boot device failed"); - goto error; - } - ipc_client_log(client, "Opened modem boot device"); - - modem_link_fd = open(XMM6260_SEC_MODEM_LINK_PM_DEVICE, O_RDWR); - if (modem_link_fd < 0) { - ipc_client_log(client, "Opening modem link device failed"); - goto error; - } - ipc_client_log(client, "Opened modem link device"); - - rc = xmm6260_sec_modem_hci_power(0); - if (rc < 0) { - ipc_client_log(client, "Turning the modem off failed"); - goto error; - } - ipc_client_log(client, "Turned the modem off"); - - rc = xmm6260_sec_modem_power(modem_boot_fd, 1); - rc |= xmm6260_sec_modem_hci_power(1); - - if (rc < 0) { - ipc_client_log(client, "Turning the modem on failed"); - goto error; - } - ipc_client_log(client, "Turned the modem on"); - - rc = xmm6260_sec_modem_link_connected_wait(modem_link_fd); - if (rc < 0) { - ipc_client_log(client, "Waiting for link connected failed"); - goto error; - } - ipc_client_log(client, "Waited for link connected"); - - p = (unsigned char *) modem_image_data + N7100_PSI_OFFSET; - - rc = xmm6260_hsic_psi_send(client, modem_boot_fd, (void *) p, N7100_PSI_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC PSI failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC PSI"); - - p = (unsigned char *) modem_image_data + N7100_EBL_OFFSET; - - rc = xmm6260_hsic_ebl_send(client, modem_boot_fd, (void *) p, N7100_EBL_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC EBL failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC EBL"); - - rc = xmm6260_hsic_port_config_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC port config failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC port config"); - - p = (unsigned char *) modem_image_data + N7100_SEC_START_OFFSET; - - rc = xmm6260_hsic_sec_start_send(client, modem_boot_fd, (void *) p, N7100_SEC_START_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC SEC start failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC SEC start"); - - p = (unsigned char *) modem_image_data + N7100_FIRMWARE_OFFSET; - - rc = xmm6260_hsic_firmware_send(client, modem_boot_fd, (void *) p, N7100_FIRMWARE_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC firmware failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC firmware"); - - rc = xmm6260_hsic_nv_data_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC nv_data failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC nv_data"); - - rc = xmm6260_hsic_sec_end_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC SEC end failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC SEC end"); - - rc = xmm6260_hsic_hw_reset_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 HSIC HW reset failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 HSIC HW reset"); - - usleep(300000); - - rc = xmm6260_sec_modem_link_get_hostwake_wait(modem_link_fd); - if (rc < 0) { - ipc_client_log(client, "Waiting for host wake failed"); - } - - rc = xmm6260_sec_modem_link_control_enable(modem_link_fd, 0); - rc |= xmm6260_sec_modem_hci_power(0); - rc |= xmm6260_sec_modem_link_control_active(modem_link_fd, 0); - - if (rc < 0) { - ipc_client_log(client, "Turning the modem off failed"); - goto error; - } - - rc = xmm6260_sec_modem_link_get_hostwake_wait(modem_link_fd); - if (rc < 0) { - ipc_client_log(client, "Waiting for host wake failed"); - goto error; - } - ipc_client_log(client, "Waited for host wake"); - - rc = xmm6260_sec_modem_link_control_enable(modem_link_fd, 1); - rc |= xmm6260_sec_modem_hci_power(1); - rc |= xmm6260_sec_modem_link_control_active(modem_link_fd, 1); - - if (rc < 0) { - ipc_client_log(client, "Turning the modem on failed"); - goto error; - } - - rc = xmm6260_sec_modem_link_connected_wait(modem_link_fd); - if (rc < 0) { - ipc_client_log(client, "Waiting for link connected failed"); - goto error; - } - ipc_client_log(client, "Waited for link connected"); - - usleep(300000); - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (modem_image_data != NULL) - munmap(modem_image_data, N7100_MODEM_IMAGE_SIZE); - - if (modem_image_fd >= 0) - close(modem_image_fd); - - if (modem_boot_fd >= 0) - close(modem_boot_fd); - - if (modem_link_fd >= 0) - close(modem_link_fd); - - return rc; -} - - -int n7100_ipc_fmt_send(struct ipc_client *client, struct ipc_message_info *request) -{ - return xmm6260_sec_modem_ipc_fmt_send(client, request); -} - -int n7100_ipc_fmt_recv(struct ipc_client *client, struct ipc_message_info *response) -{ - return xmm6260_sec_modem_ipc_fmt_recv(client, response); -} - -int n7100_ipc_rfs_send(struct ipc_client *client, struct ipc_message_info *request) -{ - return xmm6260_sec_modem_ipc_rfs_send(client, request); -} - -int n7100_ipc_rfs_recv(struct ipc_client *client, struct ipc_message_info *response) -{ - return xmm6260_sec_modem_ipc_rfs_recv(client, response); -} - -int n7100_ipc_open(void *data, int type) -{ - struct n7100_ipc_transport_data *transport_data; - - if (data == NULL) - return -1; - - transport_data = (struct n7100_ipc_transport_data *) data; - - transport_data->fd = xmm6260_sec_modem_ipc_open(type); - if (transport_data->fd < 0) - return -1; - - return 0; -} - -int n7100_ipc_close(void *data) -{ - struct n7100_ipc_transport_data *transport_data; - - if (data == NULL) - return -1; - - transport_data = (struct n7100_ipc_transport_data *) data; - - xmm6260_sec_modem_ipc_close(transport_data->fd); - transport_data->fd = -1; - - return 0; -} - -int n7100_ipc_read(void *data, void *buffer, unsigned int length) -{ - struct n7100_ipc_transport_data *transport_data; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct n7100_ipc_transport_data *) data; - - rc = xmm6260_sec_modem_ipc_read(transport_data->fd, buffer, length); - return rc; -} - -int n7100_ipc_write(void *data, void *buffer, unsigned int length) -{ - struct n7100_ipc_transport_data *transport_data; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct n7100_ipc_transport_data *) data; - - rc = xmm6260_sec_modem_ipc_write(transport_data->fd, buffer, length); - return rc; -} - -int n7100_ipc_poll(void *data, struct timeval *timeout) -{ - struct n7100_ipc_transport_data *transport_data; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct n7100_ipc_transport_data *) data; - - rc = xmm6260_sec_modem_ipc_poll(transport_data->fd, timeout); - return rc; -} - -int n7100_ipc_power_on(void *data) -{ - return 0; -} - -int n7100_ipc_power_off(void *data) -{ - int fd; - int rc; - - fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); - if (fd < 0) - return -1; - - rc = xmm6260_sec_modem_power(fd, 0); - - close(fd); - - if (rc < 0) - return -1; - - return 0; -} - -int n7100_ipc_data_create(void **transport_data, void **power_data, void **gprs_data) -{ - if (transport_data == NULL) - return -1; - - *transport_data = (void *) malloc(sizeof(struct n7100_ipc_transport_data)); - memset(*transport_data, 0, sizeof(struct n7100_ipc_transport_data)); - - return 0; -} - -int n7100_ipc_data_destroy(void *transport_data, void *power_data, void *gprs_data) -{ - if (transport_data == NULL) - return -1; - - free(transport_data); - - return 0; -} - -char *n7100_ipc_gprs_get_iface(int cid) -{ - return xmm6260_sec_modem_ipc_gprs_get_iface(cid); -} - - -int n7100_ipc_gprs_get_capabilities(struct ipc_client_gprs_capabilities *capabilities) -{ - return xmm6260_sec_modem_ipc_gprs_get_capabilities(capabilities); -} - -struct ipc_ops n7100_ipc_fmt_ops = { - .bootstrap = n7100_ipc_bootstrap, - .send = n7100_ipc_fmt_send, - .recv = n7100_ipc_fmt_recv, -}; - -struct ipc_ops n7100_ipc_rfs_ops = { - .bootstrap = NULL, - .send = n7100_ipc_rfs_send, - .recv = n7100_ipc_rfs_recv, -}; - -struct ipc_handlers n7100_ipc_handlers = { - .read = n7100_ipc_read, - .write = n7100_ipc_write, - .open = n7100_ipc_open, - .close = n7100_ipc_close, - .poll = n7100_ipc_poll, - .transport_data = NULL, - .power_on = n7100_ipc_power_on, - .power_off = n7100_ipc_power_off, - .power_data = NULL, - .gprs_activate = NULL, - .gprs_deactivate = NULL, - .gprs_data = NULL, - .data_create = n7100_ipc_data_create, - .data_destroy = n7100_ipc_data_destroy, -}; - -struct ipc_gprs_specs n7100_ipc_gprs_specs = { - .gprs_get_iface = n7100_ipc_gprs_get_iface, - .gprs_get_capabilities = n7100_ipc_gprs_get_capabilities, -}; - -struct ipc_nv_data_specs n7100_ipc_nv_data_specs = { - .nv_data_path = XMM6260_NV_DATA_PATH, - .nv_data_md5_path = XMM6260_NV_DATA_MD5_PATH, - .nv_data_backup_path = XMM6260_NV_DATA_BACKUP_PATH, - .nv_data_backup_md5_path = XMM6260_NV_DATA_BACKUP_MD5_PATH, - .nv_data_secret = XMM6260_NV_DATA_SECRET, - .nv_data_size = XMM6260_NV_DATA_SIZE, - .nv_data_chunk_size = XMM6260_NV_DATA_CHUNK_SIZE, -}; - -// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/n7100/n7100_ipc.h b/samsung-ipc/devices/n7100/n7100_ipc.h deleted file mode 100644 index 0008627..0000000 --- a/samsung-ipc/devices/n7100/n7100_ipc.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2013-2014 Paul Kocialkowski - * - * libsamsung-ipc 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 2 of the License, or - * (at your option) any later version. - * - * libsamsung-ipc 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 libsamsung-ipc. If not, see . - */ - -#ifndef __N7100_IPC_H__ -#define __N7100_IPC_H__ - -#define N7100_MODEM_IMAGE_SIZE 0x1000000 -#define N7100_PSI_OFFSET 0x1000 -#define N7100_PSI_SIZE 0xE000 -#define N7100_EBL_OFFSET 0xF000 -#define N7100_EBL_SIZE 0x19000 -#define N7100_SEC_START_OFFSET 0x9FF800 -#define N7100_SEC_START_SIZE 0x800 -#define N7100_FIRMWARE_OFFSET 0x28000 -#define N7100_FIRMWARE_SIZE 0x9D7800 -#define N7100_NV_DATA_OFFSET 0xA00000 -#define N7100_NV_DATA_SIZE 0x200000 - -#define N7100_MODEM_IMAGE_DEVICE "/dev/block/mmcblk0p10" - -struct n7100_ipc_transport_data { - int fd; -}; - -extern struct ipc_ops n7100_ipc_fmt_ops; -extern struct ipc_ops n7100_ipc_rfs_ops; -extern struct ipc_handlers n7100_ipc_handlers; -extern struct ipc_gprs_specs n7100_ipc_gprs_specs; -extern struct ipc_nv_data_specs n7100_ipc_nv_data_specs; - -#endif - -// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/piranha/piranha.c b/samsung-ipc/devices/piranha/piranha.c new file mode 100644 index 0000000..44af920 --- /dev/null +++ b/samsung-ipc/devices/piranha/piranha.c @@ -0,0 +1,340 @@ +/* + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2013-2014 Paul Kocialkowski + * + * libsamsung-ipc 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 2 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc 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 libsamsung-ipc. If not, see . + */ + +#include +#include +#include +#include +#include + +#include +#include + +#include "xmm6260.h" +#include "xmm6260_mipi.h" +#include "xmm6260_sec_modem.h" +#include "piranha.h" + +int piranha_boot(struct ipc_client *client) +{ + void *modem_image_data = NULL; + int modem_image_fd = -1; + int modem_boot_fd = -1; + unsigned char *p; + int rc; + + if (client == NULL) + return -1; + + ipc_client_log(client, "Starting piranha modem boot"); + + modem_image_fd = open(PIRANHA_MODEM_IMAGE_DEVICE, O_RDONLY); + if (modem_image_fd < 0) { + ipc_client_log(client, "Opening modem image device failed"); + goto error; + } + ipc_client_log(client, "Opened modem image device"); + + modem_image_data = mmap(0, PIRANHA_MODEM_IMAGE_SIZE, PROT_READ, MAP_SHARED, modem_image_fd, 0); + if (modem_image_data == NULL || modem_image_data == (void *) 0xffffffff) { + ipc_client_log(client, "Mapping modem image data to memory failed"); + goto error; + } + ipc_client_log(client, "Mapped modem image data to memory"); + + modem_boot_fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (modem_boot_fd < 0) { + ipc_client_log(client, "Opening modem boot device failed"); + goto error; + } + ipc_client_log(client, "Opened modem boot device"); + + rc = xmm6260_sec_modem_power(modem_boot_fd, 0); + if (rc < 0) { + ipc_client_log(client, "Turning the modem off failed"); + goto error; + } + ipc_client_log(client, "Turned the modem off"); + + rc = xmm6260_sec_modem_power(modem_boot_fd, 1); + if (rc < 0) { + ipc_client_log(client, "Turning the modem on failed"); + goto error; + } + ipc_client_log(client, "Turned the modem on"); + + p = (unsigned char *) modem_image_data + PIRANHA_PSI_OFFSET; + + rc = xmm6260_mipi_psi_send(client, modem_boot_fd, (void *) p, PIRANHA_PSI_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI PSI failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI PSI"); + + close(modem_boot_fd); + + modem_boot_fd = open(XMM6260_SEC_MODEM_BOOT1_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (modem_boot_fd < 0) { + ipc_client_log(client, "Opening modem boot device failed"); + goto error; + } + ipc_client_log(client, "Opened modem boot device"); + + p = (unsigned char *) modem_image_data + PIRANHA_EBL_OFFSET; + + rc = xmm6260_mipi_ebl_send(client, modem_boot_fd, (void *) p, PIRANHA_EBL_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI EBL failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI EBL"); + + rc = xmm6260_mipi_port_config_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI port config failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI port config"); + + p = (unsigned char *) modem_image_data + PIRANHA_SEC_START_OFFSET; + + rc = xmm6260_mipi_sec_start_send(client, modem_boot_fd, (void *) p, PIRANHA_SEC_START_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI SEC start failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI SEC start"); + + p = (unsigned char *) modem_image_data + PIRANHA_FIRMWARE_OFFSET; + + rc = xmm6260_mipi_firmware_send(client, modem_boot_fd, (void *) p, PIRANHA_FIRMWARE_SIZE); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI firmware failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI firmware"); + + rc = xmm6260_mipi_nv_data_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI nv_data failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI nv_data"); + + rc = xmm6260_mipi_sec_end_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI SEC end failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI SEC end"); + + rc = xmm6260_mipi_hw_reset_send(client, modem_boot_fd); + if (rc < 0) { + ipc_client_log(client, "Sending XMM6260 MIPI HW reset failed"); + goto error; + } + ipc_client_log(client, "Sent XMM6260 MIPI HW reset"); + + rc = 0; + goto complete; + +error: + rc = -1; + +complete: + if (modem_image_data != NULL) + munmap(modem_image_data, PIRANHA_MODEM_IMAGE_SIZE); + + if (modem_image_fd >= 0) + close(modem_image_fd); + + if (modem_boot_fd >= 0) + close(modem_boot_fd); + + return rc; +} + +int piranha_open(void *data, int type) +{ + struct piranha_transport_data *transport_data; + + if (data == NULL) + return -1; + + transport_data = (struct piranha_transport_data *) data; + + transport_data->fd = xmm6260_sec_modem_open(type); + if (transport_data->fd < 0) + return -1; + + return 0; +} + +int piranha_close(void *data) +{ + struct piranha_transport_data *transport_data; + + if (data == NULL) + return -1; + + transport_data = (struct piranha_transport_data *) data; + + xmm6260_sec_modem_close(transport_data->fd); + transport_data->fd = -1; + + return 0; +} + +int piranha_read(void *data, void *buffer, size_t length) +{ + struct piranha_transport_data *transport_data; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct piranha_transport_data *) data; + + rc = xmm6260_sec_modem_read(transport_data->fd, buffer, length); + + return rc; +} + +int piranha_write(void *data, const void *buffer, size_t length) +{ + struct piranha_transport_data *transport_data; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct piranha_transport_data *) data; + + rc = xmm6260_sec_modem_write(transport_data->fd, buffer, length); + + return rc; +} + +int piranha_poll(void *data, struct timeval *timeout) +{ + struct piranha_transport_data *transport_data; + int rc; + + if (data == NULL) + return -1; + + transport_data = (struct piranha_transport_data *) data; + + rc = xmm6260_sec_modem_poll(transport_data->fd, timeout); + + return rc; +} + +int piranha_power_on(void *data) +{ + return 0; +} + +int piranha_power_off(void *data) +{ + int fd; + int rc; + + fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); + if (fd < 0) + return -1; + + rc = xmm6260_sec_modem_power(fd, 0); + + close(fd); + + if (rc < 0) + return -1; + + return 0; +} + +int piranha_data_create(void **transport_data, void **power_data, + void **gprs_data) +{ + if (transport_data == NULL) + return -1; + + *transport_data = calloc(1, sizeof(struct piranha_transport_data)); + + return 0; +} + +int piranha_data_destroy(void *transport_data, void *power_data, + void *gprs_data) +{ + if (transport_data == NULL) + return -1; + + free(transport_data); + + return 0; +} + +struct ipc_client_ops piranha_fmt_ops = { + .boot = piranha_boot, + .send = xmm6260_sec_modem_fmt_send, + .recv = xmm6260_sec_modem_fmt_recv, +}; + +struct ipc_client_ops piranha_rfs_ops = { + .boot = NULL, + .send = xmm6260_sec_modem_rfs_send, + .recv = xmm6260_sec_modem_rfs_recv, +}; + +struct ipc_client_handlers piranha_handlers = { + .read = piranha_read, + .write = piranha_write, + .open = piranha_open, + .close = piranha_close, + .poll = piranha_poll, + .transport_data = NULL, + .power_on = piranha_power_on, + .power_off = piranha_power_off, + .power_data = NULL, + .gprs_activate = NULL, + .gprs_deactivate = NULL, + .gprs_data = NULL, + .data_create = piranha_data_create, + .data_destroy = piranha_data_destroy, +}; + +struct ipc_client_gprs_specs piranha_gprs_specs = { + .gprs_get_iface = xmm6260_sec_modem_gprs_get_iface, + .gprs_get_capabilities = xmm6260_sec_modem_gprs_get_capabilities, +}; + +struct ipc_client_nv_data_specs piranha_nv_data_specs = { + .nv_data_path = XMM6260_NV_DATA_PATH, + .nv_data_md5_path = XMM6260_NV_DATA_MD5_PATH, + .nv_data_backup_path = XMM6260_NV_DATA_BACKUP_PATH, + .nv_data_backup_md5_path = XMM6260_NV_DATA_BACKUP_MD5_PATH, + .nv_data_secret = XMM6260_NV_DATA_SECRET, + .nv_data_size = XMM6260_NV_DATA_SIZE, + .nv_data_chunk_size = XMM6260_NV_DATA_CHUNK_SIZE, +}; + +// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/piranha/piranha.h b/samsung-ipc/devices/piranha/piranha.h new file mode 100644 index 0000000..834f7c3 --- /dev/null +++ b/samsung-ipc/devices/piranha/piranha.h @@ -0,0 +1,50 @@ +/* + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2013-2014 Paul Kocialkowski + * + * libsamsung-ipc 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 2 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc 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 libsamsung-ipc. If not, see . + */ + +#ifndef __PIRANHA_H__ +#define __PIRANHA_H__ + +#define PIRANHA_MODEM_IMAGE_SIZE 0x1400000 +#define PIRANHA_PSI_OFFSET 0x1000 +#define PIRANHA_PSI_SIZE 0xE000 +#define PIRANHA_EBL_OFFSET 0xF000 +#define PIRANHA_EBL_SIZE 0x19000 +#define PIRANHA_SEC_START_OFFSET 0x9FF800 +#define PIRANHA_SEC_START_SIZE 0x800 +#define PIRANHA_FIRMWARE_OFFSET 0x28000 +#define PIRANHA_FIRMWARE_SIZE 0x9D7800 +#define PIRANHA_NV_DATA_OFFSET 0xA00000 +#define PIRANHA_NV_DATA_SIZE 0x200000 + +#define PIRANHA_MODEM_IMAGE_DEVICE "/dev/block/mmcblk0p8" + +struct piranha_transport_data { + int fd; +}; + +extern struct ipc_client_ops piranha_fmt_ops; +extern struct ipc_client_ops piranha_rfs_ops; +extern struct ipc_client_handlers piranha_handlers; +extern struct ipc_client_gprs_specs piranha_gprs_specs; +extern struct ipc_client_nv_data_specs piranha_nv_data_specs; +extern struct ipc_client_nv_data_specs piranha_nv_data_specs; + +#endif + +// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/piranha/piranha_ipc.c b/samsung-ipc/devices/piranha/piranha_ipc.c deleted file mode 100644 index 88754dd..0000000 --- a/samsung-ipc/devices/piranha/piranha_ipc.c +++ /dev/null @@ -1,368 +0,0 @@ -/* - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2013 Paul Kocialkowski - * - * libsamsung-ipc 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 2 of the License, or - * (at your option) any later version. - * - * libsamsung-ipc 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 libsamsung-ipc. If not, see . - */ - -#include -#include -#include -#include -#include - -#include -#include - -#include "xmm6260.h" -#include "xmm6260_mipi.h" -#include "xmm6260_sec_modem.h" -#include "piranha_ipc.h" - -int piranha_ipc_bootstrap(struct ipc_client *client) -{ - void *modem_image_data = NULL; - int modem_image_fd = -1; - int modem_boot_fd = -1; - - unsigned char *p; - int rc; - - if (client == NULL) - return -1; - - ipc_client_log(client, "Starting piranha modem bootstrap"); - - modem_image_fd = open(PIRANHA_MODEM_IMAGE_DEVICE, O_RDONLY); - if (modem_image_fd < 0) { - ipc_client_log(client, "Opening modem image device failed"); - goto error; - } - ipc_client_log(client, "Opened modem image device"); - - modem_image_data = mmap(0, PIRANHA_MODEM_IMAGE_SIZE, PROT_READ, MAP_SHARED, modem_image_fd, 0); - if (modem_image_data == NULL || modem_image_data == (void *) 0xffffffff) { - ipc_client_log(client, "Mapping modem image data to memory failed"); - goto error; - } - ipc_client_log(client, "Mapped modem image data to memory"); - - modem_boot_fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); - if (modem_boot_fd < 0) { - ipc_client_log(client, "Opening modem boot device failed"); - goto error; - } - ipc_client_log(client, "Opened modem boot device"); - - rc = xmm6260_sec_modem_power(modem_boot_fd, 0); - if (rc < 0) { - ipc_client_log(client, "Turning the modem off failed"); - goto error; - } - ipc_client_log(client, "Turned the modem off"); - - rc = xmm6260_sec_modem_power(modem_boot_fd, 1); - if (rc < 0) { - ipc_client_log(client, "Turning the modem on failed"); - goto error; - } - ipc_client_log(client, "Turned the modem on"); - - p = (unsigned char *) modem_image_data + PIRANHA_PSI_OFFSET; - - rc = xmm6260_mipi_psi_send(client, modem_boot_fd, (void *) p, PIRANHA_PSI_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI PSI failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI PSI"); - - close(modem_boot_fd); - - modem_boot_fd = open(XMM6260_SEC_MODEM_BOOT1_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); - if (modem_boot_fd < 0) { - ipc_client_log(client, "Opening modem boot device failed"); - goto error; - } - ipc_client_log(client, "Opened modem boot device"); - - p = (unsigned char *) modem_image_data + PIRANHA_EBL_OFFSET; - - rc = xmm6260_mipi_ebl_send(client, modem_boot_fd, (void *) p, PIRANHA_EBL_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI EBL failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI EBL"); - - rc = xmm6260_mipi_port_config_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI port config failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI port config"); - - p = (unsigned char *) modem_image_data + PIRANHA_SEC_START_OFFSET; - - rc = xmm6260_mipi_sec_start_send(client, modem_boot_fd, (void *) p, PIRANHA_SEC_START_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI SEC start failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI SEC start"); - - p = (unsigned char *) modem_image_data + PIRANHA_FIRMWARE_OFFSET; - - rc = xmm6260_mipi_firmware_send(client, modem_boot_fd, (void *) p, PIRANHA_FIRMWARE_SIZE); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI firmware failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI firmware"); - - rc = xmm6260_mipi_nv_data_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI nv_data failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI nv_data"); - - rc = xmm6260_mipi_sec_end_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI SEC end failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI SEC end"); - - rc = xmm6260_mipi_hw_reset_send(client, modem_boot_fd); - if (rc < 0) { - ipc_client_log(client, "Sending XMM6260 MIPI HW reset failed"); - goto error; - } - ipc_client_log(client, "Sent XMM6260 MIPI HW reset"); - - rc = 0; - goto complete; - -error: - rc = -1; - -complete: - if (modem_image_data != NULL) - munmap(modem_image_data, PIRANHA_MODEM_IMAGE_SIZE); - - if (modem_image_fd >= 0) - close(modem_image_fd); - - if (modem_boot_fd >= 0) - close(modem_boot_fd); - - return rc; -} - -int piranha_ipc_fmt_send(struct ipc_client *client, struct ipc_message_info *request) -{ - return xmm6260_sec_modem_ipc_fmt_send(client, request); -} - -int piranha_ipc_fmt_recv(struct ipc_client *client, struct ipc_message_info *response) -{ - return xmm6260_sec_modem_ipc_fmt_recv(client, response); -} - -int piranha_ipc_rfs_send(struct ipc_client *client, struct ipc_message_info *request) -{ - return xmm6260_sec_modem_ipc_rfs_send(client, request); -} - -int piranha_ipc_rfs_recv(struct ipc_client *client, struct ipc_message_info *response) -{ - return xmm6260_sec_modem_ipc_rfs_recv(client, response); -} - -int piranha_ipc_open(void *data, int type) -{ - struct piranha_ipc_transport_data *transport_data; - - if (data == NULL) - return -1; - - transport_data = (struct piranha_ipc_transport_data *) data; - - transport_data->fd = xmm6260_sec_modem_ipc_open(type); - if (transport_data->fd < 0) - return -1; - - return 0; -} - -int piranha_ipc_close(void *data) -{ - struct piranha_ipc_transport_data *transport_data; - - if (data == NULL) - return -1; - - transport_data = (struct piranha_ipc_transport_data *) data; - - xmm6260_sec_modem_ipc_close(transport_data->fd); - transport_data->fd = -1; - - return 0; -} - -int piranha_ipc_read(void *data, void *buffer, unsigned int length) -{ - struct piranha_ipc_transport_data *transport_data; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct piranha_ipc_transport_data *) data; - - rc = xmm6260_sec_modem_ipc_read(transport_data->fd, buffer, length); - return rc; -} - -int piranha_ipc_write(void *data, void *buffer, unsigned int length) -{ - struct piranha_ipc_transport_data *transport_data; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct piranha_ipc_transport_data *) data; - - rc = xmm6260_sec_modem_ipc_write(transport_data->fd, buffer, length); - return rc; -} - -int piranha_ipc_poll(void *data, struct timeval *timeout) -{ - struct piranha_ipc_transport_data *transport_data; - int rc; - - if (data == NULL) - return -1; - - transport_data = (struct piranha_ipc_transport_data *) data; - - rc = xmm6260_sec_modem_ipc_poll(transport_data->fd, timeout); - return rc; -} - -int piranha_ipc_power_on(void *data) -{ - return 0; -} - -int piranha_ipc_power_off(void *data) -{ - int fd; - int rc; - - fd = open(XMM6260_SEC_MODEM_BOOT0_DEVICE, O_RDWR | O_NOCTTY | O_NONBLOCK); - if (fd < 0) - return -1; - - rc = xmm6260_sec_modem_power(fd, 0); - - close(fd); - - if (rc < 0) - return -1; - - return 0; -} - -int piranha_ipc_data_create(void **transport_data, void **power_data, void **gprs_data) -{ - if (transport_data == NULL) - return -1; - - *transport_data = (void *) malloc(sizeof(struct piranha_ipc_transport_data)); - memset(*transport_data, 0, sizeof(struct piranha_ipc_transport_data)); - - return 0; -} - -int piranha_ipc_data_destroy(void *transport_data, void *power_data, void *gprs_data) -{ - if (transport_data == NULL) - return -1; - - free(transport_data); - - return 0; -} - -char *piranha_ipc_gprs_get_iface(int cid) -{ - return xmm6260_sec_modem_ipc_gprs_get_iface(cid); -} - - -int piranha_ipc_gprs_get_capabilities(struct ipc_client_gprs_capabilities *capabilities) -{ - return xmm6260_sec_modem_ipc_gprs_get_capabilities(capabilities); -} - -struct ipc_ops piranha_ipc_fmt_ops = { - .bootstrap = piranha_ipc_bootstrap, - .send = piranha_ipc_fmt_send, - .recv = piranha_ipc_fmt_recv, -}; - -struct ipc_ops piranha_ipc_rfs_ops = { - .bootstrap = NULL, - .send = piranha_ipc_rfs_send, - .recv = piranha_ipc_rfs_recv, -}; - -struct ipc_handlers piranha_ipc_handlers = { - .read = piranha_ipc_read, - .write = piranha_ipc_write, - .open = piranha_ipc_open, - .close = piranha_ipc_close, - .poll = piranha_ipc_poll, - .transport_data = NULL, - .power_on = piranha_ipc_power_on, - .power_off = piranha_ipc_power_off, - .power_data = NULL, - .gprs_activate = NULL, - .gprs_deactivate = NULL, - .gprs_data = NULL, - .data_create = piranha_ipc_data_create, - .data_destroy = piranha_ipc_data_destroy, -}; - -struct ipc_gprs_specs piranha_ipc_gprs_specs = { - .gprs_get_iface = piranha_ipc_gprs_get_iface, - .gprs_get_capabilities = piranha_ipc_gprs_get_capabilities, -}; - -struct ipc_nv_data_specs piranha_ipc_nv_data_specs = { - .nv_data_path = XMM6260_NV_DATA_PATH, - .nv_data_md5_path = XMM6260_NV_DATA_MD5_PATH, - .nv_data_backup_path = XMM6260_NV_DATA_BACKUP_PATH, - .nv_data_backup_md5_path = XMM6260_NV_DATA_BACKUP_MD5_PATH, - .nv_data_secret = XMM6260_NV_DATA_SECRET, - .nv_data_size = XMM6260_NV_DATA_SIZE, - .nv_data_chunk_size = XMM6260_NV_DATA_CHUNK_SIZE, -}; - -// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/piranha/piranha_ipc.h b/samsung-ipc/devices/piranha/piranha_ipc.h deleted file mode 100644 index 7cff520..0000000 --- a/samsung-ipc/devices/piranha/piranha_ipc.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2013 Paul Kocialkowski - * - * libsamsung-ipc 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 2 of the License, or - * (at your option) any later version. - * - * libsamsung-ipc 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 libsamsung-ipc. If not, see . - */ - -#ifndef __PIRANHA_IPC_H__ -#define __PIRANHA_IPC_H__ - -#define PIRANHA_MODEM_IMAGE_SIZE 0x1400000 -#define PIRANHA_PSI_OFFSET 0x1000 -#define PIRANHA_PSI_SIZE 0xE000 -#define PIRANHA_EBL_OFFSET 0xF000 -#define PIRANHA_EBL_SIZE 0x19000 -#define PIRANHA_SEC_START_OFFSET 0x9FF800 -#define PIRANHA_SEC_START_SIZE 0x800 -#define PIRANHA_FIRMWARE_OFFSET 0x28000 -#define PIRANHA_FIRMWARE_SIZE 0x9D7800 -#define PIRANHA_NV_DATA_OFFSET 0xA00000 -#define PIRANHA_NV_DATA_SIZE 0x200000 - -#define PIRANHA_MODEM_IMAGE_DEVICE "/dev/block/mmcblk0p8" - -struct piranha_ipc_transport_data { - int fd; -}; - -extern struct ipc_ops piranha_ipc_fmt_ops; -extern struct ipc_ops piranha_ipc_rfs_ops; -extern struct ipc_handlers piranha_ipc_handlers; -extern struct ipc_gprs_specs piranha_ipc_gprs_specs; -extern struct ipc_nv_data_specs piranha_ipc_nv_data_specs; -extern struct ipc_nv_data_specs piranha_ipc_nv_data_specs; - -#endif - -// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/devices/xmm6160/xmm6160.c b/samsung-ipc/devices/xmm6160/xmm6160.c index 2c4d64b..c0c5c35 100644 --- a/samsung-ipc/devices/xmm6160/xmm6160.c +++ b/samsung-ipc/devices/xmm6160/xmm6160.c @@ -1,7 +1,7 @@ /* * This file is part of libsamsung-ipc. * - * Copyright (C) 2011-2013 Paul Kocialkowski + * Copyright (C) 2011-2014 Paul Kocialkowski * * libsamsung-ipc is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,7 +30,7 @@ #include "xmm6160.h" int xmm6160_psi_send(struct ipc_client *client, int serial_fd, - void *psi_data, unsigned short psi_size) + const void *psi_data, unsigned short psi_size) { char at[] = XMM6160_AT; unsigned char version; @@ -38,17 +38,15 @@ int xmm6160_psi_send(struct ipc_client *client, int serial_fd, unsigned char psi_magic; unsigned char psi_crc; unsigned char psi_ack; - struct termios termios; struct timeval timeout; fd_set fds; - + size_t length; unsigned char *p; - int length; int rc; int i; - if (client == NULL || serial_fd < 0 || psi_data == NULL || psi_size <= 0) + if (client == NULL || serial_fd < 0 || psi_data == NULL || psi_size == 0) return -1; tcgetattr(serial_fd, &termios); @@ -62,7 +60,7 @@ int xmm6160_psi_send(struct ipc_client *client, int serial_fd, length = strlen(at); for (i = 0; i < XMM6160_AT_COUNT; i++) { rc = write(serial_fd, at, length); - if (rc < length) { + if (rc < (int) length) { ipc_client_log(client, "Writing AT in ASCII failed"); goto error; } @@ -185,15 +183,14 @@ complete: } int xmm6160_firmware_send(struct ipc_client *client, int device_fd, - void *device_address, void *firmware_data, int firmware_size) + void *device_address, const void *firmware_data, size_t firmware_size) { - int wc; - + size_t wc; unsigned char *p; int rc; int i; - if (client == NULL || (device_fd < 0 && device_address == NULL) || firmware_data == NULL || firmware_size <= 0) + if (client == NULL || (device_fd < 0 && device_address == NULL) || firmware_data == NULL || firmware_size == 0) return -1; p = (unsigned char *) firmware_data; @@ -204,7 +201,7 @@ int xmm6160_firmware_send(struct ipc_client *client, int device_fd, wc = 0; while (wc < firmware_size) { rc = write(device_fd, (void *) p, firmware_size - wc); - if (rc < 0) { + if (rc <= 0) { ipc_client_log(client, "Writing firmware failed"); goto error; } @@ -229,9 +226,8 @@ int xmm6160_nv_data_send(struct ipc_client *client, int device_fd, void *device_address) { void *nv_data = NULL; - int nv_size; - int wc; - + size_t nv_size; + size_t wc; unsigned char *p; int rc; @@ -239,6 +235,8 @@ int xmm6160_nv_data_send(struct ipc_client *client, int device_fd, return -1; nv_size = ipc_client_nv_data_size(client); + if (nv_size == 0) + return -1; nv_data = ipc_nv_data_load(client); if (nv_data == NULL) { @@ -255,7 +253,7 @@ int xmm6160_nv_data_send(struct ipc_client *client, int device_fd, wc = 0; while (wc < nv_size) { rc = write(device_fd, p, nv_size - wc); - if (rc < 0) { + if (rc <= 0) { ipc_client_log(client, "Writing modem image failed"); goto error; } diff --git a/samsung-ipc/devices/xmm6160/xmm6160.h b/samsung-ipc/devices/xmm6160/xmm6160.h index 14f337a..22ae2be 100644 --- a/samsung-ipc/devices/xmm6160/xmm6160.h +++ b/samsung-ipc/devices/xmm6160/xmm6160.h @@ -1,7 +1,7 @@ /* * This file is part of libsamsung-ipc. * - * Copyright (C) 2011-2013 Paul Kocialkowski + * Copyright (C) 2011-2014 Paul Kocialkowski * * libsamsung-ipc is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -37,9 +37,9 @@ #define XMM6160_NV_DATA_CHUNK_SIZE 0x1000 int xmm6160_psi_send(struct ipc_client *client, int serial_fd, - void *psi_data, unsigned short psi_size); + const void *psi_data, unsigned short psi_size); int xmm6160_firmware_send(struct ipc_client *client, int device_fd, - void *device_address, void *firmware_data, int firmware_size); + void *device_address, const void *firmware_data, size_t firmware_size); int xmm6160_nv_data_send(struct ipc_client *client, int device_fd, void *device_address); diff --git a/samsung-ipc/devices/xmm6260/xmm6260.c b/samsung-ipc/devices/xmm6260/xmm6260.c index 416f6c2..2711caf 100644 --- a/samsung-ipc/devices/xmm6260/xmm6260.c +++ b/samsung-ipc/devices/xmm6260/xmm6260.c @@ -2,7 +2,7 @@ * This file is part of libsamsung-ipc. * * Copyright (C) 2012 Alexander Tarasikov - * Copyright (C) 2013 Paul Kocialkowski + * Copyright (C) 2013-2014 Paul Kocialkowski * * libsamsung-ipc is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,18 +23,18 @@ #include "xmm6260.h" -unsigned char xmm6260_crc_calculate(void *buffer, int length) +unsigned char xmm6260_crc_calculate(const void *data, size_t size) { unsigned char crc; unsigned char *p; - if (buffer == NULL || length <= 0) + if (data == NULL || size == 0) return 0; - p = (unsigned char *) buffer; + p = (unsigned char *) data; crc = 0; - while (length--) + while (size--) crc ^= *p++; return crc; diff --git a/samsung-ipc/devices/xmm6260/xmm6260.h b/samsung-ipc/devices/xmm6260/xmm6260.h index c116ede..bc55a44 100644 --- a/samsung-ipc/devices/xmm6260/xmm6260.h +++ b/samsung-ipc/devices/xmm6260/xmm6260.h @@ -1,7 +1,7 @@ /* * This file is part of libsamsung-ipc. * - * Copyright (C) 2013 Paul Kocialkowski + * Copyright (C) 2013-2014 Paul Kocialkowski * * libsamsung-ipc is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -46,7 +46,7 @@ #define XMM6260_NV_DATA_SIZE 0x200000 #define XMM6260_NV_DATA_CHUNK_SIZE 0x1000 -unsigned char xmm6260_crc_calculate(void *buffer, int length); +unsigned char xmm6260_crc_calculate(const void *data, size_t size); #endif diff --git a/samsung-ipc/devices/xmm6260/xmm6260_hsic.c b/samsung-ipc/devices/xmm6260/xmm6260_hsic.c index 747ebd1..24b6567 100644 --- a/samsung-ipc/devices/xmm6260/xmm6260_hsic.c +++ b/samsung-ipc/devices/xmm6260/xmm6260_hsic.c @@ -2,7 +2,7 @@ * This file is part of libsamsung-ipc. * * Copyright (C) 2012 Alexander Tarasikov - * Copyright (C) 2013 Paul Kocialkowski + * Copyright (C) 2013-2014 Paul Kocialkowski * * Based on the incomplete C++ implementation which is: * Copyright (C) 2012 Sergey Gridasov @@ -37,7 +37,6 @@ int xmm6260_hsic_ack_read(int device_fd, unsigned short ack) { struct timeval timeout; fd_set fds; - unsigned short value; int rc; int i; @@ -66,20 +65,18 @@ int xmm6260_hsic_ack_read(int device_fd, unsigned short ack) } int xmm6260_hsic_psi_send(struct ipc_client *client, int device_fd, - void *psi_data, unsigned short psi_size) + const void *psi_data, unsigned short psi_size) { struct xmm6260_hsic_psi_header psi_header; char at[] = XMM6260_AT; unsigned char psi_ack; unsigned char chip_id; unsigned char psi_crc; - struct timeval timeout; fd_set fds; - int wc; - + size_t wc; + size_t length; unsigned char *p; - int length; int rc; int i; @@ -98,7 +95,7 @@ int xmm6260_hsic_psi_send(struct ipc_client *client, int device_fd, timeout.tv_usec = 100000; rc = write(device_fd, at, length); - if (rc < length) { + if (rc < (int) length) { ipc_client_log(client, "Writing ATAT in ASCII failed"); goto error; } @@ -129,7 +126,7 @@ int xmm6260_hsic_psi_send(struct ipc_client *client, int device_fd, psi_ack = 0; rc = read(device_fd, &psi_ack, sizeof(psi_ack)); - if (rc < 0 || psi_ack != XMM6260_HSIC_BOOT0_ACK) { + if (rc <= 0 || psi_ack != XMM6260_HSIC_BOOT0_ACK) { ipc_client_log(client, "Reading boot ACK failed"); goto error; } @@ -142,7 +139,7 @@ int xmm6260_hsic_psi_send(struct ipc_client *client, int device_fd, chip_id = 0; rc = read(device_fd, &chip_id, sizeof(chip_id)); - if (rc < 0) { + if (rc <= 0) { ipc_client_log(client, "Reading chip id failed"); goto error; } @@ -164,7 +161,7 @@ int xmm6260_hsic_psi_send(struct ipc_client *client, int device_fd, wc = 0; while (wc < psi_size) { rc = write(device_fd, (void *) p, psi_size - wc); - if (rc < 0) { + if (rc <= 0) { ipc_client_log(client, "Writing PSI failed"); goto error; } @@ -234,25 +231,23 @@ complete: } int xmm6260_hsic_ebl_send(struct ipc_client *client, int device_fd, - void *ebl_data, int ebl_size) + const void *ebl_data, size_t ebl_size) { unsigned char ebl_crc; - - int chunk; - int count; - int wc; - + size_t chunk; + size_t count; + size_t wc; + size_t size; unsigned char *p; - int length; int rc; - if (client == NULL || device_fd < 0 || ebl_data == NULL || ebl_size <= 0) + if (client == NULL || device_fd < 0 || ebl_data == NULL || ebl_size == 0) return -1; - length = sizeof(ebl_size); + size = sizeof(ebl_size); - rc = write(device_fd, &ebl_size, length); - if (rc < length) { + rc = write(device_fd, &ebl_size, size); + if (rc < (int) size) { ipc_client_log(client, "Writing EBL size failed"); goto error; } @@ -272,7 +267,7 @@ int xmm6260_hsic_ebl_send(struct ipc_client *client, int device_fd, count = chunk < ebl_size - wc ? chunk : ebl_size - wc; rc = write(device_fd, (void *) p, count); - if (rc < 0) { + if (rc <= 0) { ipc_client_log(client, "Writing EBL failed"); goto error; } @@ -309,20 +304,18 @@ complete: } int xmm6260_hsic_command_send(int device_fd, unsigned short code, - void *data, int size, int command_data_size, int ack) + const void *data, size_t size, size_t command_data_size, int ack) { struct xmm6260_hsic_command_header header; void *buffer = NULL; - int length; - + size_t length; struct timeval timeout; fd_set fds; - unsigned char *p; int rc; int i; - if (device_fd < 0 || data == NULL || size <= 0 || command_data_size < size) + if (device_fd < 0 || data == NULL || size == 0 || command_data_size == 0 || command_data_size < size) return -1; header.checksum = (size & 0xffff) + code; @@ -331,11 +324,11 @@ int xmm6260_hsic_command_send(int device_fd, unsigned short code, p = (unsigned char *) data; - for (i = 0; i < size; i++) + for (i = 0; i < (int) size; i++) header.checksum += *p++; length = command_data_size + sizeof(header); - buffer = malloc(length); + buffer = calloc(1, length); memset(buffer, 0, length); p = (unsigned char *) buffer; @@ -344,7 +337,7 @@ int xmm6260_hsic_command_send(int device_fd, unsigned short code, memcpy(p, data, size); rc = write(device_fd, buffer, length); - if (rc < length) + if (rc < (int) length) goto error; if (!ack) { @@ -373,7 +366,7 @@ int xmm6260_hsic_command_send(int device_fd, unsigned short code, goto error; rc = read(device_fd, buffer, command_data_size); - if (rc < command_data_size) + if (rc < (int) command_data_size) goto error; if (header.code != code) @@ -392,16 +385,16 @@ complete: return rc; } -int xmm6260_hsic_modem_data_send(int device_fd, void *data, int size, int address) +int xmm6260_hsic_modem_data_send(int device_fd, const void *data, size_t size, + int address) { - int chunk; - int count; - int c; - + size_t chunk; + size_t count; + size_t c; unsigned char *p; int rc; - if (device_fd < 0 || data == NULL || size <= 0) + if (device_fd < 0 || data == NULL || size == 0) return -1; rc = xmm6260_hsic_command_send(device_fd, XMM6260_COMMAND_FLASH_SET_ADDRESS, &address, sizeof(address), XMM6260_HSIC_FLASH_SET_ADDRESS_SIZE, 1); @@ -436,11 +429,9 @@ complete: int xmm6260_hsic_port_config_send(struct ipc_client *client, int device_fd) { void *buffer = NULL; - int length; - + size_t length; struct timeval timeout; fd_set fds; - int rc; if (client == NULL || device_fd < 0) @@ -457,14 +448,14 @@ int xmm6260_hsic_port_config_send(struct ipc_client *client, int device_fd) goto error; length = XMM6260_HSIC_PORT_CONFIG_SIZE; - buffer = malloc(length); + buffer = calloc(1, length); rc = select(device_fd + 1, &fds, NULL, NULL, &timeout); if (rc <= 0) goto error; rc = read(device_fd, buffer, length); - if (rc < length) { + if (rc < (int) length) { ipc_client_log(client, "Reading port config failed"); goto error; } @@ -490,11 +481,11 @@ complete: } int xmm6260_hsic_sec_start_send(struct ipc_client *client, int device_fd, - void *sec_data, int sec_size) + const void *sec_data, size_t sec_size) { int rc; - if (client == NULL || device_fd < 0 || sec_data == NULL || sec_size <= 0) + if (client == NULL || device_fd < 0 || sec_data == NULL || sec_size == 0) return -1; rc = xmm6260_hsic_command_send(device_fd, XMM6260_COMMAND_SEC_START, sec_data, sec_size, XMM6260_HSIC_SEC_START_SIZE, 1); @@ -507,7 +498,7 @@ int xmm6260_hsic_sec_start_send(struct ipc_client *client, int device_fd, int xmm6260_hsic_sec_end_send(struct ipc_client *client, int device_fd) { unsigned short sec_data; - int sec_size; + size_t sec_size; int rc; if (client == NULL || device_fd < 0) @@ -524,11 +515,11 @@ int xmm6260_hsic_sec_end_send(struct ipc_client *client, int device_fd) } int xmm6260_hsic_firmware_send(struct ipc_client *client, int device_fd, - void *firmware_data, int firmware_size) + const void *firmware_data, size_t firmware_size) { int rc; - if (client == NULL || device_fd < 0 || firmware_data == NULL || firmware_size <= 0) + if (client == NULL || device_fd < 0 || firmware_data == NULL || firmware_size == 0) return -1; rc = xmm6260_hsic_modem_data_send(device_fd, firmware_data, firmware_size, XMM6260_FIRMWARE_ADDRESS); @@ -541,13 +532,15 @@ int xmm6260_hsic_firmware_send(struct ipc_client *client, int device_fd, int xmm6260_hsic_nv_data_send(struct ipc_client *client, int device_fd) { void *nv_data = NULL; - int nv_size; + size_t nv_size; int rc; if (client == NULL || device_fd < 0) return -1; nv_size = ipc_client_nv_data_size(client); + if (nv_size == 0) + return -1; nv_data = ipc_nv_data_load(client); if (nv_data == NULL) { diff --git a/samsung-ipc/devices/xmm6260/xmm6260_hsic.h b/samsung-ipc/devices/xmm6260/xmm6260_hsic.h index 4e25bce..1728a4c 100644 --- a/samsung-ipc/devices/xmm6260/xmm6260_hsic.h +++ b/samsung-ipc/devices/xmm6260/xmm6260_hsic.h @@ -2,7 +2,7 @@ * This file is part of libsamsung-ipc. * * Copyright (C) 2012 Alexander Tarasikov - * Copyright (C) 2013 Paul Kocialkowski + * Copyright (C) 2013-2014 Paul Kocialkowski * * libsamsung-ipc is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -51,16 +51,16 @@ struct xmm6260_hsic_command_header { } __attribute__((packed)); int xmm6260_hsic_psi_send(struct ipc_client *client, int device_fd, - void *psi_data, unsigned short psi_size); + const void *psi_data, unsigned short psi_size); int xmm6260_hsic_ebl_send(struct ipc_client *client, int device_fd, - void *ebl_data, int ebl_size); + const void *ebl_data, size_t ebl_size); int xmm6260_hsic_port_config_send(struct ipc_client *client, int device_fd); int xmm6260_hsic_sec_start_send(struct ipc_client *client, int device_fd, - void *sec_data, int sec_size); + const void *sec_data, size_t sec_size); int xmm6260_hsic_sec_end_send(struct ipc_client *client, int device_fd); int xmm6260_hsic_firmware_send(struct ipc_client *client, int device_fd, - void *firmware_data, int firmware_size); + const void *firmware_data, size_t firmware_size); int xmm6260_hsic_nv_data_send(struct ipc_client *client, int device_fd); int xmm6260_hsic_hw_reset_send(struct ipc_client *client, int device_fd); diff --git a/samsung-ipc/devices/xmm6260/xmm6260_mipi.c b/samsung-ipc/devices/xmm6260/xmm6260_mipi.c index a14fd20..dd2a560 100644 --- a/samsung-ipc/devices/xmm6260/xmm6260_mipi.c +++ b/samsung-ipc/devices/xmm6260/xmm6260_mipi.c @@ -2,7 +2,7 @@ * This file is part of libsamsung-ipc. * * Copyright (C) 2012 Alexander Tarasikov - * Copyright (C) 2013 Paul Kocialkowski + * Copyright (C) 2013-2014 Paul Kocialkowski * * Based on the incomplete C++ implementation which is: * Copyright (C) 2012 Sergey Gridasov @@ -33,12 +33,12 @@ #include "xmm6260.h" #include "xmm6260_mipi.h" -int xmm6260_mipi_crc_calculate(void *buffer, int length) +int xmm6260_mipi_crc_calculate(const void *data, size_t size) { unsigned char crc; int mipi_crc; - crc = xmm6260_crc_calculate(buffer, length); + crc = xmm6260_crc_calculate(data, size); mipi_crc = (crc << 24) | 0xffffff; return mipi_crc; @@ -48,7 +48,6 @@ int xmm6260_mipi_ack_read(int device_fd, unsigned short ack) { struct timeval timeout; fd_set fds; - unsigned int value; int rc; int i; @@ -77,18 +76,16 @@ int xmm6260_mipi_ack_read(int device_fd, unsigned short ack) } int xmm6260_mipi_psi_send(struct ipc_client *client, int device_fd, - void *psi_data, unsigned short psi_size) + const void *psi_data, unsigned short psi_size) { struct xmm6260_mipi_psi_header psi_header; char at[] = XMM6260_AT; int psi_crc; - struct timeval timeout; fd_set fds; - int wc; - + size_t wc; + size_t length; unsigned char *p; - int length; int rc; int i; @@ -107,7 +104,7 @@ int xmm6260_mipi_psi_send(struct ipc_client *client, int device_fd, timeout.tv_usec = 100000; rc = write(device_fd, at, length); - if (rc < length) { + if (rc < (int) length) { ipc_client_log(client, "Writing ATAT in ASCII failed"); goto error; } @@ -147,7 +144,7 @@ int xmm6260_mipi_psi_send(struct ipc_client *client, int device_fd, wc = 0; while (wc < psi_size) { rc = write(device_fd, (void *) p, psi_size - wc); - if (rc < 0) { + if (rc <= 0) { ipc_client_log(client, "Writing PSI failed"); goto error; } @@ -184,20 +181,19 @@ complete: } int xmm6260_mipi_ebl_send(struct ipc_client *client, int device_fd, - void *ebl_data, int ebl_size) + const void *ebl_data, size_t ebl_size) { unsigned short boot_magic[4]; unsigned char ebl_crc; - - int chunk; - int count; - int wc; - + size_t chunk; + size_t count; + size_t wc; + size_t size; + size_t length; unsigned char *p; - int length; int rc; - if (client == NULL || device_fd < 0 || ebl_data == NULL || ebl_size <= 0) + if (client == NULL || device_fd < 0 || ebl_data == NULL || ebl_size == 0) return -1; boot_magic[0] = 0; @@ -214,7 +210,7 @@ int xmm6260_mipi_ebl_send(struct ipc_client *client, int device_fd, } rc = write(device_fd, &boot_magic, length); - if (rc < length) { + if (rc < (int) length) { ipc_client_log(client, "Writing boot magic failed"); goto error; } @@ -226,16 +222,16 @@ int xmm6260_mipi_ebl_send(struct ipc_client *client, int device_fd, goto error; } - length = sizeof(ebl_size); + size = sizeof(ebl_size); - rc = write(device_fd, &length, sizeof(length)); - if (rc < (int) sizeof(length)) { + rc = write(device_fd, &size, sizeof(size)); + if (rc < (int) sizeof(size)) { ipc_client_log(client, "Writing EBL size length failed"); goto error; } - rc = write(device_fd, &ebl_size, length); - if (rc < length) { + rc = write(device_fd, &ebl_size, size); + if (rc < (int) size) { ipc_client_log(client, "Writing EBL size failed"); goto error; } @@ -249,8 +245,8 @@ int xmm6260_mipi_ebl_send(struct ipc_client *client, int device_fd, ebl_size++; - rc = write(device_fd, &ebl_size, length); - if (rc < length) { + rc = write(device_fd, &ebl_size, size); + if (rc < (int) size) { ipc_client_log(client, "Writing EBL size failed"); goto error; } @@ -265,7 +261,7 @@ int xmm6260_mipi_ebl_send(struct ipc_client *client, int device_fd, count = chunk < ebl_size - wc ? chunk : ebl_size - wc; rc = write(device_fd, (void *) p, count); - if (rc < 0) { + if (rc <= 0) { ipc_client_log(client, "Writing EBL failed"); goto error; } @@ -302,19 +298,17 @@ complete: } int xmm6260_mipi_command_send(int device_fd, unsigned short code, - void *data, int size, int ack, int short_footer) + const void *data, size_t size, int ack, int short_footer) { struct xmm6260_mipi_command_header header; struct xmm6260_mipi_command_footer footer; - int footer_size; void *buffer = NULL; - int length; - + size_t length; + size_t footer_length; struct timeval timeout; fd_set fds; - int chunk; - int c; - + size_t chunk; + size_t c; unsigned char *p; int rc; int i; @@ -333,25 +327,25 @@ int xmm6260_mipi_command_send(int device_fd, unsigned short code, p = (unsigned char *) data; - for (i = 0; i < size; i++) + for (i = 0; i < (int) size; i++) footer.checksum += *p++; - footer_size = sizeof(footer); + footer_length = sizeof(footer); if (short_footer) - footer_size -= sizeof(short); + footer_length -= sizeof(short); - length = sizeof(header) + size + footer_size; - buffer = malloc(length); + length = sizeof(header) + size + footer_length; + buffer = calloc(1, length); p = (unsigned char *) buffer; memcpy(p, &header, sizeof(header)); p += sizeof(header); memcpy(p, data, size); p += size; - memcpy(p, &footer, footer_size); + memcpy(p, &footer, footer_length); rc = write(device_fd, buffer, length); - if (rc < length) + if (rc < (int) length) goto error; free(buffer); @@ -383,7 +377,7 @@ int xmm6260_mipi_command_send(int device_fd, unsigned short code, if (length < (int) sizeof(buffer)) goto error; - buffer = malloc(length); + buffer = calloc(1, length); p = (unsigned char *) buffer; memcpy(p, &length, sizeof(length)); @@ -397,7 +391,7 @@ int xmm6260_mipi_command_send(int device_fd, unsigned short code, goto error; rc = read(device_fd, (void *) p, chunk); - if (rc < chunk) + if (rc < (int) chunk) goto error; p += rc; @@ -421,16 +415,16 @@ complete: return rc; } -int xmm6260_mipi_modem_data_send(int device_fd, void *data, int size, int address) +int xmm6260_mipi_modem_data_send(int device_fd, const void *data, size_t size, + int address) { - int chunk; - int count; - int c; - + size_t chunk; + size_t count; + size_t c; unsigned char *p; int rc; - if (device_fd < 0 || data == NULL || size <= 0) + if (device_fd < 0 || data == NULL || size == 0) return -1; rc = xmm6260_mipi_command_send(device_fd, XMM6260_COMMAND_FLASH_SET_ADDRESS, &address, sizeof(address), 1, 0); @@ -465,14 +459,12 @@ complete: int xmm6260_mipi_port_config_send(struct ipc_client *client, int device_fd) { void *buffer = NULL; - int length; - + size_t length; struct timeval timeout; fd_set fds; - int chunk; - int count; - int c; - + size_t chunk; + size_t count; + size_t c; unsigned char *p; int rc; @@ -490,13 +482,13 @@ int xmm6260_mipi_port_config_send(struct ipc_client *client, int device_fd) goto error; rc = read(device_fd, &length, sizeof(length)); - if (rc < (int) sizeof(length) || length <= 0) { + if (rc < (int) sizeof(length) || length == 0) { ipc_client_log(client, "Reading port config length failed"); goto error; } ipc_client_log(client, "Read port config length (0x%x)", length); - buffer = malloc(length); + buffer = calloc(1, length); p = (unsigned char *) buffer; @@ -510,7 +502,7 @@ int xmm6260_mipi_port_config_send(struct ipc_client *client, int device_fd) goto error; rc = read(device_fd, p, count); - if (rc < count) { + if (rc < (int) count) { ipc_client_log(client, "Reading port config failed"); goto error; } @@ -540,11 +532,11 @@ complete: } int xmm6260_mipi_sec_start_send(struct ipc_client *client, int device_fd, - void *sec_data, int sec_size) + const void *sec_data, size_t sec_size) { int rc; - if (client == NULL || device_fd < 0 || sec_data == NULL || sec_size <= 0) + if (client == NULL || device_fd < 0 || sec_data == NULL || sec_size == 0) return -1; rc = xmm6260_mipi_command_send(device_fd, XMM6260_COMMAND_SEC_START, sec_data, sec_size, 1, 0); @@ -557,7 +549,7 @@ int xmm6260_mipi_sec_start_send(struct ipc_client *client, int device_fd, int xmm6260_mipi_sec_end_send(struct ipc_client *client, int device_fd) { unsigned short sec_data; - int sec_size; + size_t sec_size; int rc; if (client == NULL || device_fd < 0) @@ -574,11 +566,11 @@ int xmm6260_mipi_sec_end_send(struct ipc_client *client, int device_fd) } int xmm6260_mipi_firmware_send(struct ipc_client *client, int device_fd, - void *firmware_data, int firmware_size) + const void *firmware_data, size_t firmware_size) { int rc; - if (client == NULL || device_fd < 0 || firmware_data == NULL || firmware_size <= 0) + if (client == NULL || device_fd < 0 || firmware_data == NULL || firmware_size == 0) return -1; rc = xmm6260_mipi_modem_data_send(device_fd, firmware_data, firmware_size, XMM6260_FIRMWARE_ADDRESS); @@ -591,13 +583,15 @@ int xmm6260_mipi_firmware_send(struct ipc_client *client, int device_fd, int xmm6260_mipi_nv_data_send(struct ipc_client *client, int device_fd) { void *nv_data = NULL; - int nv_size; + size_t nv_size; int rc; if (client == NULL || device_fd < 0) return -1; nv_size = ipc_client_nv_data_size(client); + if (nv_size == 0) + return -1; nv_data = ipc_nv_data_load(client); if (nv_data == NULL) { @@ -624,11 +618,11 @@ complete: } int xmm6260_mipi_mps_data_send(struct ipc_client *client, int device_fd, - void *mps_data, int mps_size) + const void *mps_data, size_t mps_size) { int rc; - if (client == NULL || device_fd < 0 || mps_data == NULL || mps_size <= 0) + if (client == NULL || device_fd < 0 || mps_data == NULL || mps_size == 0) return -1; rc = xmm6260_mipi_modem_data_send(device_fd, mps_data, mps_size, XMM6260_MPS_DATA_ADDRESS); @@ -641,7 +635,7 @@ int xmm6260_mipi_mps_data_send(struct ipc_client *client, int device_fd, int xmm6260_mipi_hw_reset_send(struct ipc_client *client, int device_fd) { unsigned int hw_reset_data; - int hw_reset_size; + size_t hw_reset_size; int rc; if (client == NULL || device_fd < 0) diff --git a/samsung-ipc/devices/xmm6260/xmm6260_mipi.h b/samsung-ipc/devices/xmm6260/xmm6260_mipi.h index 4c9d7d2..4744369 100644 --- a/samsung-ipc/devices/xmm6260/xmm6260_mipi.h +++ b/samsung-ipc/devices/xmm6260/xmm6260_mipi.h @@ -2,7 +2,7 @@ * This file is part of libsamsung-ipc. * * Copyright (C) 2012 Alexander Tarasikov - * Copyright (C) 2013 Paul Kocialkowski + * Copyright (C) 2013-2014 Paul Kocialkowski * * libsamsung-ipc is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -53,19 +53,19 @@ struct xmm6260_mipi_command_footer { } __attribute__((packed)); int xmm6260_mipi_psi_send(struct ipc_client *client, int device_fd, - void *psi_data, unsigned short psi_size); + const void *psi_data, unsigned short psi_size); int xmm6260_mipi_ebl_send(struct ipc_client *client, int device_fd, - void *ebl_data, int ebl_size); + const void *ebl_data, size_t ebl_size); int xmm6260_mipi_port_config_send(struct ipc_client *client, int device_fd); int xmm6260_mipi_sec_start_send(struct ipc_client *client, int device_fd, - void *sec_data, int sec_size); + const void *sec_data, size_t sec_size); int xmm6260_mipi_sec_end_send(struct ipc_client *client, int device_fd); int xmm6260_mipi_firmware_send(struct ipc_client *client, int device_fd, - void *firmware_data, int firmware_size); + const void *firmware_data, size_t firmware_size); int xmm6260_mipi_nv_data_send(struct ipc_client *client, int device_fd); int xmm6260_mipi_mps_data_send(struct ipc_client *client, int device_fd, - void *mps_data, int mps_size); + const void *mps_data, size_t mps_size); int xmm6260_mipi_hw_reset_send(struct ipc_client *client, int device_fd); #endif diff --git a/samsung-ipc/devices/xmm6260/xmm6260_sec_modem.c b/samsung-ipc/devices/xmm6260/xmm6260_sec_modem.c index e7b89b3..06731a7 100644 --- a/samsung-ipc/devices/xmm6260/xmm6260_sec_modem.c +++ b/samsung-ipc/devices/xmm6260/xmm6260_sec_modem.c @@ -2,7 +2,7 @@ * This file is part of libsamsung-ipc. * * Copyright (C) 2012 Alexander Tarasikov - * Copyright (C) 2013 Paul Kocialkowski + * Copyright (C) 2013-2014 Paul Kocialkowski * * libsamsung-ipc is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -171,34 +171,37 @@ int xmm6260_sec_modem_link_get_hostwake_wait(int device_fd) return -1; } -int xmm6260_sec_modem_ipc_fmt_send(struct ipc_client *client, struct ipc_message_info *request) +int xmm6260_sec_modem_fmt_send(struct ipc_client *client, + struct ipc_message *message) { struct ipc_fmt_header header; void *buffer; + size_t length; + size_t count; unsigned char *p; - int count; int rc; - if (client == NULL || client->handlers == NULL || client->handlers->write == NULL || request == NULL) + if (client == NULL || client->handlers == NULL || client->handlers->write == NULL || message == NULL) return -1; - ipc_fmt_header_fill(&header, request); + ipc_fmt_header_setup(&header, message); - buffer = malloc(header.length); + length = header.length; + buffer = calloc(1, length); memcpy(buffer, &header, sizeof(struct ipc_fmt_header)); - if (request->data != NULL && request->length > 0) - memcpy((void *) ((unsigned char *) buffer + sizeof(struct ipc_fmt_header)), request->data, request->length); + if (message->data != NULL && message->size > 0) + memcpy((void *) ((unsigned char *) buffer + sizeof(struct ipc_fmt_header)), message->data, message->size); - ipc_client_log_send(client, request, __func__); + ipc_client_log_send(client, message, __func__); p = (unsigned char *) buffer; count = 0; - while (count < header.length) { - rc = client->handlers->write(client->handlers->transport_data, p, header.length - count); + while (count < length) { + rc = client->handlers->write(client->handlers->transport_data, p, length - count); if (rc <= 0) { - ipc_client_log(client, "Writing FMT data to the modem failed"); + ipc_client_log(client, "Writing FMT data failed"); goto error; } @@ -219,36 +222,37 @@ complete: return rc; } -int xmm6260_sec_modem_ipc_fmt_recv(struct ipc_client *client, struct ipc_message_info *response) +int xmm6260_sec_modem_fmt_recv(struct ipc_client *client, + struct ipc_message *message) { struct ipc_fmt_header *header; void *buffer = NULL; + size_t length; + size_t count; unsigned char *p; - int length; - int count; int rc; - if (client == NULL || client->handlers == NULL || client->handlers->read == NULL || response == NULL) + if (client == NULL || client->handlers == NULL || client->handlers->read == NULL || message == NULL) return -1; length = XMM6260_DATA_SIZE; - buffer = malloc(length); + buffer = calloc(1, length); rc = client->handlers->read(client->handlers->transport_data, buffer, length); if (rc < (int) sizeof(struct ipc_fmt_header)) { - ipc_client_log(client, "Reading FMT header from the modem failed"); + ipc_client_log(client, "Reading FMT header failed"); goto error; } header = (struct ipc_fmt_header *) buffer; - ipc_fmt_message_fill(header, response); + ipc_fmt_message_setup(header, message); if (header->length > sizeof(struct ipc_fmt_header)) { - response->length = header->length - sizeof(struct ipc_fmt_header); - response->data = malloc(response->length); + message->size = header->length - sizeof(struct ipc_fmt_header); + message->data = calloc(1, message->size); - p = (unsigned char *) response->data; + p = (unsigned char *) message->data; count = rc - sizeof(struct ipc_fmt_header); if (count > 0) { @@ -256,10 +260,10 @@ int xmm6260_sec_modem_ipc_fmt_recv(struct ipc_client *client, struct ipc_message p += count; } - while (count < (int) response->length) { - rc = client->handlers->read(client->handlers->transport_data, p, response->length - count); + while (count < message->size) { + rc = client->handlers->read(client->handlers->transport_data, p, message->size - count); if (rc <= 0) { - ipc_client_log(client, "Reading FMT data from the modem failed"); + ipc_client_log(client, "Reading FMT data failed"); goto error; } @@ -268,7 +272,7 @@ int xmm6260_sec_modem_ipc_fmt_recv(struct ipc_client *client, struct ipc_message } } - ipc_client_log_recv(client, response, __func__); + ipc_client_log_recv(client, message, __func__); rc = 0; goto complete; @@ -283,35 +287,37 @@ complete: return rc; } -int xmm6260_sec_modem_ipc_rfs_send(struct ipc_client *client, struct ipc_message_info *request) +int xmm6260_sec_modem_rfs_send(struct ipc_client *client, + struct ipc_message *message) { struct ipc_rfs_header header; void *buffer; + size_t length; + size_t count; unsigned char *p; - int count; int rc; - - if (client == NULL || client->handlers == NULL || client->handlers->write == NULL || request == NULL) + if (client == NULL || client->handlers == NULL || client->handlers->write == NULL || message == NULL) return -1; - ipc_rfs_header_fill(&header, request); + ipc_rfs_header_setup(&header, message); - buffer = malloc(header.length); + length = header.length; + buffer = calloc(1, length); memcpy(buffer, &header, sizeof(struct ipc_rfs_header)); - if (request->data != NULL && request->length > 0) - memcpy((void *) ((unsigned char *) buffer + sizeof(struct ipc_rfs_header)), request->data, request->length); + if (message->data != NULL && message->size > 0) + memcpy((void *) ((unsigned char *) buffer + sizeof(struct ipc_rfs_header)), message->data, message->size); - ipc_client_log_send(client, request, __func__); + ipc_client_log_send(client, message, __func__); p = (unsigned char *) buffer; count = 0; - while (count < (int) header.length) { - rc = client->handlers->write(client->handlers->transport_data, p, header.length - count); + while (count < length) { + rc = client->handlers->write(client->handlers->transport_data, p, length - count); if (rc <= 0) { - ipc_client_log(client, "Writing RFS data to the modem failed"); + ipc_client_log(client, "Writing RFS data failed"); goto error; } @@ -332,36 +338,37 @@ complete: return rc; } -int xmm6260_sec_modem_ipc_rfs_recv(struct ipc_client *client, struct ipc_message_info *response) +int xmm6260_sec_modem_rfs_recv(struct ipc_client *client, + struct ipc_message *message) { struct ipc_rfs_header *header; void *buffer = NULL; + size_t length; + size_t count; unsigned char *p; - int length; - int count; int rc; - if (client == NULL || client->handlers == NULL || client->handlers->read == NULL || response == NULL) + if (client == NULL || client->handlers == NULL || client->handlers->read == NULL || message == NULL) return -1; length = XMM6260_DATA_SIZE; - buffer = malloc(length); + buffer = calloc(1, length); rc = client->handlers->read(client->handlers->transport_data, buffer, length); if (rc < (int) sizeof(struct ipc_rfs_header)) { - ipc_client_log(client, "Reading RFS header from the modem failed"); + ipc_client_log(client, "Reading RFS header failed"); goto error; } header = (struct ipc_rfs_header *) buffer; - ipc_rfs_message_fill(header, response); + ipc_rfs_message_setup(header, message); if (header->length > sizeof(struct ipc_rfs_header)) { - response->length = header->length - sizeof(struct ipc_rfs_header); - response->data = malloc(response->length); + message->size = header->length - sizeof(struct ipc_rfs_header); + message->data = calloc(1, message->size); - p = (unsigned char *) response->data; + p = (unsigned char *) message->data; count = rc - sizeof(struct ipc_rfs_header); if (count > 0) { @@ -369,10 +376,10 @@ int xmm6260_sec_modem_ipc_rfs_recv(struct ipc_client *client, struct ipc_message p += count; } - while (count < (int) response->length) { - rc = client->handlers->read(client->handlers->transport_data, p, response->length - count); + while (count < message->size) { + rc = client->handlers->read(client->handlers->transport_data, p, message->size - count); if (rc <= 0) { - ipc_client_log(client, "Reading RFS data from the modem failed"); + ipc_client_log(client, "Reading RFS data failed"); goto error; } @@ -381,7 +388,7 @@ int xmm6260_sec_modem_ipc_rfs_recv(struct ipc_client *client, struct ipc_message } } - ipc_client_log_recv(client, response, __func__); + ipc_client_log_recv(client, message, __func__); rc = 0; goto complete; @@ -396,7 +403,7 @@ complete: return rc; } -int xmm6260_sec_modem_ipc_open(int type) +int xmm6260_sec_modem_open(int type) { int fd; @@ -414,7 +421,7 @@ int xmm6260_sec_modem_ipc_open(int type) return fd; } -int xmm6260_sec_modem_ipc_close(int fd) +int xmm6260_sec_modem_close(int fd) { if (fd < 0) return -1; @@ -424,7 +431,7 @@ int xmm6260_sec_modem_ipc_close(int fd) return 0; } -int xmm6260_sec_modem_ipc_read(int fd, void *buffer, unsigned int length) +int xmm6260_sec_modem_read(int fd, void *buffer, size_t length) { int rc; @@ -432,10 +439,11 @@ int xmm6260_sec_modem_ipc_read(int fd, void *buffer, unsigned int length) return -1; rc = read(fd, buffer, length); + return rc; } -int xmm6260_sec_modem_ipc_write(int fd, void *buffer, unsigned int length) +int xmm6260_sec_modem_write(int fd, const void *buffer, size_t length) { int rc; @@ -443,10 +451,11 @@ int xmm6260_sec_modem_ipc_write(int fd, void *buffer, unsigned int length) return -1; rc = write(fd, buffer, length); + return rc; } -int xmm6260_sec_modem_ipc_poll(int fd, struct timeval *timeout) +int xmm6260_sec_modem_poll(int fd, struct timeval *timeout) { fd_set fds; int rc; @@ -468,7 +477,7 @@ int xmm6260_sec_modem_ipc_poll(int fd, struct timeval *timeout) return rc; } -char *xmm6260_sec_modem_ipc_gprs_get_iface(int cid) +char *xmm6260_sec_modem_gprs_get_iface(int cid) { char *iface = NULL; @@ -480,13 +489,12 @@ char *xmm6260_sec_modem_ipc_gprs_get_iface(int cid) return iface; } -int xmm6260_sec_modem_ipc_gprs_get_capabilities(struct ipc_client_gprs_capabilities *capabilities) +int xmm6260_sec_modem_gprs_get_capabilities(struct ipc_client_gprs_capabilities *capabilities) { if (capabilities == NULL) return -1; - capabilities->port_list = 0; - capabilities->cid_max = XMM6260_SEC_MODEM_GPRS_IFACE_COUNT; + capabilities->cid_count = XMM6260_SEC_MODEM_GPRS_IFACE_COUNT; return 0; } diff --git a/samsung-ipc/devices/xmm6260/xmm6260_sec_modem.h b/samsung-ipc/devices/xmm6260/xmm6260_sec_modem.h index 8895fbb..d1c6fe6 100644 --- a/samsung-ipc/devices/xmm6260/xmm6260_sec_modem.h +++ b/samsung-ipc/devices/xmm6260/xmm6260_sec_modem.h @@ -1,7 +1,7 @@ /* * This file is part of libsamsung-ipc. * - * Copyright (C) 2013 Paul Kocialkowski + * Copyright (C) 2013-2014 Paul Kocialkowski * * libsamsung-ipc is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -40,19 +40,23 @@ int xmm6260_sec_modem_link_control_active(int device_fd, int active); int xmm6260_sec_modem_link_connected_wait(int device_fd); int xmm6260_sec_modem_link_get_hostwake_wait(int device_fd); -int xmm6260_sec_modem_ipc_fmt_send(struct ipc_client *client, struct ipc_message_info *request); -int xmm6260_sec_modem_ipc_fmt_recv(struct ipc_client *client, struct ipc_message_info *response); -int xmm6260_sec_modem_ipc_rfs_send(struct ipc_client *client, struct ipc_message_info *request); -int xmm6260_sec_modem_ipc_rfs_recv(struct ipc_client *client, struct ipc_message_info *response); - -int xmm6260_sec_modem_ipc_open(int type); -int xmm6260_sec_modem_ipc_close(int fd); -int xmm6260_sec_modem_ipc_read(int fd, void *buffer, unsigned int length); -int xmm6260_sec_modem_ipc_write(int fd, void *buffer, unsigned int length); -int xmm6260_sec_modem_ipc_poll(int fd, struct timeval *timeout); - -char *xmm6260_sec_modem_ipc_gprs_get_iface(int cid); -int xmm6260_sec_modem_ipc_gprs_get_capabilities(struct ipc_client_gprs_capabilities *capabilities); +int xmm6260_sec_modem_fmt_send(struct ipc_client *client, + struct ipc_message *message); +int xmm6260_sec_modem_fmt_recv(struct ipc_client *client, + struct ipc_message *message); +int xmm6260_sec_modem_rfs_send(struct ipc_client *client, + struct ipc_message *message); +int xmm6260_sec_modem_rfs_recv(struct ipc_client *client, + struct ipc_message *message); + +int xmm6260_sec_modem_open(int type); +int xmm6260_sec_modem_close(int fd); +int xmm6260_sec_modem_read(int fd, void *buffer, size_t length); +int xmm6260_sec_modem_write(int fd, const void *buffer, size_t length); +int xmm6260_sec_modem_poll(int fd, struct timeval *timeout); + +char *xmm6260_sec_modem_gprs_get_iface(int cid); +int xmm6260_sec_modem_gprs_get_capabilities(struct ipc_client_gprs_capabilities *capabilities); #endif diff --git a/samsung-ipc/ipc.c b/samsung-ipc/ipc.c index 86f4291..a8cacf0 100644 --- a/samsung-ipc/ipc.c +++ b/samsung-ipc/ipc.c @@ -3,7 +3,7 @@ * * Copyright (C) 2010-2011 Joerie de Gram * Copyright (C) 2011 Simon Busch - * Copyright (C) 2013 Paul Kocialkowsk + * Copyright (C) 2013-2014 Paul Kocialkowsk * * libsamsung-ipc is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -51,7 +51,7 @@ int ipc_device_detect(void) char *line, *p, *c; int index = -1; int fd = -1; - int length; + size_t length; int rc; int i; @@ -68,8 +68,7 @@ int ipc_device_detect(void) if (fd < 0) goto error; - length = sizeof(buffer); - length = read(fd, &buffer, length); + length = read(fd, &buffer, sizeof(buffer)); close(fd); fd = -1; @@ -145,26 +144,22 @@ complete: return index; } -struct ipc_client *ipc_client_create(int client_type) +struct ipc_client *ipc_client_create(int type) { - struct ipc_client *client; - int device_index = -1; + struct ipc_client *client = NULL; + int device_index; - device_index = ipc_device_detect(); - - if (device_index < 0 || device_index > ipc_devices_count) - return NULL; - - if (client_type < 0 || client_type > IPC_CLIENT_TYPE_RFS) + if (type < 0 || type > IPC_CLIENT_TYPE_RFS) return NULL; - client = (struct ipc_client *) malloc(sizeof(struct ipc_client)); - memset(client, 0, sizeof(struct ipc_client)); + device_index = ipc_device_detect(); + if (device_index < 0 || device_index > ipc_devices_count) + goto error; - client->type = client_type; + client = (struct ipc_client *) calloc(1, sizeof(struct ipc_client)); + client->type = type; - switch (client_type) - { + switch (type) { case IPC_CLIENT_TYPE_RFS: client->ops = ipc_devices[device_index].rfs_ops; break; @@ -172,19 +167,27 @@ struct ipc_client *ipc_client_create(int client_type) client->ops = ipc_devices[device_index].fmt_ops; break; default: - return NULL; + goto error; } client->gprs_specs = ipc_devices[device_index].gprs_specs; client->nv_data_specs = ipc_devices[device_index].nv_data_specs; - // Handlers are subject to be modified - client->handlers = (struct ipc_handlers *) malloc(sizeof(struct ipc_handlers)); - memset(client->handlers, 0, sizeof(struct ipc_handlers)); + // Handlers can be modified + client->handlers = (struct ipc_client_handlers *) calloc(1, sizeof(struct ipc_client_handlers)); - if (ipc_devices[device_index].handlers != 0) - memcpy(client->handlers, ipc_devices[device_index].handlers, sizeof(struct ipc_handlers)); + if (ipc_devices[device_index].handlers != NULL) + memcpy(client->handlers, ipc_devices[device_index].handlers, sizeof(struct ipc_client_handlers)); + goto complete; + +error: + if (client != NULL) { + free(client); + client = NULL; + } + +complete: return client; } @@ -202,37 +205,11 @@ int ipc_client_destroy(struct ipc_client *client) return 0; } -void ipc_client_log(struct ipc_client *client, const char *message, ...) -{ - char buffer[4096]; - va_list args; - - if (client == NULL || client->log_callback == NULL || message == NULL) - return; - - va_start(args, message); - vsnprintf(buffer, 4096, message, args); - client->log_callback(client->log_data, buffer); - va_end(args); -} - -int ipc_client_set_log_callback(struct ipc_client *client, - void (*log_callback)(void *log_data, const char *message), void *log_data) -{ - if (client == NULL) - return -1; - - client->log_callback = log_callback; - client->log_data = log_data; - - return 0; -} - -int ipc_client_set_transport_handlers(struct ipc_client *client, +int ipc_client_transport_handlers_register(struct ipc_client *client, int (*open)(void *transport_data, int type), int (*close)(void *transport_data), - int (*read)(void *transport_data, void *buffer, unsigned int length), - int (*write)(void *transport_data, void *buffer, unsigned int length), + int (*read)(void *transport_data, void *data, size_t size), + int (*write)(void *transport_data, const void *data, size_t size), int (*poll)(void *transport_data, struct timeval *timeout), void *transport_data) { @@ -255,9 +232,8 @@ int ipc_client_set_transport_handlers(struct ipc_client *client, return 0; } -int ipc_client_set_power_handlers(struct ipc_client *client, - int (*power_on)(void *power_data), - int (*power_off)(void *power_data), +int ipc_client_power_handlers_register(struct ipc_client *client, + int (*power_on)(void *power_data), int (*power_off)(void *power_data), void *power_data) { if (client == NULL || client->handlers == NULL) @@ -273,10 +249,9 @@ int ipc_client_set_power_handlers(struct ipc_client *client, return 0; } -int ipc_client_set_gprs_handlers(struct ipc_client *client, +int ipc_client_gprs_handlers_register(struct ipc_client *client, int (*gprs_activate)(void *gprs_data, int cid), - int (*gprs_deactivate)(void *gprs_data, int cid), - void *gprs_data) + int (*gprs_deactivate)(void *gprs_data, int cid), void *gprs_data) { if (client == NULL || client->handlers == NULL) return -1; @@ -291,61 +266,70 @@ int ipc_client_set_gprs_handlers(struct ipc_client *client, return 0; } -int ipc_client_bootstrap(struct ipc_client *client) +void ipc_client_log(struct ipc_client *client, const char *message, ...) { - if (client == NULL || client->ops == NULL || - client->ops->bootstrap == NULL) - return -1; + char buffer[4096]; + va_list args; + + if (client == NULL || client->log_callback == NULL || message == NULL) + return; - return client->ops->bootstrap(client); + va_start(args, message); + vsnprintf((char *) &buffer, sizeof(buffer), message, args); + client->log_callback(client->log_data, buffer); + va_end(args); } -int ipc_client_send(struct ipc_client *client, const unsigned short command, - const char type, unsigned char *data, const int length, unsigned char mseq) +int ipc_client_log_callback_register(struct ipc_client *client, + void (*log_callback)(void *log_data, const char *message), void *log_data) { - struct ipc_message_info request; - - if (client == NULL || client->ops == NULL || client->ops->send == NULL) + if (client == NULL) return -1; - request.mseq = mseq; - request.aseq = 0xff; - request.group = IPC_GROUP(command); - request.index = IPC_INDEX(command); - request.type = type; - request.length = length; - request.data = data; + client->log_callback = log_callback; + client->log_data = log_data; - return client->ops->send(client, &request); + return 0; } -int ipc_client_recv(struct ipc_client *client, - struct ipc_message_info *response) +int ipc_client_boot(struct ipc_client *client) { - if (client == NULL || client->ops == NULL || client->ops->recv == NULL) + if (client == NULL || client->ops == NULL || client->ops->boot == NULL) return -1; - return client->ops->recv(client, response); + return client->ops->boot(client); } -void ipc_client_response_free(struct ipc_client *client, - struct ipc_message_info *response) +int ipc_client_send(struct ipc_client *client, unsigned char mseq, + unsigned short command, unsigned char type, const void *data, size_t size) { - if (response == NULL) - return; + struct ipc_message message; - if (response->data != NULL && response->length > 0) { - free(response->data); - response->data = NULL; - } + if (client == NULL || client->ops == NULL || client->ops->send == NULL) + return -1; + + memset(&message, 0, sizeof(message)); + message.mseq = mseq; + message.aseq = 0xff; + message.command = command; + message.type = type; + message.data = (void *) data; + message.size = size; + + return client->ops->send(client, &message); +} + +int ipc_client_recv(struct ipc_client *client, struct ipc_message *message) +{ + if (client == NULL || client->ops == NULL || client->ops->recv == NULL || message == NULL) + return -1; - memset(response, 0, sizeof(struct ipc_message_info)); + return client->ops->recv(client, message); } int ipc_client_open(struct ipc_client *client) { - if (client == NULL || client->handlers == NULL || - client->handlers->open == NULL) + if (client == NULL || client->handlers == NULL || client->handlers->open == NULL) return -1; return client->handlers->open(client->handlers->transport_data, client->type); @@ -353,8 +337,7 @@ int ipc_client_open(struct ipc_client *client) int ipc_client_close(struct ipc_client *client) { - if (client == NULL || client->handlers == NULL || - client->handlers->close == NULL) + if (client == NULL || client->handlers == NULL || client->handlers->close == NULL) return -1; return client->handlers->close(client->handlers->transport_data); @@ -362,8 +345,7 @@ int ipc_client_close(struct ipc_client *client) int ipc_client_poll(struct ipc_client *client, struct timeval *timeout) { - if (client == NULL || client->handlers == NULL || - client->handlers->poll == NULL) + if (client == NULL || client->handlers == NULL || client->handlers->poll == NULL) return -1; return client->handlers->poll(client->handlers->transport_data, timeout); @@ -371,8 +353,7 @@ int ipc_client_poll(struct ipc_client *client, struct timeval *timeout) int ipc_client_power_on(struct ipc_client *client) { - if (client == NULL || client->handlers == NULL || - client->handlers->power_on == NULL) + if (client == NULL || client->handlers == NULL || client->handlers->power_on == NULL) return -1; return client->handlers->power_on(client->handlers->power_data); @@ -380,8 +361,7 @@ int ipc_client_power_on(struct ipc_client *client) int ipc_client_power_off(struct ipc_client *client) { - if (client == NULL || client->handlers == NULL || - client->handlers->power_off == NULL) + if (client == NULL || client->handlers == NULL || client->handlers->power_off == NULL) return -1; return client->handlers->power_off(client->handlers->power_data); @@ -389,8 +369,7 @@ int ipc_client_power_off(struct ipc_client *client) int ipc_client_gprs_activate(struct ipc_client *client, int cid) { - if (client == NULL || client->handlers == NULL || - client->handlers->gprs_activate == NULL) + if (client == NULL || client->handlers == NULL || client->handlers->gprs_activate == NULL) return -1; return client->handlers->gprs_activate(client->handlers->gprs_data, cid); @@ -398,8 +377,7 @@ int ipc_client_gprs_activate(struct ipc_client *client, int cid) int ipc_client_gprs_deactivate(struct ipc_client *client, int cid) { - if (client == NULL || client->handlers == NULL || - client->handlers->gprs_deactivate == NULL) + if (client == NULL || client->handlers == NULL || client->handlers->gprs_deactivate == NULL) return -1; return client->handlers->gprs_deactivate(client->handlers->gprs_data, cid); @@ -407,28 +385,23 @@ int ipc_client_gprs_deactivate(struct ipc_client *client, int cid) int ipc_client_data_create(struct ipc_client *client) { - if (client == NULL || client->handlers == NULL || - client->handlers->data_create == NULL) + if (client == NULL || client->handlers == NULL || client->handlers->data_create == NULL) return -1; - return client->handlers->data_create(&client->handlers->transport_data, - &client->handlers->power_data, &client->handlers->power_data); + return client->handlers->data_create(&client->handlers->transport_data, &client->handlers->power_data, &client->handlers->power_data); } int ipc_client_data_destroy(struct ipc_client *client) { - if (client == NULL || client->handlers == NULL || - client->handlers->data_destroy == NULL) + if (client == NULL || client->handlers == NULL || client->handlers->data_destroy == NULL) return -1; - return client->handlers->data_destroy(client->handlers->transport_data, - client->handlers->power_data, client->handlers->power_data); + return client->handlers->data_destroy(client->handlers->transport_data, client->handlers->power_data, client->handlers->power_data); } char *ipc_client_gprs_get_iface(struct ipc_client *client, int cid) { - if (client == NULL || client->gprs_specs == NULL || - client->gprs_specs->gprs_get_iface == NULL) + if (client == NULL || client->gprs_specs == NULL || client->gprs_specs->gprs_get_iface == NULL) return NULL; return client->gprs_specs->gprs_get_iface(cid); @@ -437,8 +410,7 @@ char *ipc_client_gprs_get_iface(struct ipc_client *client, int cid) int ipc_client_gprs_get_capabilities(struct ipc_client *client, struct ipc_client_gprs_capabilities *capabilities) { - if (client == NULL || client->gprs_specs == NULL || - client->gprs_specs->gprs_get_capabilities == NULL) + if (client == NULL || client->gprs_specs == NULL || client->gprs_specs->gprs_get_capabilities == NULL) return -1; return client->gprs_specs->gprs_get_capabilities(capabilities); @@ -446,9 +418,7 @@ int ipc_client_gprs_get_capabilities(struct ipc_client *client, char *ipc_client_nv_data_path(struct ipc_client *client) { - if (client == NULL || - client->nv_data_specs == NULL || - client->nv_data_specs->nv_data_path == NULL) + if (client == NULL || client->nv_data_specs == NULL || client->nv_data_specs->nv_data_path == NULL) return NULL; return client->nv_data_specs->nv_data_path; @@ -456,9 +426,7 @@ char *ipc_client_nv_data_path(struct ipc_client *client) char *ipc_client_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) + if (client == NULL || client->nv_data_specs == NULL || client->nv_data_specs->nv_data_md5_path == NULL) return NULL; return client->nv_data_specs->nv_data_md5_path; @@ -466,9 +434,7 @@ char *ipc_client_nv_data_md5_path(struct ipc_client *client) char *ipc_client_nv_data_backup_path(struct ipc_client *client) { - if (client == NULL || - client->nv_data_specs == NULL || - client->nv_data_specs->nv_data_backup_path == NULL) + if (client == NULL || client->nv_data_specs == NULL || client->nv_data_specs->nv_data_backup_path == NULL) return NULL; return client->nv_data_specs->nv_data_backup_path; @@ -476,9 +442,7 @@ char *ipc_client_nv_data_backup_path(struct ipc_client *client) char *ipc_client_nv_data_backup_md5_path(struct ipc_client *client) { - if (client == NULL || - client->nv_data_specs == NULL || - client->nv_data_specs->nv_data_backup_md5_path == NULL) + if (client == NULL || client->nv_data_specs == NULL || client->nv_data_specs->nv_data_backup_md5_path == NULL) return NULL; return client->nv_data_specs->nv_data_backup_md5_path; @@ -486,9 +450,7 @@ char *ipc_client_nv_data_backup_md5_path(struct ipc_client *client) char *ipc_client_nv_data_secret(struct ipc_client *client) { - if (client == NULL || - client->nv_data_specs == NULL || - client->nv_data_specs->nv_data_secret == NULL) + if (client == NULL || client->nv_data_specs == NULL || client->nv_data_specs->nv_data_secret == NULL) return NULL; return client->nv_data_specs->nv_data_secret; @@ -496,9 +458,7 @@ char *ipc_client_nv_data_secret(struct ipc_client *client) size_t ipc_client_nv_data_size(struct ipc_client *client) { - if (client == NULL || - client->nv_data_specs == NULL || - client->nv_data_specs->nv_data_size == 0) + if (client == NULL || client->nv_data_specs == NULL || client->nv_data_specs->nv_data_size == 0) return 0; return client->nv_data_specs->nv_data_size; @@ -506,9 +466,7 @@ size_t ipc_client_nv_data_size(struct ipc_client *client) size_t ipc_client_nv_data_chunk_size(struct ipc_client *client) { - if (client == NULL || - client->nv_data_specs == NULL || - client->nv_data_specs->nv_data_chunk_size == 0) + if (client == NULL || client->nv_data_specs == NULL || client->nv_data_specs->nv_data_chunk_size == 0) return 0; return client->nv_data_specs->nv_data_chunk_size; diff --git a/samsung-ipc/ipc.h b/samsung-ipc/ipc.h index 5870cdd..b50303e 100644 --- a/samsung-ipc/ipc.h +++ b/samsung-ipc/ipc.h @@ -2,6 +2,7 @@ * This file is part of libsamsung-ipc. * * Copyright (C) 2011 Simon Busch + * Copyright (C) 2014 Paul Kocialkowski * * libsamsung-ipc is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -29,19 +30,19 @@ * Structures */ -struct ipc_ops { - int (*bootstrap)(struct ipc_client *client); - int (*send)(struct ipc_client *client, struct ipc_message_info *); - int (*recv)(struct ipc_client *client, struct ipc_message_info *); +struct ipc_client_ops { + int (*boot)(struct ipc_client *client); + int (*send)(struct ipc_client *client, struct ipc_message *message); + int (*recv)(struct ipc_client *client, struct ipc_message *message); }; -struct ipc_handlers { +struct ipc_client_handlers { /* Transport handlers */ int (*open)(void *transport_data, int type); int (*close)(void *transport_data); - int (*read)(void *transport_data, void *buffer, unsigned int length); - int (*write)(void *transport_data, void *buffer, unsigned int length); + int (*read)(void *transport_data, void *buffer, size_t length); + int (*write)(void *transport_data, const void *buffer, size_t length); int (*poll)(void *transport_data, struct timeval *timeout); void *transport_data; @@ -63,12 +64,12 @@ struct ipc_handlers { int (*data_destroy)(void *transport_data, void *power_data, void *gprs_data); }; -struct ipc_gprs_specs { +struct ipc_client_gprs_specs { char *(*gprs_get_iface)(int cid); int (*gprs_get_capabilities)(struct ipc_client_gprs_capabilities *capabilities); }; -struct ipc_nv_data_specs { +struct ipc_client_nv_data_specs { char *nv_data_path; char *nv_data_md5_path; char *nv_data_backup_path; @@ -84,10 +85,10 @@ struct ipc_client { void (*log_callback)(void *log_data, const char *message); void *log_data; - struct ipc_ops *ops; - struct ipc_handlers *handlers; - struct ipc_gprs_specs *gprs_specs; - struct ipc_nv_data_specs *nv_data_specs; + struct ipc_client_ops *ops; + struct ipc_client_handlers *handlers; + struct ipc_client_gprs_specs *gprs_specs; + struct ipc_client_nv_data_specs *nv_data_specs; }; /* diff --git a/samsung-ipc/ipc_devices.c b/samsung-ipc/ipc_devices.c index dec61c2..ee97f77 100644 --- a/samsung-ipc/ipc_devices.c +++ b/samsung-ipc/ipc_devices.c @@ -28,111 +28,111 @@ struct ipc_device_desc ipc_devices[] = { .name = "crespo", .board_name = "herring", .kernel_version = "2.6.35", - .fmt_ops = &crespo_ipc_fmt_ops, - .rfs_ops = &crespo_ipc_rfs_ops, - .handlers = &crespo_ipc_handlers, - .gprs_specs = &crespo_ipc_gprs_specs_single, - .nv_data_specs = &crespo_ipc_nv_data_specs, + .fmt_ops = &crespo_fmt_ops, + .rfs_ops = &crespo_rfs_ops, + .handlers = &crespo_handlers, + .gprs_specs = &crespo_gprs_specs_single, + .nv_data_specs = &crespo_nv_data_specs, }, { .name = "crespo", .board_name = "herring", .kernel_version = "3.0", - .fmt_ops = &crespo_ipc_fmt_ops, - .rfs_ops = &crespo_ipc_rfs_ops, - .handlers = &crespo_ipc_handlers, - .gprs_specs = &crespo_ipc_gprs_specs, - .nv_data_specs = &crespo_ipc_nv_data_specs, + .fmt_ops = &crespo_fmt_ops, + .rfs_ops = &crespo_rfs_ops, + .handlers = &crespo_handlers, + .gprs_specs = &crespo_gprs_specs, + .nv_data_specs = &crespo_nv_data_specs, }, { .name = "aries", .board_name = "aries", .kernel_version = NULL, - .fmt_ops = &aries_ipc_fmt_ops, - .rfs_ops = &aries_ipc_rfs_ops, - .handlers = &aries_ipc_handlers, - .gprs_specs = &aries_ipc_gprs_specs, - .nv_data_specs = &aries_ipc_nv_data_specs, + .fmt_ops = &aries_fmt_ops, + .rfs_ops = &aries_rfs_ops, + .handlers = &aries_handlers, + .gprs_specs = &aries_gprs_specs, + .nv_data_specs = &aries_nv_data_specs, }, { .name = "aries", .board_name = "gt-p1000", .kernel_version = NULL, - .fmt_ops = &aries_ipc_fmt_ops, - .rfs_ops = &aries_ipc_rfs_ops, - .handlers = &aries_ipc_handlers, - .gprs_specs = &aries_ipc_gprs_specs, - .nv_data_specs = &aries_ipc_nv_data_specs, + .fmt_ops = &aries_fmt_ops, + .rfs_ops = &aries_rfs_ops, + .handlers = &aries_handlers, + .gprs_specs = &aries_gprs_specs, + .nv_data_specs = &aries_nv_data_specs, }, { .name = "galaxys2", .board_name = "smdk4210", .kernel_version = NULL, - .fmt_ops = &galaxys2_ipc_fmt_ops, - .rfs_ops = &galaxys2_ipc_rfs_ops, - .handlers = &galaxys2_ipc_handlers, - .gprs_specs = &galaxys2_ipc_gprs_specs, - .nv_data_specs = &galaxys2_ipc_nv_data_specs, + .fmt_ops = &galaxys2_fmt_ops, + .rfs_ops = &galaxys2_rfs_ops, + .handlers = &galaxys2_handlers, + .gprs_specs = &galaxys2_gprs_specs, + .nv_data_specs = &galaxys2_nv_data_specs, }, { .name = "galaxys2", .board_name = "i9100", .kernel_version = NULL, - .fmt_ops = &galaxys2_ipc_fmt_ops, - .rfs_ops = &galaxys2_ipc_rfs_ops, - .handlers = &galaxys2_ipc_handlers, - .gprs_specs = &galaxys2_ipc_gprs_specs, - .nv_data_specs = &galaxys2_ipc_nv_data_specs, + .fmt_ops = &galaxys2_fmt_ops, + .rfs_ops = &galaxys2_rfs_ops, + .handlers = &galaxys2_handlers, + .gprs_specs = &galaxys2_gprs_specs, + .nv_data_specs = &galaxys2_nv_data_specs, }, { .name = "maguro", .board_name = "tuna", .kernel_version = NULL, - .fmt_ops = &maguro_ipc_fmt_ops, - .rfs_ops = &maguro_ipc_rfs_ops, - .handlers = &maguro_ipc_handlers, - .gprs_specs = &maguro_ipc_gprs_specs, - .nv_data_specs = &maguro_ipc_nv_data_specs, + .fmt_ops = &maguro_fmt_ops, + .rfs_ops = &maguro_rfs_ops, + .handlers = &maguro_handlers, + .gprs_specs = &maguro_gprs_specs, + .nv_data_specs = &maguro_nv_data_specs, }, { .name = "piranha", .board_name = "espresso10", .kernel_version = NULL, - .fmt_ops = &piranha_ipc_fmt_ops, - .rfs_ops = &piranha_ipc_rfs_ops, - .handlers = &piranha_ipc_handlers, - .gprs_specs = &piranha_ipc_gprs_specs, - .nv_data_specs = &piranha_ipc_nv_data_specs, + .fmt_ops = &piranha_fmt_ops, + .rfs_ops = &piranha_rfs_ops, + .handlers = &piranha_handlers, + .gprs_specs = &piranha_gprs_specs, + .nv_data_specs = &piranha_nv_data_specs, }, { .name = "piranha", .board_name = "espresso", .kernel_version = NULL, - .fmt_ops = &piranha_ipc_fmt_ops, - .rfs_ops = &piranha_ipc_rfs_ops, - .handlers = &piranha_ipc_handlers, - .gprs_specs = &piranha_ipc_gprs_specs, - .nv_data_specs = &piranha_ipc_nv_data_specs, + .fmt_ops = &piranha_fmt_ops, + .rfs_ops = &piranha_rfs_ops, + .handlers = &piranha_handlers, + .gprs_specs = &piranha_gprs_specs, + .nv_data_specs = &piranha_nv_data_specs, }, { .name = "i9300", .board_name = "smdk4x12", .kernel_version = NULL, - .fmt_ops = &i9300_ipc_fmt_ops, - .rfs_ops = &i9300_ipc_rfs_ops, - .handlers = &i9300_ipc_handlers, - .gprs_specs = &i9300_ipc_gprs_specs, - .nv_data_specs = &i9300_ipc_nv_data_specs, + .fmt_ops = &i9300_fmt_ops, + .rfs_ops = &i9300_rfs_ops, + .handlers = &i9300_handlers, + .gprs_specs = &i9300_gprs_specs, + .nv_data_specs = &i9300_nv_data_specs, }, { .name = "n7100", .board_name = "smdk4x12", .kernel_version = NULL, - .fmt_ops = &n7100_ipc_fmt_ops, - .rfs_ops = &n7100_ipc_rfs_ops, - .handlers = &n7100_ipc_handlers, - .gprs_specs = &n7100_ipc_gprs_specs, - .nv_data_specs = &n7100_ipc_nv_data_specs, + .fmt_ops = &n7100_fmt_ops, + .rfs_ops = &n7100_rfs_ops, + .handlers = &n7100_handlers, + .gprs_specs = &n7100_gprs_specs, + .nv_data_specs = &n7100_nv_data_specs, }, }; diff --git a/samsung-ipc/ipc_devices.h b/samsung-ipc/ipc_devices.h index b93de60..36058c9 100644 --- a/samsung-ipc/ipc_devices.h +++ b/samsung-ipc/ipc_devices.h @@ -20,13 +20,13 @@ #include -#include "devices/crespo/crespo_ipc.h" -#include "devices/aries/aries_ipc.h" -#include "devices/galaxys2/galaxys2_ipc.h" -#include "devices/maguro/maguro_ipc.h" -#include "devices/piranha/piranha_ipc.h" -#include "devices/i9300/i9300_ipc.h" -#include "devices/n7100/n7100_ipc.h" +#include "devices/crespo/crespo.h" +#include "devices/aries/aries.h" +#include "devices/galaxys2/galaxys2.h" +#include "devices/maguro/maguro.h" +#include "devices/piranha/piranha.h" +#include "devices/i9300/i9300.h" +#include "devices/n7100/n7100.h" #ifndef __IPC_DEVICES_H__ #define __IPC_DEVICES_H__ @@ -36,11 +36,11 @@ struct ipc_device_desc { char *board_name; char *kernel_version; - struct ipc_ops *fmt_ops; - struct ipc_ops *rfs_ops; - struct ipc_handlers *handlers; - struct ipc_gprs_specs *gprs_specs; - struct ipc_nv_data_specs *nv_data_specs; + struct ipc_client_ops *fmt_ops; + struct ipc_client_ops *rfs_ops; + struct ipc_client_handlers *handlers; + struct ipc_client_gprs_specs *gprs_specs; + struct ipc_client_nv_data_specs *nv_data_specs; }; extern struct ipc_device_desc ipc_devices[]; diff --git a/samsung-ipc/ipc_util.c b/samsung-ipc/ipc_util.c deleted file mode 100644 index 3cbb5af..0000000 --- a/samsung-ipc/ipc_util.c +++ /dev/null @@ -1,516 +0,0 @@ -/* - * This file is part of libsamsung-ipc. - * - * Copyright (C) 2010-2011 Joerie de Gram - * Copyright (C) 2013 Paul Kocialkowski - * - * libsamsung-ipc 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 2 of the License, or - * (at your option) any later version. - * - * libsamsung-ipc 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 libsamsung-ipc. If not, see . - */ - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include "ipc.h" - -/* Log utils */ -const char *ipc_response_type_to_str(int type) -{ - switch (type) { - case IPC_TYPE_INDI: - return "INDI"; - case IPC_TYPE_RESP: - return "RESP"; - case IPC_TYPE_NOTI: - return "NOTI"; - default: - return "UNKNOWN"; - } -} - -const char *ipc_request_type_to_str(int type) -{ - switch (type) { - case IPC_TYPE_EXEC: - return "EXEC"; - case IPC_TYPE_GET: - return "GET"; - case IPC_TYPE_SET: - return "SET"; - case IPC_TYPE_CFRM: - return "CFRM"; - case IPC_TYPE_EVENT: - return "EVENT"; - default: - return "UNKNOWN"; - } -} - -const char *ipc_command_to_str(int command) -{ - switch (command) { - case IPC_PWR_PHONE_PWR_UP: - return "IPC_PWR_PHONE_PWR_UP"; - case IPC_PWR_PHONE_PWR_OFF: - return "IPC_PWR_PHONE_PWR_OFF"; - case IPC_PWR_PHONE_RESET: - return "IPC_PWR_PHONE_RESET"; - case IPC_PWR_BATT_STATUS: - return "IPC_PWR_BATT_STATUS"; - case IPC_PWR_BATT_TYPE: - return "IPC_PWR_BATT_TYPE"; - case IPC_PWR_BATT_COMP: - return "IPC_PWR_BATT_COMP"; - case IPC_PWR_PHONE_STATE: - return "IPC_PWR_PHONE_STATE"; - case IPC_CALL_OUTGOING: - return "IPC_CALL_OUTGOING"; - case IPC_CALL_INCOMING: - return "IPC_CALL_INCOMING"; - case IPC_CALL_RELEASE: - return "IPC_CALL_RELEASE"; - case IPC_CALL_ANSWER: - return "IPC_CALL_ANSWER"; - case IPC_CALL_STATUS: - return "IPC_CALL_STATUS"; - case IPC_CALL_LIST: - return "IPC_CALL_LIST"; - case IPC_CALL_BURST_DTMF: - return "IPC_CALL_BURST_DTMF"; - case IPC_CALL_CONT_DTMF: - return "IPC_CALL_CONT_DTMF"; - case IPC_CALL_WAITING: - return "IPC_CALL_WAITING"; - case IPC_CALL_LINE_ID: - return "IPC_CALL_LINE_ID"; - case IPC_SMS_SEND_MSG: - return "IPC_SMS_SEND_MSG"; - case IPC_SMS_INCOMING_MSG: - return "IPC_SMS_INCOMING_MSG"; - case IPC_SMS_READ_MSG: - return "IPC_SMS_READ_MSG"; - case IPC_SMS_SAVE_MSG: - return "IPC_SMS_SAVE_MSG"; - case IPC_SMS_DEL_MSG: - return "IPC_SMS_DEL_MSG"; - case IPC_SMS_DELIVER_REPORT: - return "IPC_SMS_DELIVER_REPORT"; - case IPC_SMS_DEVICE_READY: - return "IPC_SMS_DEVICE_READY"; - case IPC_SMS_SEL_MEM: - return "IPC_SMS_SEL_MEM"; - case IPC_SMS_STORED_MSG_COUNT: - return "IPC_SMS_STORED_MSG_COUNT"; - case IPC_SMS_SVC_CENTER_ADDR: - return "IPC_SMS_SVC_CENTER_ADDR"; - case IPC_SMS_SVC_OPTION: - return "IPC_SMS_SVC_OPTION"; - case IPC_SMS_MEM_STATUS: - return "IPC_SMS_MEM_STATUS"; - case IPC_SMS_CBS_MSG: - return "IPC_SMS_CBS_MSG"; - case IPC_SMS_CBS_CFG: - return "IPC_SMS_CBS_CFG"; - case IPC_SMS_STORED_MSG_STATUS: - return "IPC_SMS_STORED_MSG_STATUS"; - case IPC_SMS_PARAM_COUNT: - return "IPC_SMS_PARAM_COUNT"; - case IPC_SMS_PARAM: - return "IPC_SMS_PARAM"; - case IPC_SEC_PIN_STATUS: - return "IPC_SEC_PIN_STATUS"; - case IPC_SEC_PHONE_LOCK: - return "IPC_SEC_PHONE_LOCK"; - case IPC_SEC_CHANGE_LOCKING_PW: - return "IPC_SEC_CHANGE_LOCKING_PW"; - case IPC_SEC_SIM_LANG: - return "IPC_SEC_SIM_LANG"; - case IPC_SEC_RSIM_ACCESS: - return "IPC_SEC_RSIM_ACCESS"; - case IPC_SEC_GSIM_ACCESS: - return "IPC_SEC_GSIM_ACCESS"; - case IPC_SEC_SIM_ICC_TYPE: - return "IPC_SEC_SIM_ICC_TYPE"; - case IPC_SEC_LOCK_INFOMATION: - return "IPC_SEC_LOCK_INFOMATION"; - case IPC_SEC_IMS_AUTH: - return "IPC_SEC_IMS_AUTH"; - case IPC_PB_ACCESS: - return "IPC_PB_ACCESS"; - case IPC_PB_STORAGE: - return "IPC_PB_STORAGE"; - case IPC_PB_STORAGE_LIST: - return "IPC_PB_STORAGE_LIST"; - case IPC_PB_ENTRY_INFO: - return "IPC_PB_ENTRY_INFO"; - case IPC_PB_3GPB_CAPA: - return "IPC_PB_3GPB_CAPA"; - case IPC_DISP_ICON_INFO: - return "IPC_DISP_ICON_INFO"; - case IPC_DISP_HOMEZONE_INFO: - return "IPC_DISP_HOMEZONE_INFO"; - case IPC_DISP_RSSI_INFO: - return "IPC_DISP_RSSI_INFO"; - case IPC_NET_PREF_PLMN: - return "IPC_NET_PREF_PLMN"; - case IPC_NET_PLMN_SEL: - return "IPC_NET_PLMN_SEL"; - case IPC_NET_SERVING_NETWORK: - return "IPC_NET_SERVING_NETWORK"; - case IPC_NET_PLMN_LIST: - return "IPC_NET_PLMN_LIST"; - case IPC_NET_REGIST: - return "IPC_NET_REGIST"; - case IPC_NET_SUBSCRIBER_NUM: - return "IPC_NET_SUBSCRIBER_NUM"; - case IPC_NET_BAND_SEL: - return "IPC_NET_BAND_SEL"; - case IPC_NET_SERVICE_DOMAIN_CONFIG: - return "IPC_NET_SERVICE_DOMAIN_CONFIG"; - case IPC_NET_POWERON_ATTACH: - return "IPC_NET_POWERON_ATTACH"; - case IPC_NET_MODE_SEL: - return "IPC_NET_MODE_SEL"; - case IPC_NET_ACQ_ORDER: - return "IPC_NET_ACQ_ORDER"; - case IPC_NET_IDENTITY: - return "IPC_NET_IDENTITY"; - case IPC_NET_PREFERRED_NETWORK_INFO: - return "IPC_NET_PREFERRED_NETWORK_INFO"; - case IPC_SND_SPKR_VOLUME_CTRL: - return "IPC_SND_SPKR_VOLUME_CTRL"; - case IPC_SND_MIC_MUTE_CTRL: - return "IPC_SND_MIC_MUTE_CTRL"; - case IPC_SND_AUDIO_PATH_CTRL: - return "IPC_SND_AUDIO_PATH_CTRL"; - case IPC_SND_AUDIO_SOURCE_CTRL: - return "IPC_SND_AUDIO_SOURCE_CTRL"; - case IPC_SND_LOOPBACK_CTRL: - return "IPC_SND_LOOPBACK_CTRL"; - case IPC_SND_VOICE_RECORDING_CTRL: - return "IPC_SND_VOICE_RECORDING_CTRL"; - case IPC_SND_VIDEO_CALL_CTRL: - return "IPC_SND_VIDEO_CALL_CTRL"; - case IPC_SND_RINGBACK_TONE_CTRL: - return "IPC_SND_RINGBACK_TONE_CTRL"; - case IPC_SND_CLOCK_CTRL: - return "IPC_SND_CLOCK_CTRL"; - case IPC_SND_WB_AMR_STATUS: - return "IPC_SND_WB_AMR_STATUS"; - case IPC_MISC_ME_VERSION: - return "IPC_MISC_ME_VERSION"; - case IPC_MISC_ME_IMSI: - return "IPC_MISC_ME_IMSI"; - case IPC_MISC_ME_SN: - return "IPC_MISC_ME_SN"; - case IPC_MISC_TIME_INFO: - return "IPC_MISC_TIME_INFO"; - case IPC_MISC_DEBUG_LEVEL: - return "IPC_MISC_DEBUG_LEVEL"; - case IPC_SVC_ENTER: - return "IPC_SVC_ENTER"; - case IPC_SVC_END: - return "IPC_SVC_END"; - case IPC_SVC_PRO_KEYCODE: - return "IPC_SVC_PRO_KEYCODE"; - case IPC_SVC_SCREEN_CFG: - return "IPC_SVC_SCREEN_CFG"; - case IPC_SVC_DISPLAY_SCREEN: - return "IPC_SVC_DISPLAY_SCREEN"; - case IPC_SVC_CHANGE_SVC_MODE: - return "IPC_SVC_CHANGE_SVC_MODE"; - case IPC_SVC_DEVICE_TEST: - return "IPC_SVC_DEVICE_TEST"; - case IPC_SVC_DEBUG_DUMP: - return "IPC_SVC_DEBUG_DUMP"; - case IPC_SVC_DEBUG_STRING: - return "IPC_SVC_DEBUG_STRING"; - case IPC_SS_WAITING: - return "IPC_SS_WAITING"; - case IPC_SS_CLI: - return "IPC_SS_CLI"; - case IPC_SS_BARRING: - return "IPC_SS_BARRING"; - case IPC_SS_BARRING_PW: - return "IPC_SS_BARRING_PW"; - case IPC_SS_FORWARDING: - return "IPC_SS_FORWARDING"; - case IPC_SS_INFO: - return "IPC_SS_INFO"; - case IPC_SS_MANAGE_CALL: - return "IPC_SS_MANAGE_CALL"; - case IPC_SS_USSD: - return "IPC_SS_USSD"; - case IPC_SS_AOC: - return "IPC_SS_AOC"; - case IPC_SS_RELEASE_COMPLETE: - return "IPC_SS_RELEASE_COMPLETE"; - case IPC_GPRS_DEFINE_PDP_CONTEXT: - return "IPC_GPRS_DEFINE_PDP_CONTEXT"; - case IPC_GPRS_QOS: - return "IPC_GPRS_QOS"; - case IPC_GPRS_PS: - return "IPC_GPRS_PS"; - case IPC_GPRS_PDP_CONTEXT: - return "IPC_GPRS_PDP_CONTEXT"; - case IPC_GPRS_ENTER_DATA: - return "IPC_GPRS_ENTER_DATA"; - case IPC_GPRS_SHOW_PDP_ADDR: - return "IPC_GPRS_SHOW_PDP_ADDR"; - case IPC_GPRS_MS_CLASS: - return "IPC_GPRS_MS_CLASS"; - case IPC_GPRS_3G_QUAL_SRVC_PROFILE: - return "IPC_GPRS_3G_QUAL_SRVC_PROFILE"; - case IPC_GPRS_IP_CONFIGURATION: - return "IPC_GPRS_IP_CONFIGURATION"; - case IPC_GPRS_DEFINE_SEC_PDP_CONTEXT: - return "IPC_GPRS_DEFINE_SEC_PDP_CONTEXT"; - case IPC_GPRS_TFT: - return "IPC_GPRS_TFT"; - case IPC_GPRS_HSDPA_STATUS: - return "IPC_GPRS_HSDPA_STATUS"; - case IPC_GPRS_CURRENT_SESSION_DATA_COUNTER: - return "IPC_GPRS_CURRENT_SESSION_DATA_COUNTER"; - case IPC_GPRS_DATA_DORMANT: - return "IPC_GPRS_DATA_DORMANT"; - case IPC_GPRS_PIN_CTRL: - return "IPC_GPRS_PIN_CTRL"; - case IPC_GPRS_CALL_STATUS: - return "IPC_GPRS_CALL_STATUS"; - case IPC_GPRS_PORT_LIST: - return "IPC_GPRS_PORT_LIST"; - case IPC_SAT_PROFILE_DOWNLOAD: - return "IPC_SAT_PROFILE_DOWNLOAD"; - case IPC_SAT_ENVELOPE_CMD: - return "IPC_SAT_ENVELOPE_CMD"; - case IPC_SAT_PROACTIVE_CMD: - return "IPC_SAT_PROACTIVE_CMD"; - case IPC_SAT_TERMINATE_USAT_SESSION: - return "IPC_SAT_TERMINATE_USAT_SESSION"; - case IPC_SAT_EVENT_DOWNLOAD: - return "IPC_SAT_EVENT_DOWNLOAD"; - case IPC_SAT_PROVIDE_LOCAL_INFO: - return "IPC_SAT_PROVIDE_LOCAL_INFO"; - case IPC_SAT_POLLING: - return "IPC_SAT_POLLING"; - case IPC_SAT_REFRESH: - return "IPC_SAT_REFRESH"; - case IPC_SAT_SETUP_EVENT_LIST: - return "IPC_SAT_SETUP_EVENT_LIST"; - case IPC_SAT_CALL_CONTROL_RESULT: - return "IPC_SAT_CALL_CONTROL_RESULT"; - case IPC_SAT_IMAGE_CLUT: - return "IPC_SAT_IMAGE_CLUT"; - case IPC_SAT_SETUP_CALL_PROCESSING: - return "IPC_SAT_SETUP_CALL_PROCESSING"; - case IPC_IMEI_START: - return "IPC_IMEI_START"; - case IPC_IMEI_CHECK_DEVICE_INFO: - return "IPC_IMEI_CHECK_DEVICE_INFO"; - case IPC_RFS_NV_READ_ITEM: - return "IPC_RFS_NV_READ_ITEM"; - case IPC_RFS_NV_WRITE_ITEM: - return "IPC_RFS_NV_WRITE_ITEM"; - case IPC_GEN_PHONE_RES: - return "IPC_GEN_PHONE_RES"; - default: - return "UNKNOWN"; - } -} - -void ipc_client_hex_dump(struct ipc_client *client, void *data, int size) -{ - /* dumps size bytes of *data to stdout. Looks like: - * [0000] 75 6E 6B 6E 6F 77 6E 20 - * 30 FF 00 00 00 00 39 00 unknown 0.....9. - * (in a single line of course) - */ - - unsigned char *p = data; - unsigned char c; - int n; - char bytestr[4] = {0}; - char addrstr[10] = {0}; - char hexstr[ 16*3 + 5] = {0}; - char charstr[16*1 + 5] = {0}; - for (n=1;n<=size;n++) { - if (n%16 == 1) { - /* store address for this line */ - unsigned int end = 0, start = 0; - end = *((unsigned int*) p); - start = *((unsigned int*) data); - snprintf(addrstr, sizeof(addrstr), "%.4x", end - start); - } - - c = *p; - if (isalnum(c) == 0) { - c = '.'; - } - - /* store hex str (for left side) */ - snprintf(bytestr, sizeof(bytestr), "%02X ", *p); - strncat(hexstr, bytestr, sizeof(hexstr)-strlen(hexstr)-1); - - /* store char str (for right side) */ - snprintf(bytestr, sizeof(bytestr), "%c", c); - strncat(charstr, bytestr, sizeof(charstr)-strlen(charstr)-1); - - if (n%16 == 0) { - /* line completed */ - ipc_client_log(client, "[%4.4s] %-50.50s %s", addrstr, hexstr, charstr); - hexstr[0] = 0; - charstr[0] = 0; - } else if (n%8 == 0) { - /* half line: add whitespaces */ - strncat(hexstr, " ", sizeof(hexstr)-strlen(hexstr)-1); - strncat(charstr, " ", sizeof(charstr)-strlen(charstr)-1); - } - p++; /* next byte */ - } - - if (strlen(hexstr) > 0) { - /* print rest of buffer if not empty */ - ipc_client_log(client, "[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr); - } -} - -void ipc_client_log_recv(struct ipc_client *client, - struct ipc_message_info *response, const char *prefix) -{ - switch (client->type) { - case IPC_CLIENT_TYPE_FMT: - ipc_client_log(client, "%s: RECV FMT!", prefix); - ipc_client_log(client, "%s: Response: aseq=0x%02x, command=%s, type=%s, length=%d", - prefix, response->aseq, ipc_command_to_str(IPC_COMMAND(response)), ipc_response_type_to_str(response->type), response->length); -#ifdef DEBUG - if (response->length > 0) { - ipc_client_log(client, "==== FMT DATA DUMP ===="); - ipc_client_hex_dump(client, (void *) response->data, - response->length > 0x100 ? 0x100 : response->length); - ipc_client_log(client, "======================="); - } -#endif - break; - case IPC_CLIENT_TYPE_RFS: - ipc_client_log(client, "%s: RECV RFS!", prefix); - ipc_client_log(client, "%s: Response: aseq=0x%02x, command=%s, length=%d", - prefix, response->aseq, ipc_command_to_str(IPC_COMMAND(response)), response->length); -#ifdef DEBUG - if (response->length > 0) { - ipc_client_log(client, "==== RFS DATA DUMP ===="); - ipc_client_hex_dump(client, (void *) response->data, - response->length > 0x100 ? 0x100 : response->length); - ipc_client_log(client, "======================="); - } -#endif - break; - } -} - -void ipc_client_log_send(struct ipc_client *client, - struct ipc_message_info *request, const char *prefix) -{ - switch (client->type) { - case IPC_CLIENT_TYPE_FMT: - ipc_client_log(client, "%s: SEND FMT!", prefix); - ipc_client_log(client, "%s: Request: mseq=0x%02x, command=%s, type=%s, length=%d", - prefix, request->mseq, ipc_command_to_str(IPC_COMMAND(request)), ipc_request_type_to_str(request->type), request->length); -#ifdef DEBUG - if (request->length > 0) { - ipc_client_log(client, "==== FMT DATA DUMP ===="); - ipc_client_hex_dump(client, (void *) request->data, - request->length > 0x100 ? 0x100 : request->length); - ipc_client_log(client, "======================="); - } -#endif - break; - case IPC_CLIENT_TYPE_RFS: - ipc_client_log(client, "%s: SEND RFS!", prefix); - ipc_client_log(client, "%s: Request: mseq=0x%02x, command=%s, length=%d", - prefix, request->mseq, ipc_command_to_str(IPC_COMMAND(request)), request->length); -#ifdef DEBUG - if (request->length > 0) { - ipc_client_log(client, "==== RFS DATA DUMP ===="); - ipc_client_hex_dump(client, (void *) request->data, - request->length > 0x100 ? 0x100 : request->length); - ipc_client_log(client, "======================="); - } -#endif - break; - } -} - -void ipc_fmt_header_fill(struct ipc_fmt_header *header, struct ipc_message_info *message) -{ - if (header == NULL || message == NULL) - return; - - memset(header, 0, sizeof(struct ipc_fmt_header)); - header->mseq = message->mseq; - header->aseq = message->aseq; - header->group = message->group; - header->index = message->index; - header->type = message->type; - header->length = message->length + sizeof(struct ipc_fmt_header); -} - -void ipc_fmt_message_fill(struct ipc_fmt_header *header, struct ipc_message_info *message) -{ - if (header == NULL || message == NULL) - return; - - memset(message, 0, sizeof(struct ipc_message_info)); - message->mseq = header->mseq; - message->aseq = header->aseq; - message->group = header->group; - message->index = header->index; - message->type = header->type; - message->cmd = IPC_COMMAND(message); - message->length = 0; - message->data = NULL; -} - -void ipc_rfs_header_fill(struct ipc_rfs_header *header, struct ipc_message_info *message) -{ - if (header == NULL || message == NULL) - return; - - memset(header, 0, sizeof(struct ipc_rfs_header)); - header->id = message->mseq; - header->index = message->index; - header->length = message->length + sizeof(struct ipc_rfs_header); -} - -void ipc_rfs_message_fill(struct ipc_rfs_header *header, struct ipc_message_info *message) -{ - if (header == NULL || message == NULL) - return; - - memset(message, 0, sizeof(struct ipc_message_info)); - message->aseq = header->id; - message->group = IPC_GROUP_RFS; - message->index = header->index; - message->length = 0; - message->data = NULL; -} - -// vim:ts=4:sw=4:expandtab diff --git a/samsung-ipc/ipc_utils.c b/samsung-ipc/ipc_utils.c new file mode 100644 index 0000000..54a4fd7 --- /dev/null +++ b/samsung-ipc/ipc_utils.c @@ -0,0 +1,531 @@ +/* + * This file is part of libsamsung-ipc. + * + * Copyright (C) 2010-2011 Joerie de Gram + * Copyright (C) 2013-2014 Paul Kocialkowski + * + * libsamsung-ipc 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 2 of the License, or + * (at your option) any later version. + * + * libsamsung-ipc 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 libsamsung-ipc. If not, see . + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include "ipc.h" + +const char *ipc_request_type_string(unsigned char type) +{ + static char type_string[5] = { 0 }; + + switch (type) { + case IPC_TYPE_EXEC: + return "IPC_TYPE_EXEC"; + case IPC_TYPE_GET: + return "IPC_TYPE_GET"; + case IPC_TYPE_SET: + return "IPC_TYPE_SET"; + case IPC_TYPE_CFRM: + return "IPC_TYPE_CFRM"; + case IPC_TYPE_EVENT: + return "IPC_TYPE_EVENT"; + default: + snprintf((char *) &type_string, sizeof(type_string), "0x%02x", type); + return type_string; + } +} + +const char *ipc_response_type_string(unsigned char type) +{ + static char type_string[5] = { 0 }; + + switch (type) { + case IPC_TYPE_INDI: + return "IPC_TYPE_INDI"; + case IPC_TYPE_RESP: + return "IPC_TYPE_RESP"; + case IPC_TYPE_NOTI: + return "IPC_TYPE_NOTI"; + default: + snprintf((char *) &type_string, sizeof(type_string), "0x%02x", type); + return type_string; + } +} + +const char *ipc_command_string(unsigned short command) +{ + static char command_string[7] = { 0 }; + + switch (command) { + case IPC_PWR_PHONE_PWR_UP: + return "IPC_PWR_PHONE_PWR_UP"; + case IPC_PWR_PHONE_PWR_OFF: + return "IPC_PWR_PHONE_PWR_OFF"; + case IPC_PWR_PHONE_RESET: + return "IPC_PWR_PHONE_RESET"; + case IPC_PWR_BATT_STATUS: + return "IPC_PWR_BATT_STATUS"; + case IPC_PWR_BATT_TYPE: + return "IPC_PWR_BATT_TYPE"; + case IPC_PWR_BATT_COMP: + return "IPC_PWR_BATT_COMP"; + case IPC_PWR_PHONE_STATE: + return "IPC_PWR_PHONE_STATE"; + case IPC_CALL_OUTGOING: + return "IPC_CALL_OUTGOING"; + case IPC_CALL_INCOMING: + return "IPC_CALL_INCOMING"; + case IPC_CALL_RELEASE: + return "IPC_CALL_RELEASE"; + case IPC_CALL_ANSWER: + return "IPC_CALL_ANSWER"; + case IPC_CALL_STATUS: + return "IPC_CALL_STATUS"; + case IPC_CALL_LIST: + return "IPC_CALL_LIST"; + case IPC_CALL_BURST_DTMF: + return "IPC_CALL_BURST_DTMF"; + case IPC_CALL_CONT_DTMF: + return "IPC_CALL_CONT_DTMF"; + case IPC_CALL_WAITING: + return "IPC_CALL_WAITING"; + case IPC_CALL_LINE_ID: + return "IPC_CALL_LINE_ID"; + case IPC_SMS_SEND_MSG: + return "IPC_SMS_SEND_MSG"; + case IPC_SMS_INCOMING_MSG: + return "IPC_SMS_INCOMING_MSG"; + case IPC_SMS_READ_MSG: + return "IPC_SMS_READ_MSG"; + case IPC_SMS_SAVE_MSG: + return "IPC_SMS_SAVE_MSG"; + case IPC_SMS_DEL_MSG: + return "IPC_SMS_DEL_MSG"; + case IPC_SMS_DELIVER_REPORT: + return "IPC_SMS_DELIVER_REPORT"; + case IPC_SMS_DEVICE_READY: + return "IPC_SMS_DEVICE_READY"; + case IPC_SMS_SEL_MEM: + return "IPC_SMS_SEL_MEM"; + case IPC_SMS_STORED_MSG_COUNT: + return "IPC_SMS_STORED_MSG_COUNT"; + case IPC_SMS_SVC_CENTER_ADDR: + return "IPC_SMS_SVC_CENTER_ADDR"; + case IPC_SMS_SVC_OPTION: + return "IPC_SMS_SVC_OPTION"; + case IPC_SMS_MEM_STATUS: + return "IPC_SMS_MEM_STATUS"; + case IPC_SMS_CBS_MSG: + return "IPC_SMS_CBS_MSG"; + case IPC_SMS_CBS_CFG: + return "IPC_SMS_CBS_CFG"; + case IPC_SMS_STORED_MSG_STATUS: + return "IPC_SMS_STORED_MSG_STATUS"; + case IPC_SMS_PARAM_COUNT: + return "IPC_SMS_PARAM_COUNT"; + case IPC_SMS_PARAM: + return "IPC_SMS_PARAM"; + case IPC_SEC_PIN_STATUS: + return "IPC_SEC_PIN_STATUS"; + case IPC_SEC_PHONE_LOCK: + return "IPC_SEC_PHONE_LOCK"; + case IPC_SEC_CHANGE_LOCKING_PW: + return "IPC_SEC_CHANGE_LOCKING_PW"; + case IPC_SEC_SIM_LANG: + return "IPC_SEC_SIM_LANG"; + case IPC_SEC_RSIM_ACCESS: + return "IPC_SEC_RSIM_ACCESS"; + case IPC_SEC_GSIM_ACCESS: + return "IPC_SEC_GSIM_ACCESS"; + case IPC_SEC_SIM_ICC_TYPE: + return "IPC_SEC_SIM_ICC_TYPE"; + case IPC_SEC_LOCK_INFOMATION: + return "IPC_SEC_LOCK_INFOMATION"; + case IPC_SEC_IMS_AUTH: + return "IPC_SEC_IMS_AUTH"; + case IPC_PB_ACCESS: + return "IPC_PB_ACCESS"; + case IPC_PB_STORAGE: + return "IPC_PB_STORAGE"; + case IPC_PB_STORAGE_LIST: + return "IPC_PB_STORAGE_LIST"; + case IPC_PB_ENTRY_INFO: + return "IPC_PB_ENTRY_INFO"; + case IPC_PB_3GPB_CAPA: + return "IPC_PB_3GPB_CAPA"; + case IPC_DISP_ICON_INFO: + return "IPC_DISP_ICON_INFO"; + case IPC_DISP_HOMEZONE_INFO: + return "IPC_DISP_HOMEZONE_INFO"; + case IPC_DISP_RSSI_INFO: + return "IPC_DISP_RSSI_INFO"; + case IPC_NET_PREF_PLMN: + return "IPC_NET_PREF_PLMN"; + case IPC_NET_PLMN_SEL: + return "IPC_NET_PLMN_SEL"; + case IPC_NET_SERVING_NETWORK: + return "IPC_NET_SERVING_NETWORK"; + case IPC_NET_PLMN_LIST: + return "IPC_NET_PLMN_LIST"; + case IPC_NET_REGIST: + return "IPC_NET_REGIST"; + case IPC_NET_SUBSCRIBER_NUM: + return "IPC_NET_SUBSCRIBER_NUM"; + case IPC_NET_BAND_SEL: + return "IPC_NET_BAND_SEL"; + case IPC_NET_SERVICE_DOMAIN_CONFIG: + return "IPC_NET_SERVICE_DOMAIN_CONFIG"; + case IPC_NET_POWERON_ATTACH: + return "IPC_NET_POWERON_ATTACH"; + case IPC_NET_MODE_SEL: + return "IPC_NET_MODE_SEL"; + case IPC_NET_ACQ_ORDER: + return "IPC_NET_ACQ_ORDER"; + case IPC_NET_IDENTITY: + return "IPC_NET_IDENTITY"; + case IPC_NET_PREFERRED_NETWORK_INFO: + return "IPC_NET_PREFERRED_NETWORK_INFO"; + case IPC_SND_SPKR_VOLUME_CTRL: + return "IPC_SND_SPKR_VOLUME_CTRL"; + case IPC_SND_MIC_MUTE_CTRL: + return "IPC_SND_MIC_MUTE_CTRL"; + case IPC_SND_AUDIO_PATH_CTRL: + return "IPC_SND_AUDIO_PATH_CTRL"; + case IPC_SND_AUDIO_SOURCE_CTRL: + return "IPC_SND_AUDIO_SOURCE_CTRL"; + case IPC_SND_LOOPBACK_CTRL: + return "IPC_SND_LOOPBACK_CTRL"; + case IPC_SND_VOICE_RECORDING_CTRL: + return "IPC_SND_VOICE_RECORDING_CTRL"; + case IPC_SND_VIDEO_CALL_CTRL: + return "IPC_SND_VIDEO_CALL_CTRL"; + case IPC_SND_RINGBACK_TONE_CTRL: + return "IPC_SND_RINGBACK_TONE_CTRL"; + case IPC_SND_CLOCK_CTRL: + return "IPC_SND_CLOCK_CTRL"; + case IPC_SND_WB_AMR_STATUS: + return "IPC_SND_WB_AMR_STATUS"; + case IPC_MISC_ME_VERSION: + return "IPC_MISC_ME_VERSION"; + case IPC_MISC_ME_IMSI: + return "IPC_MISC_ME_IMSI"; + case IPC_MISC_ME_SN: + return "IPC_MISC_ME_SN"; + case IPC_MISC_TIME_INFO: + return "IPC_MISC_TIME_INFO"; + case IPC_MISC_DEBUG_LEVEL: + return "IPC_MISC_DEBUG_LEVEL"; + case IPC_SVC_ENTER: + return "IPC_SVC_ENTER"; + case IPC_SVC_END: + return "IPC_SVC_END"; + case IPC_SVC_PRO_KEYCODE: + return "IPC_SVC_PRO_KEYCODE"; + case IPC_SVC_SCREEN_CFG: + return "IPC_SVC_SCREEN_CFG"; + case IPC_SVC_DISPLAY_SCREEN: + return "IPC_SVC_DISPLAY_SCREEN"; + case IPC_SVC_CHANGE_SVC_MODE: + return "IPC_SVC_CHANGE_SVC_MODE"; + case IPC_SVC_DEVICE_TEST: + return "IPC_SVC_DEVICE_TEST"; + case IPC_SVC_DEBUG_DUMP: + return "IPC_SVC_DEBUG_DUMP"; + case IPC_SVC_DEBUG_STRING: + return "IPC_SVC_DEBUG_STRING"; + case IPC_SS_WAITING: + return "IPC_SS_WAITING"; + case IPC_SS_CLI: + return "IPC_SS_CLI"; + case IPC_SS_BARRING: + return "IPC_SS_BARRING"; + case IPC_SS_BARRING_PW: + return "IPC_SS_BARRING_PW"; + case IPC_SS_FORWARDING: + return "IPC_SS_FORWARDING"; + case IPC_SS_INFO: + return "IPC_SS_INFO"; + case IPC_SS_MANAGE_CALL: + return "IPC_SS_MANAGE_CALL"; + case IPC_SS_USSD: + return "IPC_SS_USSD"; + case IPC_SS_AOC: + return "IPC_SS_AOC"; + case IPC_SS_RELEASE_COMPLETE: + return "IPC_SS_RELEASE_COMPLETE"; + case IPC_GPRS_DEFINE_PDP_CONTEXT: + return "IPC_GPRS_DEFINE_PDP_CONTEXT"; + case IPC_GPRS_QOS: + return "IPC_GPRS_QOS"; + case IPC_GPRS_PS: + return "IPC_GPRS_PS"; + case IPC_GPRS_PDP_CONTEXT: + return "IPC_GPRS_PDP_CONTEXT"; + case IPC_GPRS_ENTER_DATA: + return "IPC_GPRS_ENTER_DATA"; + case IPC_GPRS_SHOW_PDP_ADDR: + return "IPC_GPRS_SHOW_PDP_ADDR"; + case IPC_GPRS_MS_CLASS: + return "IPC_GPRS_MS_CLASS"; + case IPC_GPRS_3G_QUAL_SRVC_PROFILE: + return "IPC_GPRS_3G_QUAL_SRVC_PROFILE"; + case IPC_GPRS_IP_CONFIGURATION: + return "IPC_GPRS_IP_CONFIGURATION"; + case IPC_GPRS_DEFINE_SEC_PDP_CONTEXT: + return "IPC_GPRS_DEFINE_SEC_PDP_CONTEXT"; + case IPC_GPRS_TFT: + return "IPC_GPRS_TFT"; + case IPC_GPRS_HSDPA_STATUS: + return "IPC_GPRS_HSDPA_STATUS"; + case IPC_GPRS_CURRENT_SESSION_DATA_COUNTER: + return "IPC_GPRS_CURRENT_SESSION_DATA_COUNTER"; + case IPC_GPRS_DATA_DORMANT: + return "IPC_GPRS_DATA_DORMANT"; + case IPC_GPRS_PIN_CTRL: + return "IPC_GPRS_PIN_CTRL"; + case IPC_GPRS_CALL_STATUS: + return "IPC_GPRS_CALL_STATUS"; + case IPC_GPRS_PORT_LIST: + return "IPC_GPRS_PORT_LIST"; + case IPC_SAT_PROFILE_DOWNLOAD: + return "IPC_SAT_PROFILE_DOWNLOAD"; + case IPC_SAT_ENVELOPE_CMD: + return "IPC_SAT_ENVELOPE_CMD"; + case IPC_SAT_PROACTIVE_CMD: + return "IPC_SAT_PROACTIVE_CMD"; + case IPC_SAT_TERMINATE_USAT_SESSION: + return "IPC_SAT_TERMINATE_USAT_SESSION"; + case IPC_SAT_EVENT_DOWNLOAD: + return "IPC_SAT_EVENT_DOWNLOAD"; + case IPC_SAT_PROVIDE_LOCAL_INFO: + return "IPC_SAT_PROVIDE_LOCAL_INFO"; + case IPC_SAT_POLLING: + return "IPC_SAT_POLLING"; + case IPC_SAT_REFRESH: + return "IPC_SAT_REFRESH"; + case IPC_SAT_SETUP_EVENT_LIST: + return "IPC_SAT_SETUP_EVENT_LIST"; + case IPC_SAT_CALL_CONTROL_RESULT: + return "IPC_SAT_CALL_CONTROL_RESULT"; + case IPC_SAT_IMAGE_CLUT: + return "IPC_SAT_IMAGE_CLUT"; + case IPC_SAT_SETUP_CALL_PROCESSING: + return "IPC_SAT_SETUP_CALL_PROCESSING"; + case IPC_IMEI_START: + return "IPC_IMEI_START"; + case IPC_IMEI_CHECK_DEVICE_INFO: + return "IPC_IMEI_CHECK_DEVICE_INFO"; + case IPC_RFS_NV_READ_ITEM: + return "IPC_RFS_NV_READ_ITEM"; + case IPC_RFS_NV_WRITE_ITEM: + return "IPC_RFS_NV_WRITE_ITEM"; + case IPC_GEN_PHONE_RES: + return "IPC_GEN_PHONE_RES"; + default: + snprintf((char *) &command_string, sizeof(command_string), "0x%04x", command); + return command_string; + } +} + +void ipc_hex_dump(struct ipc_client *client, const void *data, size_t size) +{ + /* dumps size bytes of *data to stdout. Looks like: + * [0000] 75 6E 6B 6E 6F 77 6E 20 + * 30 FF 00 00 00 00 39 00 unknown 0.....9. + * (in a single line of course) + */ + + unsigned char *p = (unsigned char *) data; + unsigned char c; + size_t n; + char bytestr[4] = {0}; + char addrstr[10] = {0}; + char hexstr[ 16*3 + 5] = {0}; + char charstr[16*1 + 5] = {0}; + for (n=1;n<=size;n++) { + if (n%16 == 1) { + /* store address for this line */ + unsigned int end = 0, start = 0; + end = *((unsigned int*) p); + start = *((unsigned int*) data); + snprintf(addrstr, sizeof(addrstr), "%.4x", end - start); + } + + c = *p; + if (isalnum(c) == 0) { + c = '.'; + } + + /* store hex str (for left side) */ + snprintf(bytestr, sizeof(bytestr), "%02X ", *p); + strncat(hexstr, bytestr, sizeof(hexstr)-strlen(hexstr)-1); + + /* store char str (for right side) */ + snprintf(bytestr, sizeof(bytestr), "%c", c); + strncat(charstr, bytestr, sizeof(charstr)-strlen(charstr)-1); + + if (n%16 == 0) { + /* line completed */ + ipc_client_log(client, "[%4.4s] %-50.50s %s", addrstr, hexstr, charstr); + hexstr[0] = 0; + charstr[0] = 0; + } else if (n%8 == 0) { + /* half line: add whitespaces */ + strncat(hexstr, " ", sizeof(hexstr)-strlen(hexstr)-1); + strncat(charstr, " ", sizeof(charstr)-strlen(charstr)-1); + } + p++; /* next byte */ + } + + if (strlen(hexstr) > 0) { + /* print rest of buffer if not empty */ + ipc_client_log(client, "[%4.4s] %-50.50s %s\n", addrstr, hexstr, charstr); + } +} + +void ipc_client_log_recv(struct ipc_client *client, struct ipc_message *message, + const char *prefix) +{ + if (client == NULL || message == NULL || prefix == NULL) + return; + + switch (client->type) { + case IPC_CLIENT_TYPE_FMT: + ipc_client_log(client, "%s: Received FMT message", prefix); + ipc_client_log(client, "%s: Message: aseq=0x%02x, command=%s, type=%s, size=%d", prefix, message->aseq, ipc_command_string(message->command), ipc_response_type_string(message->type), message->size); +#ifdef DEBUG + if (message->size > 0) { + ipc_client_log(client, "=============================== FMT data dump ================================"); + ipc_hex_dump(client, (void *) message->data, message->size > 0x100 ? 0x100 : message->size); + ipc_client_log(client, "=============================================================================="); + } +#endif + break; + case IPC_CLIENT_TYPE_RFS: + ipc_client_log(client, "%s: Received RFS message", prefix); + ipc_client_log(client, "%s: Message: aseq=0x%02x, command=%s, size=%d", prefix, message->aseq, ipc_command_string(message->command), message->size); +#ifdef DEBUG + if (message->size > 0) { + ipc_client_log(client, "=============================== RFS data dump ================================"); + ipc_hex_dump(client, (void *) message->data, message->size > 0x100 ? 0x100 : message->size); + ipc_client_log(client, "=============================================================================="); + } +#endif + break; + } +} + +void ipc_client_log_send(struct ipc_client *client, struct ipc_message *message, + const char *prefix) +{ + if (client == NULL || message == NULL || prefix == NULL) + return; + + switch (client->type) { + case IPC_CLIENT_TYPE_FMT: + ipc_client_log(client, "%s: Sent FMT message", prefix); + ipc_client_log(client, "%s: Message: mseq=0x%02x, command=%s, type=%s, size=%d", prefix, message->mseq, ipc_command_string(message->command), ipc_response_type_string(message->type), message->size); +#ifdef DEBUG + if (message->size > 0) { + ipc_client_log(client, "=============================== FMT data dump ================================"); + ipc_hex_dump(client, (void *) message->data, message->size > 0x100 ? 0x100 : message->size); + ipc_client_log(client, "=============================================================================="); + } +#endif + break; + case IPC_CLIENT_TYPE_RFS: + ipc_client_log(client, "%s: Sent RFS message", prefix); + ipc_client_log(client, "%s: Message: mseq=0x%02x, command=%s, size=%d", prefix, message->mseq, ipc_command_string(message->command), message->size); +#ifdef DEBUG + if (message->size > 0) { + ipc_client_log(client, "=============================== RFS data dump ================================"); + ipc_hex_dump(client, (void *) message->data, message->size > 0x100 ? 0x100 : message->size); + ipc_client_log(client, "=============================================================================="); + } +#endif + break; + } +} + +int ipc_fmt_header_setup(struct ipc_fmt_header *header, + const struct ipc_message *message) +{ + if (header == NULL || message == NULL) + return -1; + + memset(header, 0, sizeof(struct ipc_fmt_header)); + header->mseq = message->mseq; + header->aseq = message->aseq; + header->group = IPC_GROUP(message->command); + header->index = IPC_INDEX(message->command); + header->type = message->type; + header->length = message->size + sizeof(struct ipc_fmt_header); + + return 0; +} + +int ipc_fmt_message_setup(const struct ipc_fmt_header *header, + struct ipc_message *message) +{ + if (header == NULL || message == NULL) + return -1; + + memset(message, 0, sizeof(struct ipc_message)); + message->mseq = header->mseq; + message->aseq = header->aseq; + message->command = IPC_COMMAND(header->group, header->index); + message->type = header->type; + message->data = NULL; + message->size = 0; + + return 0; +} + +int ipc_rfs_header_setup(struct ipc_rfs_header *header, + const struct ipc_message *message) +{ + if (header == NULL || message == NULL) + return -1; + + memset(header, 0, sizeof(struct ipc_rfs_header)); + header->id = message->mseq; + header->index = IPC_INDEX(message->command); + header->length = message->size + sizeof(struct ipc_rfs_header); + + return 0; +} + +int ipc_rfs_message_setup(const struct ipc_rfs_header *header, + struct ipc_message *message) +{ + if (header == NULL || message == NULL) + return -1; + + memset(message, 0, sizeof(struct ipc_message)); + message->aseq = header->id; + message->command = IPC_COMMAND(IPC_GROUP_RFS, header->index); + message->data = NULL; + message->size = 0; + + return 0; +} + +// vim:ts=4:sw=4:expandtab diff --git a/tools/modemctrl.c b/tools/modemctrl.c index 0edfa8d..91d0dc9 100644 --- a/tools/modemctrl.c +++ b/tools/modemctrl.c @@ -62,25 +62,25 @@ int seq_get(void) void modem_snd_no_mic_mute(struct ipc_client *client) { uint8_t data = 0; - ipc_client_send(client, IPC_SND_MIC_MUTE_CTRL, IPC_TYPE_SET, (void *) &data, 1, seq_get()); + ipc_client_send(client, seq_get(), IPC_SND_MIC_MUTE_CTRL, IPC_TYPE_SET, (void *) &data, 1); } void modem_snd_clock_ctrl(struct ipc_client *client) { uint8_t data = 0x01; - ipc_client_send(client, IPC_SND_CLOCK_CTRL, IPC_TYPE_EXEC, (void *) &data, 1, seq_get()); + ipc_client_send(client, seq_get(), IPC_SND_CLOCK_CTRL, IPC_TYPE_EXEC, (void *) &data, 1); } void modem_snd_spkr_volume_ctrl(struct ipc_client *client) { uint16_t data = 0x0411; - ipc_client_send(client, IPC_SND_SPKR_VOLUME_CTRL, IPC_TYPE_SET, (void *) &data, 2, seq_get()); + ipc_client_send(client, seq_get(), IPC_SND_SPKR_VOLUME_CTRL, IPC_TYPE_SET, (void *) &data, 2); } void modem_snd_audio_path_ctrl(struct ipc_client *client) { uint8_t data = 0x01; - ipc_client_send(client, IPC_SND_AUDIO_PATH_CTRL, IPC_TYPE_SET, (void *) &data, 1, seq_get()); + ipc_client_send(client, seq_get(), IPC_SND_AUDIO_PATH_CTRL, IPC_TYPE_SET, (void *) &data, 1); } @@ -99,7 +99,7 @@ void modem_exec_call_out(struct ipc_client *client, char *num) call_out.prefix=IPC_CALL_PREFIX_NONE; //0x21;//IPC_CALL_PREFIX_NONE; memcpy(call_out.number, num, call_out.number_length); - ipc_client_send(client, IPC_CALL_OUTGOING, IPC_TYPE_EXEC, (void *) &call_out, sizeof(struct ipc_call_outgoing_data), seq_get()); + ipc_client_send(client, seq_get(), IPC_CALL_OUTGOING, IPC_TYPE_EXEC, (void *) &call_out, sizeof(struct ipc_call_outgoing_data)); out_call = 1; @@ -112,14 +112,14 @@ void modem_exec_call_answer(struct ipc_client *client) { modem_snd_clock_ctrl(client); - ipc_client_send(client, IPC_CALL_ANSWER, IPC_TYPE_EXEC, NULL, 0, seq_get()); + ipc_client_send(client, seq_get(), IPC_CALL_ANSWER, IPC_TYPE_EXEC, NULL, 0); modem_snd_no_mic_mute(client); } void modem_get_call_list(struct ipc_client *client) { - ipc_client_send(client, IPC_CALL_LIST, IPC_TYPE_GET, NULL, 0, seq_get()); + ipc_client_send(client, seq_get(), IPC_CALL_LIST, IPC_TYPE_GET, NULL, 0); modem_snd_no_mic_mute(client); } @@ -127,12 +127,12 @@ void modem_get_call_list(struct ipc_client *client) void modem_exec_power_normal(struct ipc_client *client) { uint16_t data = 0x0202; - ipc_client_send(client, IPC_PWR_PHONE_STATE, IPC_TYPE_EXEC, (void *) &data, sizeof(data), seq_get()); + ipc_client_send(client, seq_get(), IPC_PWR_PHONE_STATE, IPC_TYPE_EXEC, (void *) &data, sizeof(data)); } void modem_set_sms_device_ready(struct ipc_client *client) { - ipc_client_send(client, IPC_SMS_DEVICE_READY, IPC_TYPE_SET, NULL, 0, seq_get()); + ipc_client_send(client, seq_get(), IPC_SMS_DEVICE_READY, IPC_TYPE_SET, NULL, 0); } void modem_set_sec_pin_status(struct ipc_client *client, char *pin1, char *pin2) @@ -142,17 +142,17 @@ void modem_set_sec_pin_status(struct ipc_client *client, char *pin1, char *pin2) printf("[I] Sending PIN1 unlock request\n"); ipc_sec_pin_status_setup(&pin_status, IPC_SEC_PIN_TYPE_PIN1, pin1, pin2); - ipc_client_send(client, IPC_SEC_PIN_STATUS, IPC_TYPE_SET, (void *) &pin_status, sizeof(pin_status), seq_get()); + ipc_client_send(client, seq_get(), IPC_SEC_PIN_STATUS, IPC_TYPE_SET, (void *) &pin_status, sizeof(pin_status)); } -void modem_response_sec(struct ipc_client *client, struct ipc_message_info *resp) +void modem_response_sec(struct ipc_client *client, struct ipc_message *resp) { struct ipc_sec_pin_status_response_data *sim_status; unsigned char type; int status; char *data; - switch(IPC_COMMAND(resp)) + switch(resp->command) { case IPC_SEC_PIN_STATUS : sim_status = (struct ipc_sec_pin_status_response_data *)resp->data; @@ -208,9 +208,9 @@ void modem_response_sec(struct ipc_client *client, struct ipc_message_info *resp } } -void modem_response_sms(struct ipc_client *client, struct ipc_message_info *resp) +void modem_response_sms(struct ipc_client *client, struct ipc_message *resp) { - switch(IPC_COMMAND(resp)) + switch(resp->command) { case IPC_SMS_DEVICE_READY: if(state == MODEM_STATE_LPM) @@ -227,11 +227,11 @@ void modem_response_sms(struct ipc_client *client, struct ipc_message_info *resp } } -void modem_response_call(struct ipc_client *client, struct ipc_message_info *resp) +void modem_response_call(struct ipc_client *client, struct ipc_message *resp) { struct ipc_call_status_data *stat; - switch(IPC_COMMAND(resp)) + switch(resp->command) { case IPC_CALL_LIST: /* @@ -276,11 +276,11 @@ void modem_response_call(struct ipc_client *client, struct ipc_message_info *res } } -void modem_response_pwr(struct ipc_client *client, struct ipc_message_info *resp) +void modem_response_pwr(struct ipc_client *client, struct ipc_message *resp) { int state_n; - switch(IPC_COMMAND(resp)) + switch(resp->command) { case IPC_PWR_PHONE_PWR_UP: printf("[2] Phone is powered up (LPM)!\n"); @@ -307,13 +307,13 @@ void modem_response_pwr(struct ipc_client *client, struct ipc_message_info *resp } } -void modem_response_net(struct ipc_client *client, struct ipc_message_info *resp) +void modem_response_net(struct ipc_client *client, struct ipc_message *resp) { struct ipc_net_regist_response_data *regi; struct ipc_net_plmn_entry *plmn; char mnc[6]; - switch(IPC_COMMAND(resp)) + switch(resp->command) { case IPC_NET_REGIST: regi = (struct ipc_net_regist_response_data *) resp->data; @@ -325,7 +325,7 @@ void modem_response_net(struct ipc_client *client, struct ipc_message_info *resp break; case IPC_NET_SERVING_NETWORK: - memcpy(mnc, (char *)(resp->data + 3), 5); + memcpy(mnc, (char *)((char *) resp->data + 3), 5); mnc[5]=0; printf("[6] Registered with network! Got PLMN (Mobile Network Code): '%s'\n", mnc); /* @@ -340,9 +340,9 @@ void modem_response_net(struct ipc_client *client, struct ipc_message_info *resp } } -void modem_response_handle(struct ipc_client *client, struct ipc_message_info *resp) +void modem_response_handle(struct ipc_client *client, struct ipc_message *resp) { - switch(resp->group) + switch(IPC_GROUP(resp->command)) { case IPC_GROUP_NET: modem_response_net(client, resp); @@ -369,7 +369,7 @@ void modem_response_handle(struct ipc_client *client, struct ipc_message_info *r int modem_read_loop(struct ipc_client *client) { - struct ipc_message_info resp; + struct ipc_message resp; int rc; memset(&resp, 0, sizeof(resp)); @@ -431,7 +431,7 @@ int modem_start(struct ipc_client *client) int rc = -1; ipc_client_data_create(client); - ipc_client_bootstrap(client); + ipc_client_boot(client); usleep(300); @@ -458,8 +458,8 @@ void print_help() { printf("usage: modemctrl \n"); printf("commands:\n"); - printf("\tstart bootstrap modem and start read loop\n"); - printf("\tbootstrap bootstrap modem only\n"); + printf("\tstart boot modem and start read loop\n"); + printf("\tboot boot modem only\n"); printf("\tpower-on power on the modem\n"); printf("\tpower-off power off the modem\n"); printf("arguments:\n"); @@ -523,8 +523,8 @@ int main(int argc, char *argv[]) } if (debug == 0) - ipc_client_set_log_callback(client_fmt, modem_log_handler_quiet, NULL); - else ipc_client_set_log_callback(client_fmt, modem_log_handler, NULL); + ipc_client_log_callback_register(client_fmt, modem_log_handler_quiet, NULL); + else ipc_client_log_callback_register(client_fmt, modem_log_handler, NULL); while(opt_i < argc) { if(strncmp(argv[optind], "power-on", 8) == 0) { @@ -535,8 +535,8 @@ int main(int argc, char *argv[]) if (ipc_client_power_off(client_fmt) < 0) printf("[E] Something went wrong while powering modem off\n"); goto modem_quit; - } else if (strncmp(argv[optind], "bootstrap", 9) == 0) { - ipc_client_bootstrap(client_fmt); + } else if (strncmp(argv[optind], "boot", 9) == 0) { + ipc_client_boot(client_fmt); } else if(strncmp(argv[optind], "start", 5) == 0) { printf("[0] Starting modem on FMT client\n"); rc = modem_start(client_fmt); -- cgit v1.1