summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoey Hewitt <joey@joeyhewitt.com>2019-09-19 14:34:55 -0600
committerJoey Hewitt <joey@joeyhewitt.com>2019-09-19 14:34:55 -0600
commit768db3423e938c3291fa39a49044a616f039c245 (patch)
treeb72d43bbb39041c4a7f01c61f4a57b71a4bc0906
parenteb2f3f6010f543bf8e7366dd234680a50a0657cb (diff)
downloadexternal_modem-boot-replicant-6.0.tar.gz
external_modem-boot-replicant-6.0.tar.bz2
external_modem-boot-replicant-6.0.zip
split into boot and efsdreplicant-6.0
-rw-r--r--.gitignore3
-rw-r--r--Android.mk25
-rw-r--r--Makefile7
-rw-r--r--boot.c58
-rw-r--r--efsd.c44
-rw-r--r--sahara.c48
-rw-r--r--sahara.h3
7 files changed, 120 insertions, 68 deletions
diff --git a/.gitignore b/.gitignore
index 054d289..8c705c1 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
*~
*.o
-modem-boot
+mdm9k-boot
+mdm9k-efsd
diff --git a/Android.mk b/Android.mk
index 65c1703..cb5a0e0 100644
--- a/Android.mk
+++ b/Android.mk
@@ -1,5 +1,6 @@
#
# Copyright (C) 2017 Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>
+# Copyright (C) 2019 Joey Hewitt <joey@joeyhewitt.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -18,15 +19,25 @@
LOCAL_PATH := $(call my-dir)
include $(CLEAR_VARS)
+ LOCAL_SRC_FILES := \
+ boot.c \
+ sahara.c
-LOCAL_SRC_FILES := \
- boot.c \
- sahara.c
+ LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH)
-LOCAL_C_INCLUDES := \
- $(LOCAL_PATH)
+ LOCAL_MODULE := mdm9k-boot
+ LOCAL_MODULE_TAGS := optional
+include $(BUILD_EXECUTABLE)
+
+include $(CLEAR_VARS)
+ LOCAL_SRC_FILES := \
+ efsd.c \
+ sahara.c
-LOCAL_MODULE := modem-boot
-LOCAL_MODULE_TAGS := optional
+ LOCAL_C_INCLUDES := \
+ $(LOCAL_PATH)
+ LOCAL_MODULE := mdm9k-efsd
+ LOCAL_MODULE_TAGS := optional
include $(BUILD_EXECUTABLE)
diff --git a/Makefile b/Makefile
index 06dffe1..a18c80b 100644
--- a/Makefile
+++ b/Makefile
@@ -5,7 +5,12 @@ HEADERS = i9305.h sahara.h
CC = gcc -Wall -Wextra
-modem-boot: boot.o sahara.o
+all: mdm9k-boot mdm9k-efsd
+
+mdm9k-boot: boot.o sahara.o $(HEADERS)
+ $(CC) $^ -o $@
+
+mdm9k-efsd: efsd.o sahara.o $(HEADERS)
$(CC) $^ -o $@
%.o: %.c
diff --git a/boot.c b/boot.c
index 583457e..1a7a056 100644
--- a/boot.c
+++ b/boot.c
@@ -20,49 +20,10 @@
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
-#include <termios.h>
#include <stdlib.h>
-#include <sahara.h>
-#include <i9305.h>
-
-int configure_tty(int *tty_fd, time_t timeout_sec, long int timeout_usec)
-{
- int tty_dev;
- struct termios termios;
- struct timeval timeout;
- fd_set fds;
- int rc;
-
- tty_dev = open(TTY_DEVICE, O_RDWR | O_SYNC);
- if (tty_dev < 0) {
- printf("failed to open modem tty device\n");
- return -1;
- } else {
- printf("opened modem tty device\n");
- }
-
- tcgetattr(tty_dev, &termios);
- cfmakeraw(&termios);
- cfsetispeed(&termios, B9600);
- cfsetospeed(&termios, B9600);
- tcsetattr(tty_dev, TCSANOW, &termios);
-
- FD_ZERO(&fds);
- FD_SET(tty_dev, &fds);
- timeout.tv_sec = timeout_sec;
- timeout.tv_usec = timeout_usec;
-
- rc = select(tty_dev+1, &fds, NULL, NULL, &timeout);
- if (rc <= 0) {
- printf("failed waiting to read\n");
- return -1;
- }
-
- *tty_fd = tty_dev;
-
- return 0;
-}
+#include "sahara.h"
+#include "i9305.h"
int main()
{
@@ -132,20 +93,5 @@ int main()
else
printf("error: cdc-wdm device does not exist\n");
- printf("\nconfiguring EFS sync\n");
-
- rc = configure_tty(&tty_dev, 0, 500000);
- if (rc < 0) {
- printf("failed to configure serial interface\n");
- }
-
- while (1) {
- rc = handle_memory_debug(tty_dev);
- if (rc < 0) {
- printf("error during modem operation\n");
- return -1;
- }
- }
-
return 0;
}
diff --git a/efsd.c b/efsd.c
new file mode 100644
index 0000000..67340a8
--- /dev/null
+++ b/efsd.c
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2017 Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de>
+ * Copyright (C) 2019 Joey Hewitt <joey@joeyhewitt.com>
+ *
+ * This program 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.
+ *
+ * This program 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 this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include <stdio.h>
+
+#include "sahara.h"
+#include "i9305.h"
+
+int main()
+{
+ int tty_dev;
+
+ printf("starting EFS sync daemon\n");
+
+ int rc = configure_tty(&tty_dev, 0, 500000);
+ if (rc < 0) {
+ printf("failed to configure serial interface\n");
+ }
+
+ while (1) {
+ rc = handle_memory_debug(tty_dev);
+ if (rc < 0) {
+ printf("error during modem operation\n");
+ return -1;
+ }
+ }
+
+ return 0;
+}
diff --git a/sahara.c b/sahara.c
index 271ee56..d41212c 100644
--- a/sahara.c
+++ b/sahara.c
@@ -21,9 +21,49 @@
#include <fcntl.h>
#include <unistd.h>
#include <string.h>
+#include <termios.h>
+#include <errno.h>
-#include <sahara.h>
-#include <i9305.h>
+#include "sahara.h"
+#include "i9305.h"
+
+int configure_tty(int *tty_fd, time_t timeout_sec, long int timeout_usec)
+{
+ int tty_dev;
+ struct termios termios;
+ struct timeval timeout;
+ fd_set fds;
+ int rc;
+
+ tty_dev = open(TTY_DEVICE, O_RDWR | O_SYNC);
+ if (tty_dev < 0) {
+ printf("failed to open modem tty device\n");
+ return -1;
+ } else {
+ printf("opened modem tty device\n");
+ }
+
+ tcgetattr(tty_dev, &termios);
+ cfmakeraw(&termios);
+ cfsetispeed(&termios, B9600);
+ cfsetospeed(&termios, B9600);
+ tcsetattr(tty_dev, TCSANOW, &termios);
+
+ FD_ZERO(&fds);
+ FD_SET(tty_dev, &fds);
+ timeout.tv_sec = timeout_sec;
+ timeout.tv_usec = timeout_usec;
+
+ rc = select(tty_dev+1, &fds, NULL, NULL, &timeout);
+ if (rc <= 0) {
+ printf("failed waiting to read\n");
+ return -1;
+ }
+
+ *tty_fd = tty_dev;
+
+ return 0;
+}
static int check_mode(int mode_recv, int mode_expected)
{
@@ -215,6 +255,7 @@ int send_file(int tty_fd, struct sah_data_end_ack *data_end_ack)
struct sah_header header;
struct sah_data_end_req data_end_req;
int rc;
+ char *filename = NULL;
rc = hello_handshake(tty_fd, SAH_MODE_TRANSFER_PENDING);
if (rc < 0) {
@@ -241,7 +282,8 @@ int send_file(int tty_fd, struct sah_data_end_ack *data_end_ack)
return -1;
}
- printf("id %d: file transfer complete\n", data_end_req.id);
+ file_for_id(data_end_req.id, &filename); // assume success because it succeeded before
+ printf("id %d file %s: file transfer complete\n", data_end_req.id, filename);
header.command = SAH_COMMAND_DATA_END_RESP;
header.packet_size = 8;
diff --git a/sahara.h b/sahara.h
index 65e9eb7..93f01f8 100644
--- a/sahara.h
+++ b/sahara.h
@@ -18,6 +18,8 @@
#ifndef __SAHARA_PROTOCOL_H__
#define __SAHARA_PROTOCOL_H__
+#include <time.h>
+
/*
* Most of these details of the SAHARA protocol were retrieved from the
* libopenpst library (https://github.com/openpst/libopenpst).
@@ -98,6 +100,7 @@ struct sah_memory_table {
unsigned char file[20];
} __attribute__((__packed__));
+int configure_tty(int *tty_fd, time_t timeout_sec, long int timeout_usec);
int send_file(int tty_fd, struct sah_data_end_ack *data_end_ack);
int handle_memory_debug(int tty_fd);