Skip to content

Instantly share code, notes, and snippets.

@telent
Created March 23, 2017 22:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save telent/fa67574cbb483228d9861376e8dea92a to your computer and use it in GitHub Desktop.
Save telent/fa67574cbb483228d9861376e8dea92a to your computer and use it in GitHub Desktop.
diff -ur libmbim-1.14.0.orig/src/mbimcli/mbimcli-basic-connect.c libmbim-1.14.0/src/mbimcli/mbimcli-basic-connect.c
--- libmbim-1.14.0.orig/src/mbimcli/mbimcli-basic-connect.c 2016-07-05 10:20:34.000000000 +0100
+++ libmbim-1.14.0/src/mbimcli/mbimcli-basic-connect.c 2017-03-23 22:14:17.607830964 +0000
@@ -46,6 +46,7 @@
static gboolean query_subscriber_ready_status_flag;
static gboolean query_radio_state_flag;
static gchar *set_radio_state_str;
+static gboolean machine_readable_output_flag;
static gboolean query_device_services_flag;
static gboolean query_pin_flag;
static gchar *set_pin_enter_str;
@@ -176,6 +177,10 @@
"Query IP configuration (SessionID is optional, defaults to 0)",
"[SessionID]"
},
+ { "machine-readable", 0, 0, G_OPTION_ARG_NONE, &machine_readable_output_flag,
+ "IP configuration output is machine readable (tab separated)",
+ NULL
+ },
{ "disconnect", 0, G_OPTION_FLAG_OPTIONAL_ARG, G_OPTION_ARG_CALLBACK, G_CALLBACK (disconnect_arg_parse),
"Disconnect (SessionID is optional, defaults to 0)",
"[SessionID]"
@@ -723,7 +728,9 @@
!mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
g_printerr ("error: couldn't get IP configuration response message: %s\n", error->message);
} else {
- success = mbimcli_print_ip_config (device, response, &error);
+ success = mbimcli_print_ip_config (device, response,
+ machine_readable_output_flag,
+ &error);
if (!success)
g_printerr ("error: couldn't parse IP configuration response message: %s\n", error->message);
}
diff -ur libmbim-1.14.0.orig/src/mbimcli/mbimcli-dss.c libmbim-1.14.0/src/mbimcli/mbimcli-dss.c
--- libmbim-1.14.0.orig/src/mbimcli/mbimcli-dss.c 2015-10-10 12:09:31.000000000 +0100
+++ libmbim-1.14.0/src/mbimcli/mbimcli-dss.c 2017-03-23 16:49:45.782946278 +0000
@@ -134,7 +134,7 @@
!mbim_message_response_get_result (response, MBIM_MESSAGE_TYPE_COMMAND_DONE, &error)) {
g_printerr ("error: couldn't get IP configuration response message: %s\n", error->message);
} else {
- success = mbimcli_print_ip_config (device, response, &error);
+ success = mbimcli_print_ip_config (device, response, FALSE, &error);
if (!success)
g_printerr ("error: couldn't parse IP configuration response message: %s\n", error->message);
}
diff -ur libmbim-1.14.0.orig/src/mbimcli/mbimcli-helpers.c libmbim-1.14.0/src/mbimcli/mbimcli-helpers.c
--- libmbim-1.14.0.orig/src/mbimcli/mbimcli-helpers.c 2015-10-10 13:58:10.000000000 +0100
+++ libmbim-1.14.0/src/mbimcli/mbimcli-helpers.c 2017-03-23 22:09:34.884695419 +0000
@@ -48,10 +48,76 @@
return FALSE;
}
+static void print_available_fields(gchar *family,
+ MbimDevice *device,
+ gchar *fields_str,
+ gboolean tab_separated)
+{
+ if(tab_separated) {
+ g_print ("\n%s\tfields\t%s\n", family, fields_str);
+ } else {
+ g_print ("\n[%s] IPv4 configuration available: '%s'\n",
+ mbim_device_get_path_display (device), fields_str);
+ }
+}
+
+static void print_ip_address(char *family,
+ guint i,
+ gchar *address_str,
+ guint prefix_length,
+ gboolean tab_separated)
+{
+ if(tab_separated) {
+ g_print ("%s\taddress\t%s/%u\n",
+ family,
+ address_str,
+ prefix_length);
+ } else {
+ g_print (" IP [%u]: '%s/%u'\n",
+ i,
+ address_str,
+ prefix_length);
+ }
+}
+
+static void print_gw_address(gchar *family,
+ gchar *str,
+ gboolean tab_separated)
+{
+ if(tab_separated) {
+ g_print ("%s\tgateway\t%s\n", family, str);
+ } else {
+ g_print (" Gateway: '%s'\n", str);
+ }
+}
+
+static void print_dns_address(gchar *family,
+ guint i,
+ gchar *str,
+ gboolean tab_separated)
+{
+ if(tab_separated) {
+ g_print ("%s\tdns\t%s\n", family, str);
+ } else {
+ g_print (" DNS [%u]: '%s'\n", i, str);
+ }
+}
+
+static void print_mtu(gchar *family,
+ guint mtu,
+ gboolean tab_separated)
+{
+ if(tab_separated) {
+ g_print ("%s\tmtu\t%u\n", family, mtu);
+ } else {
+ g_print (" MTU: '%u'\n", mtu);
+ }
+}
gboolean
mbimcli_print_ip_config (MbimDevice *device,
MbimMessage *response,
+ gboolean tab_separated,
GError **error)
{
MbimIPConfigurationAvailableFlag ipv4configurationavailable;
@@ -94,7 +160,7 @@
/* IPv4 info */
str = mbim_ip_configuration_available_flag_build_string_from_mask (ipv4configurationavailable);
- g_print ("\n[%s] IPv4 configuration available: '%s'\n", mbim_device_get_path_display (device), str);
+ print_available_fields("IPv4", device, str, tab_separated);
g_free (str);
if (ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_ADDRESS) {
@@ -103,10 +169,9 @@
for (i = 0; i < ipv4addresscount; i++) {
addr = g_inet_address_new_from_bytes ((guint8 *)&ipv4address[i]->ipv4_address, G_SOCKET_FAMILY_IPV4);
str = g_inet_address_to_string (addr);
- g_print (" IP [%u]: '%s/%u'\n",
- i,
- str,
- ipv4address[i]->on_link_prefix_length);
+ print_ip_address("IPv4", i, str,
+ ipv4address[i]->on_link_prefix_length,
+ tab_separated);
g_free (str);
g_object_unref (addr);
}
@@ -115,7 +180,7 @@
if (ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_GATEWAY) {
addr = g_inet_address_new_from_bytes ((guint8 *)ipv4gateway, G_SOCKET_FAMILY_IPV4);
str = g_inet_address_to_string (addr);
- g_print (" Gateway: '%s'\n", str);
+ print_gw_address("IPv4", str, tab_separated);
g_free (str);
g_object_unref (addr);
}
@@ -127,19 +192,19 @@
addr = g_inet_address_new_from_bytes ((guint8 *)&ipv4dnsserver[i], G_SOCKET_FAMILY_IPV4);
if (!g_inet_address_get_is_any (addr)) {
str = g_inet_address_to_string (addr);
- g_print (" DNS [%u]: '%s'\n", i, str);
+ print_dns_address("IPv4", i, str, tab_separated);
g_free (str);
}
g_object_unref (addr);
}
}
- if (ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU)
- g_print (" MTU: '%u'\n", ipv4mtu);
-
+ if (ipv4configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU){
+ print_mtu("IPv4", ipv4mtu, tab_separated);
+ }
/* IPv6 info */
str = mbim_ip_configuration_available_flag_build_string_from_mask (ipv6configurationavailable);
- g_print ("\n[%s] IPv6 configuration available: '%s'\n", mbim_device_get_path_display (device), str);
+ print_available_fields("IPv6", device, str, tab_separated);
g_free (str);
if (ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_ADDRESS) {
@@ -148,10 +213,9 @@
for (i = 0; i < ipv6addresscount; i++) {
addr = g_inet_address_new_from_bytes ((guint8 *)&ipv6address[i]->ipv6_address, G_SOCKET_FAMILY_IPV6);
str = g_inet_address_to_string (addr);
- g_print (" IP [%u]: '%s/%u'\n",
- i,
- str,
- ipv6address[i]->on_link_prefix_length);
+ print_ip_address("IPv6", i, str,
+ ipv6address[i]->on_link_prefix_length,
+ tab_separated);
g_free (str);
g_object_unref (addr);
}
@@ -160,7 +224,7 @@
if (ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_GATEWAY) {
addr = g_inet_address_new_from_bytes ((guint8 *)ipv6gateway, G_SOCKET_FAMILY_IPV6);
str = g_inet_address_to_string (addr);
- g_print (" Gateway: '%s'\n", str);
+ print_gw_address("IPv6", str, tab_separated);
g_free (str);
g_object_unref (addr);
}
@@ -172,7 +236,7 @@
addr = g_inet_address_new_from_bytes ((guint8 *)&ipv6dnsserver[i], G_SOCKET_FAMILY_IPV6);
if (!g_inet_address_get_is_any (addr)) {
str = g_inet_address_to_string (addr);
- g_print (" DNS [%u]: '%s'\n", i, str);
+ print_dns_address("IPv6", i, str, tab_separated);
g_free (str);
}
g_object_unref (addr);
@@ -180,7 +244,7 @@
}
if (ipv6configurationavailable & MBIM_IP_CONFIGURATION_AVAILABLE_FLAG_MTU)
- g_print (" MTU: '%u'\n", ipv6mtu);
+ print_mtu("IPv6", ipv6mtu, tab_separated);
mbim_ipv4_element_array_free (ipv4address);
mbim_ipv6_element_array_free (ipv6address);
diff -ur libmbim-1.14.0.orig/src/mbimcli/mbimcli-helpers.h libmbim-1.14.0/src/mbimcli/mbimcli-helpers.h
--- libmbim-1.14.0.orig/src/mbimcli/mbimcli-helpers.h 2015-10-10 12:09:31.000000000 +0100
+++ libmbim-1.14.0/src/mbimcli/mbimcli-helpers.h 2017-03-23 16:49:01.170657417 +0000
@@ -30,6 +30,7 @@
gboolean mbimcli_print_ip_config (MbimDevice *device,
MbimMessage *response,
+ gboolean tab_separated,
GError **error);
typedef gboolean (*MbimParseKeyValueForeachFn) (const gchar *key,
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment