aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLoic Poulain <loic.poulain@linaro.org>2020-12-11 15:53:25 +0100
committerLoic Poulain <loic.poulain@linaro.org>2020-12-16 12:09:57 +0100
commit9479c5f29f0340397b994e466aaed00f39624e04 (patch)
treeff34b28fb1e1f7c122a733e6e75d5a12504c381e
parent4f46583bb5e6d0bb081181c0a6290999523e58b6 (diff)
Add noqmap support
That disable wmap aggregation. The mhi interface then directly send/receive IP packets. Signed-off-by: Loic Poulain <loic.poulain@linaro.org>
-rwxr-xr-xmhi-qmi-connectbin103616 -> 108912 bytes
-rw-r--r--mhi-qmi-connect.c101
2 files changed, 88 insertions, 13 deletions
diff --git a/mhi-qmi-connect b/mhi-qmi-connect
index 463e828..35cb6c9 100755
--- a/mhi-qmi-connect
+++ b/mhi-qmi-connect
Binary files differ
diff --git a/mhi-qmi-connect.c b/mhi-qmi-connect.c
index 949acee..40ba1fb 100644
--- a/mhi-qmi-connect.c
+++ b/mhi-qmi-connect.c
@@ -10,7 +10,7 @@
#include <gio/gio.h>
#define MAX_QMAP_DATAGRAM_SIZE 16384
-#define MAX_QMAP_AGGREGATED_DATAGRAM 16
+#define MAX_QMAP_AGGREGATED_DATAGRAM 32
#define QMAP_HEADER_SIZE 16
// IFACE_ID/ENDPOINT_TYPE allows to select the type of endpoint/bus
@@ -57,6 +57,7 @@ struct config_struct {
gboolean set_ip;
gboolean default_route;
gboolean loopback;
+ gboolean noqmap;
};
static struct config_struct config;
@@ -412,6 +413,67 @@ static void setup_rmnet(void)
setup_dns();
}
+static void setup_ip(void)
+{
+ GError *error = NULL;
+ gchar cmdline[1000] = {0};
+ gchar *iptool = "ip";
+ gchar *iptool_alt = "/sbin/ip";
+
+ /* TODO: proper solution */
+ if (udev)
+ iptool = iptool_alt;
+
+ /* Set WWAN interface up */
+ g_snprintf(cmdline, sizeof(cmdline), "%s link set %s up", iptool, wwan_iface);
+ if (!g_spawn_command_line_sync(cmdline, NULL, NULL, NULL, &error)) {
+ g_printerr("%s: %s\n", cmdline, error->message);
+ g_error_free(error);
+ op_shutdown(SHUTDOWN_ERROR);
+ return;
+ }
+
+ if (config.set_ip) {
+ /* Set RMNET IP address */
+ g_snprintf(cmdline, sizeof(cmdline), "%s addr add %s/27 dev %s",
+ iptool, ip4_addr, wwan_iface);
+ if (!g_spawn_command_line_sync(cmdline, NULL, NULL, NULL, &error)) {
+ g_printerr("%s: %s\n", cmdline, error->message);
+ g_error_free(error);
+ op_shutdown(SHUTDOWN_ERROR);
+ return;
+ }
+ g_print("[%s] [IP] <%s> address set to %s\n",
+ qmi_device_get_path_display(device), wwan_iface, ip4_addr);
+ }
+
+ if (!config.default_route)
+ return;
+
+ g_print("[%s] [IP] <%s> as default route\n",
+ qmi_device_get_path_display(device), wwan_iface);
+
+ /* Save routing */
+ g_snprintf(cmdline, sizeof(cmdline), "%s route save", iptool);
+ if (!g_spawn_command_line_sync(cmdline, &ip_route_dump, NULL, NULL, &error)) {
+ g_printerr("%s: %s\n", cmdline, error->message);
+ g_error_free(error);
+ op_shutdown(SHUTDOWN_ERROR);
+ return;
+ }
+
+ /* Set mhi as default route */
+ g_snprintf(cmdline, sizeof(cmdline), "%s route replace default via %s", iptool, ip4_addr);
+ if (!g_spawn_command_line_sync(cmdline, NULL, NULL, NULL, &error)) {
+ g_printerr("%s: %s\n", cmdline, error->message);
+ g_error_free(error);
+ op_shutdown(SHUTDOWN_ERROR);
+ return;
+ }
+
+ setup_dns();
+}
+
/* 13 - Network settings retrieved */
static void get_current_settings_ready(QmiClientWds *client, GAsyncResult *res)
{
@@ -465,8 +527,11 @@ static void get_current_settings_ready(QmiClientWds *client, GAsyncResult *res)
}
qmi_message_wds_get_current_settings_output_unref(output);
-
- setup_rmnet();
+
+ if (config.noqmap)
+ setup_ip();
+ else
+ setup_rmnet();
}
/* 12 - Network started, get network settings */
@@ -485,7 +550,7 @@ static void start_network_ready(QmiClientWds *client, GAsyncResult *res)
op_shutdown(SHUTDOWN_ERROR);
return;
}
-
+
if (!qmi_message_wds_start_network_output_get_result(output, &error)) {
if (error->code == QMI_PROTOCOL_ERROR_CALL_FAILED) {
g_printerr("error: Call failed, retrying in 5 seconds\n");
@@ -649,15 +714,22 @@ static void allocate_wda_client_ready(QmiDevice *dev, GAsyncResult *res)
input = qmi_message_wda_set_data_format_input_new();
- /* QMAP aggregation protocol */
- qmi_message_wda_set_data_format_input_set_uplink_data_aggregation_protocol(
- input, QMI_WDA_DATA_AGGREGATION_PROTOCOL_QMAP, &error);
- qmi_message_wda_set_data_format_input_set_downlink_data_aggregation_protocol(
- input, QMI_WDA_DATA_AGGREGATION_PROTOCOL_QMAP, &error);
- qmi_message_wda_set_data_format_input_set_downlink_data_aggregation_max_size(
- input, MAX_QMAP_DATAGRAM_SIZE, &error);
- qmi_message_wda_set_data_format_input_set_downlink_data_aggregation_max_datagrams(
- input, MAX_QMAP_AGGREGATED_DATAGRAM, &error);
+ if (!config.noqmap) {
+ /* QMAP aggregation protocol */
+ qmi_message_wda_set_data_format_input_set_uplink_data_aggregation_protocol(
+ input, QMI_WDA_DATA_AGGREGATION_PROTOCOL_QMAP, &error);
+ qmi_message_wda_set_data_format_input_set_downlink_data_aggregation_protocol(
+ input, QMI_WDA_DATA_AGGREGATION_PROTOCOL_QMAP, &error);
+ qmi_message_wda_set_data_format_input_set_downlink_data_aggregation_max_size(
+ input, MAX_QMAP_DATAGRAM_SIZE, &error);
+ qmi_message_wda_set_data_format_input_set_downlink_data_aggregation_max_datagrams(
+ input, MAX_QMAP_AGGREGATED_DATAGRAM, &error);
+ } else {
+ /* Non aggregated IP */
+ qmi_message_wda_set_data_format_input_set_uplink_data_aggregation_protocol(
+ input, QMI_WDA_DATA_AGGREGATION_PROTOCOL_DISABLED, &error);
+ }
+
qmi_message_wda_set_data_format_input_set_link_layer_protocol(
input, QMI_WDA_LINK_LAYER_PROTOCOL_RAW_IP, &error);
@@ -993,6 +1065,9 @@ static GOptionEntry main_entries[] = {
{ "mux-id", 'm', 0, G_OPTION_ARG_INT, &config.mux_id,
"QMAP/RMNET mux-id of the connection (default is 1)", "[ID]"
},
+ { "noqmap", 0, 0, G_OPTION_ARG_NONE, &config.noqmap,
+ "Use raw IP protocol instead of QMAP (slower)", NULL
+ },
{ "set-ip", 0, 0, G_OPTION_ARG_NONE, &config.set_ip,
"Setup rmnet IP address and DNS from Bearer context info", NULL
},