aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--samsung-ipc/crespo_ipc.c72
-rw-r--r--samsung-ipc/h1_ipc.c21
-rw-r--r--samsung-ipc/ipc.c27
-rw-r--r--samsung-ipc/ipc.h36
4 files changed, 119 insertions, 37 deletions
diff --git a/samsung-ipc/crespo_ipc.c b/samsung-ipc/crespo_ipc.c
index d067115..4b4c497 100644
--- a/samsung-ipc/crespo_ipc.c
+++ b/samsung-ipc/crespo_ipc.c
@@ -38,6 +38,7 @@
#include "crespo_modem_ctl.h"
#include "crespo_nv_data.h"
#include "crespo_ipc.h"
+#include "ipc.h"
int s3c2410_serial3_fd= -1;
int modem_ctl_fd= -1;
@@ -135,7 +136,7 @@ error:
return NULL;
}
-int ipc_open(void)
+int crespo_ipc_open(void)
{
/* Control variables. */
int boot_tries_count=0;
@@ -165,21 +166,21 @@ int ipc_open(void)
uint8_t *data_p;
int i;
- printf("ipc_open: enter\n");
+ printf("crespo_ipc_open: enter\n");
boot_loop_start:
if(boot_tries_count > 5)
{
- printf("ipc_open: boot has failed too many times.\n");
+ printf("crespo_ipc_open: boot has failed too many times.\n");
goto error;
}
/* Read the radio.img image. */
- printf("ipc_open: reading radio image\n");
+ printf("crespo_ipc_open: reading radio image\n");
radio_img_p=mtd_read("/dev/mtd/mtd5ro", RADIO_IMG_SIZE, 0x1000);
- printf("ipc_open: radio image read\n");
+ printf("crespo_ipc_open: radio image read\n");
- printf("ipc_open: open modem_ctl\n");
+ printf("crespo_ipc_open: open modem_ctl\n");
modem_ctl_fd=open("/dev/modem_ctl", O_RDWR | O_NDELAY);
if(modem_ctl_fd < 0)
goto error_loop;
@@ -188,13 +189,13 @@ boot_loop_start:
ioctl(modem_ctl_fd, IOCTL_MODEM_RESET);
usleep(400000);
- printf("ipc_open: open s3c2410_serial3\n");
+ printf("crespo_ipc_open: open s3c2410_serial3\n");
s3c2410_serial3_fd=open("/dev/s3c2410_serial3", O_RDWR | O_NDELAY);
if(s3c2410_serial3_fd < 0)
goto error_loop;
/* Setup the s3c2410 serial. */
- printf("ipc_open: setup s3c2410_serial3\n");
+ printf("crespo_ipc_open: setup s3c2410_serial3\n");
tcgetattr(s3c2410_serial3_fd, &termios);
cfmakeraw(&termios);
@@ -210,31 +211,31 @@ boot_loop_start:
tcsetattr(s3c2410_serial3_fd, TCSANOW, &termios); //FIXME
/* Send 'AT' in ASCII. */
- printf("ipc_open: sending AT in ASCII\n");
+ printf("crespo_ipc_open: sending AT in ASCII\n");
for(i=0 ; i < 20 ; i++)
{
write(s3c2410_serial3_fd, "AT", 2);
usleep(50000);
}
- printf("ipc_open: sending AT in ASCII done\n");
+ printf("crespo_ipc_open: sending AT in ASCII done\n");
usleep(50000); //FIXME
/* Get and check bootcore version. */
read(s3c2410_serial3_fd, &bootcore_version, sizeof(bootcore_version));
- printf("ipc_open: got bootcore version: 0x%x\n", bootcore_version);
+ printf("crespo_ipc_open: got bootcore version: 0x%x\n", bootcore_version);
if(bootcore_version != BOOTCORE_VERSION)
goto error_loop;
/* Get info_size. */
read(s3c2410_serial3_fd, &info_size, sizeof(info_size));
- printf("ipc_open: got info_size: 0x%x\n", info_size);
+ printf("crespo_ipc_open: got info_size: 0x%x\n", info_size);
/* Send PSI magic. */
data=PSI_MAGIC;
write(s3c2410_serial3_fd, &data, sizeof(data));
- printf("ipc_open: sent PSI_MAGIC (0x%x)\n", PSI_MAGIC);
+ printf("crespo_ipc_open: sent PSI_MAGIC (0x%x)\n", PSI_MAGIC);
/* Send PSI data len. */
data_16=PSI_DATA_LEN;
@@ -245,7 +246,7 @@ boot_loop_start:
write(s3c2410_serial3_fd, data_p, 1);
data_p++;
}
- printf("ipc_open: sent PSI_DATA_LEN (0x%x)\n", PSI_DATA_LEN);
+ printf("crespo_ipc_open: sent PSI_DATA_LEN (0x%x)\n", PSI_DATA_LEN);
/* Write the first part of modem.img. */
FD_ZERO(&fds);
@@ -256,13 +257,13 @@ boot_loop_start:
data_p=radio_img_p;
- printf("ipc_open: sending the first part of radio.img\n");
+ printf("crespo_ipc_open: sending the first part of radio.img\n");
for(i=0 ; i < PSI_DATA_LEN ; i++)
{
if(select(FD_SETSIZE, NULL, &fds, NULL, &timeout) == 0)
{
- printf("ipc_open: select timeout passed\n");
+ printf("crespo_ipc_open: select timeout passed\n");
goto error_loop;
}
@@ -272,24 +273,24 @@ boot_loop_start:
data_p++;
}
- printf("ipc_open: first part of radio.img sent; crc_byte is 0x%x\n", crc_byte);
+ printf("crespo_ipc_open: first part of radio.img sent; crc_byte is 0x%x\n", crc_byte);
if(select(FD_SETSIZE, NULL, &fds, NULL, &timeout) == 0)
{
- printf("ipc_open: select timeout passed\n");
+ printf("crespo_ipc_open: select timeout passed\n");
goto error_loop;
}
write(s3c2410_serial3_fd, &crc_byte, sizeof(crc_byte));
- printf("ipc_open: crc_byte sent\n");
+ printf("crespo_ipc_open: crc_byte sent\n");
data=0;
for(i=0 ; data != 0x01 ; i++)
{
if(select(FD_SETSIZE, &fds, NULL, NULL, &timeout) == 0)
{
- printf("ipc_open: select timeout passed\n");
+ printf("crespo_ipc_open: select timeout passed\n");
goto error_loop;
}
@@ -297,15 +298,15 @@ boot_loop_start:
if(i > 50)
{
- printf("ipc_open: fairly too much attempts to get ACK\n");
+ printf("crespo_ipc_open: fairly too much attempts to get ACK\n");
goto error_loop;
}
}
- printf("ipc_open: close s3c2410_serial3\n");
+ printf("crespo_ipc_open: close s3c2410_serial3\n");
close(s3c2410_serial3_fd);
- printf("ipc_open: writing the rest of radio.img to modem_ctl.\n");
+ printf("crespo_ipc_open: writing the rest of radio.img to modem_ctl.\n");
/* Seek to the begining of modem_ctl_fd (should already be so). */
lseek(modem_ctl_fd, 0, SEEK_SET);
@@ -321,7 +322,7 @@ boot_loop_start:
{
if(select(FD_SETSIZE, NULL, &fds, NULL, &timeout) == 0)
{
- printf("ipc_open: select timeout passed\n");
+ printf("crespo_ipc_open: select timeout passed\n");
goto error_loop;
}
@@ -340,7 +341,7 @@ boot_loop_start:
nv_data_md5_check();
/* Write nv_data.bin to modem_ctl. */
- printf("ipc_open: write nv_data to modem_ctl\n");
+ printf("crespo_ipc_open: write nv_data to modem_ctl\n");
nv_data_p=file_read("/efs/nv_data.bin", NV_DATA_SIZE, 1024);
data_p=nv_data_p;
@@ -372,11 +373,11 @@ error:
printf("%s: something went wrong\n", __func__);
rc=1;
exit:
- printf("ipc_open: exit\n");
+ printf("crespo_ipc_open: exit\n");
return rc;
}
-int ipc_close(void)
+int crespo_ipc_close(void)
{
close(modem_fmt_fd);
close(modem_rfs_fd);
@@ -385,17 +386,17 @@ int ipc_close(void)
return 0;
}
-void ipc_power_on(void)
+void crespo_ipc_power_on(void)
{
ioctl(modem_ctl_fd, IOCTL_MODEM_START);
}
-void ipc_power_off(void)
+void crespo_ipc_power_off(void)
{
ioctl(modem_ctl_fd, IOCTL_MODEM_OFF);
}
-void ipc_send(struct ipc_request *request)
+void crespo_ipc_send(struct ipc_request *request)
{
struct modem_io modem_data;
struct ipc_header hdlc_data;
@@ -438,7 +439,7 @@ void wake_unlock(char *lock_name, int size)
write(wake_unlock_fd, lock_name, size);
}
-int ipc_recv(struct ipc_response *response)
+int crespo_ipc_recv(struct ipc_response *response)
{
struct modem_io modem_data;
struct ipc_header *hdlc_data;
@@ -510,3 +511,12 @@ recv_loop_start:
return 1;
}
+
+struct ipc_ops crespo_ipc_ops = {
+ .open = crespo_ipc_open,
+ .close = crespo_ipc_close,
+ .power_on = crespo_ipc_power_on,
+ .power_off = crespo_ipc_power_off,
+ .send = crespo_ipc_send,
+ .recv = crespo_ipc_recv,
+};
diff --git a/samsung-ipc/h1_ipc.c b/samsung-ipc/h1_ipc.c
index 4fc7f4f..9002283 100644
--- a/samsung-ipc/h1_ipc.c
+++ b/samsung-ipc/h1_ipc.c
@@ -22,11 +22,12 @@
#include <unistd.h>
#include <fcntl.h>
+#include "ipc.h"
#include "h1_ipc.h"
static int fd = 0;
-int ipc_open()
+int h1_ipc_open()
{
struct termios termios;
@@ -43,7 +44,7 @@ int ipc_open()
return 0;
}
-int ipc_close()
+int h1_ipc_close()
{
if(fd) {
return close(fd);
@@ -52,17 +53,17 @@ int ipc_close()
return 1;
}
-void ipc_power_on()
+void h1_ipc_power_on()
{
ioctl(fd, IOCTL_PHONE_ON);
}
-void ipc_power_off()
+void h1_ipc_power_off()
{
ioctl(fd, IOCTL_PHONE_OFF);
}
-void ipc_send(struct ipc_request *request)
+void h1_ipc_send(struct ipc_request *request)
{
struct hdlc_header *hdlc;
unsigned char *frame;
@@ -95,7 +96,7 @@ void ipc_send(struct ipc_request *request)
free(frame);
}
-int ipc_recv(struct ipc_response *response)
+int h1_ipc_recv(struct ipc_response *response)
{
unsigned char buf[4];
unsigned char *data;
@@ -131,3 +132,11 @@ int ipc_recv(struct ipc_response *response)
return 1;
}
+struct ipc_ops h1_ipc_ops = {
+ .open = h1_ipc_open,
+ .close = h1_ipc_close,
+ .power_on = h1_ipc_power_on,
+ .power_off = h1_ipc_power_off,
+ .send = h1_ipc_send,
+ .recv = h1_ipc_recv,
+};
diff --git a/samsung-ipc/ipc.c b/samsung-ipc/ipc.c
index 441a130..135dd63 100644
--- a/samsung-ipc/ipc.c
+++ b/samsung-ipc/ipc.c
@@ -24,6 +24,33 @@
#include <radio.h>
+#include "ipc.h"
+
+struct ipc_ops *ops = NULL;
+
+extern struct ipc_ops crespo_ipc_ops;
+extern struct ipc_ops h1_ipc_ops;
+
+int ipc_init(int client_type)
+{
+ int rc = 0;
+
+ switch (client_type)
+ {
+ case IPC_CLIENT_TYPE_CRESPO:
+ ops = &crespo_ipc_ops;
+ break;
+ case IPC_CLIENT_TYPE_H1:
+ ops = &h1_ipc_ops;
+ break;
+ default:
+ rc = -1;
+ break;
+ }
+
+ return rc;
+}
+
/* Convenience functions for ipc_send */
inline void ipc_msg_send_get(const int command, unsigned char aseq)
{
diff --git a/samsung-ipc/ipc.h b/samsung-ipc/ipc.h
new file mode 100644
index 0000000..29a30bd
--- /dev/null
+++ b/samsung-ipc/ipc.h
@@ -0,0 +1,36 @@
+/**
+ * This file is part of libsamsung-ipc.
+ *
+ * Copyright (C) 2011 Simon Busch <morphis@gravedo.de>
+ *
+ * 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 3 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#ifndef __IPC_H__
+#define __IPC_H__
+
+struct ipc_ops {
+ int (*open)(void);
+ int (*close)(void);
+ int (*power_on)(void);
+ int (*power_off)(void);
+ int (*send)(struct ipc_request*);
+ int (*recv)(struct ipc_response*);
+};
+
+#define IPC_CLIENT_TYPE_CRESPO 1
+#define IPC_CLIENT_TYPE_H1 2
+
+#endif