cli: implement bearer creating and listing based on the new MMBearer
This commit is contained in:
@@ -206,6 +206,83 @@ prefix_newlines (const gchar *prefix,
|
|||||||
NULL);
|
NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
print_bearer_info (MMBearer *bearer)
|
||||||
|
{
|
||||||
|
const MMBearerIpConfig *ipv4_config;
|
||||||
|
const MMBearerIpConfig *ipv6_config;
|
||||||
|
|
||||||
|
ipv4_config = mm_bearer_get_ipv4_config (bearer);
|
||||||
|
ipv6_config = mm_bearer_get_ipv6_config (bearer);
|
||||||
|
|
||||||
|
/* Not the best thing to do, as we may be doing _get() calls twice, but
|
||||||
|
* easiest to maintain */
|
||||||
|
#undef VALIDATE
|
||||||
|
#define VALIDATE(str) (str ? str : "unknown")
|
||||||
|
|
||||||
|
g_print ("Bearer '%s'\n",
|
||||||
|
mm_bearer_get_path (bearer));
|
||||||
|
g_print (" -------------------------\n"
|
||||||
|
" Status | connected: '%s'\n"
|
||||||
|
" | suspended: '%s'\n"
|
||||||
|
" | interface: '%s'\n",
|
||||||
|
mm_bearer_get_connected (bearer) ? "yes" : "no",
|
||||||
|
mm_bearer_get_suspended (bearer) ? "yes" : "no",
|
||||||
|
VALIDATE (mm_bearer_get_interface (bearer)));
|
||||||
|
|
||||||
|
/* IPv4 */
|
||||||
|
g_print (" -------------------------\n"
|
||||||
|
" IPv4 configuration | method: '%s'\n",
|
||||||
|
(ipv4_config ?
|
||||||
|
mmcli_get_bearer_ip_method_string (mm_bearer_ip_config_get_method (ipv4_config)) :
|
||||||
|
"none"));
|
||||||
|
if (ipv4_config &&
|
||||||
|
mm_bearer_ip_config_get_method (ipv4_config) == MM_BEARER_IP_METHOD_STATIC) {
|
||||||
|
const gchar **dns;
|
||||||
|
guint i;
|
||||||
|
|
||||||
|
dns = mm_bearer_ip_config_get_dns (ipv4_config);
|
||||||
|
g_print (" | address: '%s'\n"
|
||||||
|
" | prefix: '%u'\n"
|
||||||
|
" | gateway: '%s'\n"
|
||||||
|
" | DNS: '%s'",
|
||||||
|
VALIDATE (mm_bearer_ip_config_get_address (ipv4_config)),
|
||||||
|
mm_bearer_ip_config_get_prefix (ipv4_config),
|
||||||
|
VALIDATE (mm_bearer_ip_config_get_gateway (ipv4_config)),
|
||||||
|
VALIDATE (dns[0]));
|
||||||
|
/* Additional DNS addresses */
|
||||||
|
for (i = 1; dns[i]; i++)
|
||||||
|
g_print (", '%s'", dns[i]);
|
||||||
|
g_print ("\n");
|
||||||
|
}
|
||||||
|
|
||||||
|
/* IPv6 */
|
||||||
|
g_print (" -------------------------\n"
|
||||||
|
" IPv6 configuration | method: '%s'\n",
|
||||||
|
(ipv6_config ?
|
||||||
|
mmcli_get_bearer_ip_method_string (mm_bearer_ip_config_get_method (ipv6_config)) :
|
||||||
|
"none"));
|
||||||
|
if (ipv6_config &&
|
||||||
|
mm_bearer_ip_config_get_method (ipv6_config) == MM_BEARER_IP_METHOD_STATIC) {
|
||||||
|
const gchar **dns;
|
||||||
|
guint i;
|
||||||
|
|
||||||
|
dns = mm_bearer_ip_config_get_dns (ipv6_config);
|
||||||
|
g_print (" | address: '%s'\n"
|
||||||
|
" | prefix: '%u'\n"
|
||||||
|
" | gateway: '%s'\n"
|
||||||
|
" | DNS: '%s'",
|
||||||
|
VALIDATE(mm_bearer_ip_config_get_address (ipv6_config)),
|
||||||
|
mm_bearer_ip_config_get_prefix (ipv6_config),
|
||||||
|
VALIDATE(mm_bearer_ip_config_get_gateway (ipv6_config)),
|
||||||
|
VALIDATE(dns[0]));
|
||||||
|
/* Additional DNS addresses */
|
||||||
|
for (i = 1; dns[i]; i++)
|
||||||
|
g_print (", '%s'", dns[i]);
|
||||||
|
g_print ("\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
print_modem_info (void)
|
print_modem_info (void)
|
||||||
{
|
{
|
||||||
@@ -217,6 +294,7 @@ print_modem_info (void)
|
|||||||
|
|
||||||
/* Not the best thing to do, as we may be doing _get() calls twice, but
|
/* Not the best thing to do, as we may be doing _get() calls twice, but
|
||||||
* easiest to maintain */
|
* easiest to maintain */
|
||||||
|
#undef VALIDATE
|
||||||
#define VALIDATE(str) (str ? str : "unknown")
|
#define VALIDATE(str) (str ? str : "unknown")
|
||||||
|
|
||||||
/* Strings with mixed properties */
|
/* Strings with mixed properties */
|
||||||
@@ -292,7 +370,6 @@ print_modem_info (void)
|
|||||||
VALIDATE (mm_sim_get_operator_name (sim)));
|
VALIDATE (mm_sim_get_operator_name (sim)));
|
||||||
g_object_unref (sim);
|
g_object_unref (sim);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_print ("\n");
|
g_print ("\n");
|
||||||
|
|
||||||
g_free (prefixed_revision);
|
g_free (prefixed_revision);
|
||||||
@@ -408,8 +485,8 @@ factory_reset_ready (MMModem *modem,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
list_bearers_process_reply (gchar **result,
|
list_bearers_process_reply (GList *result,
|
||||||
const GError *error)
|
const GError *error)
|
||||||
{
|
{
|
||||||
if (error) {
|
if (error) {
|
||||||
g_printerr ("error: couldn't list bearers: '%s'\n",
|
g_printerr ("error: couldn't list bearers: '%s'\n",
|
||||||
@@ -418,21 +495,21 @@ list_bearers_process_reply (gchar **result,
|
|||||||
}
|
}
|
||||||
|
|
||||||
g_print ("\n");
|
g_print ("\n");
|
||||||
if (!result || !result[0]) {
|
if (!result) {
|
||||||
g_print ("No bearers were found\n");
|
g_print ("No bearers were found\n");
|
||||||
} else {
|
} else {
|
||||||
guint i;
|
GList *l;
|
||||||
|
|
||||||
/* Count number of items */
|
g_print ("Found %u bearers:\n", g_list_length (result));
|
||||||
for (i = 0; result[i]; i++)
|
for (l = result; l; l = g_list_next (l)) {
|
||||||
;
|
MMBearer *bearer = MM_BEARER (l->data);
|
||||||
g_print ("Found %u bearers:\n", i);
|
|
||||||
|
|
||||||
for (i = 0; result[i]; i++) {
|
g_print ("\n");
|
||||||
g_print ("\t%s\n", result[i]);
|
print_bearer_info (bearer);
|
||||||
|
g_object_unref (bearer);
|
||||||
}
|
}
|
||||||
|
g_list_free (result);
|
||||||
}
|
}
|
||||||
g_strfreev (result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -440,7 +517,7 @@ list_bearers_ready (MMModem *modem,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer nothing)
|
gpointer nothing)
|
||||||
{
|
{
|
||||||
gchar **operation_result;
|
GList *operation_result;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
operation_result = mm_modem_list_bearers_finish (modem, result, &error);
|
operation_result = mm_modem_list_bearers_finish (modem, result, &error);
|
||||||
@@ -450,17 +527,18 @@ list_bearers_ready (MMModem *modem,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
create_bearer_process_reply (gchar *result,
|
create_bearer_process_reply (MMBearer *bearer,
|
||||||
const GError *error)
|
const GError *error)
|
||||||
{
|
{
|
||||||
if (!result) {
|
if (!bearer) {
|
||||||
g_printerr ("error: couldn't create new bearer: '%s'\n",
|
g_printerr ("error: couldn't create new bearer: '%s'\n",
|
||||||
error ? error->message : "unknown error");
|
error ? error->message : "unknown error");
|
||||||
exit (EXIT_FAILURE);
|
exit (EXIT_FAILURE);
|
||||||
}
|
}
|
||||||
|
|
||||||
g_print ("successfully created new bearer in modem: '%s'\n", result);
|
g_print ("Successfully created new bearer in modem:\n");
|
||||||
g_free (result);
|
print_bearer_info (bearer);
|
||||||
|
g_object_unref (bearer);
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@@ -468,11 +546,11 @@ create_bearer_ready (MMModem *modem,
|
|||||||
GAsyncResult *result,
|
GAsyncResult *result,
|
||||||
gpointer nothing)
|
gpointer nothing)
|
||||||
{
|
{
|
||||||
gchar *operation_result;
|
MMBearer *bearer;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
|
|
||||||
operation_result = mm_modem_create_bearer_finish (modem, result, &error);
|
bearer = mm_modem_create_bearer_finish (modem, result, &error);
|
||||||
create_bearer_process_reply (operation_result, error);
|
create_bearer_process_reply (bearer, error);
|
||||||
|
|
||||||
mmcli_async_operation_done ();
|
mmcli_async_operation_done ();
|
||||||
}
|
}
|
||||||
@@ -783,7 +861,7 @@ mmcli_modem_run_synchronous (GDBusConnection *connection)
|
|||||||
|
|
||||||
/* Request to list the bearers? */
|
/* Request to list the bearers? */
|
||||||
if (list_bearers_flag) {
|
if (list_bearers_flag) {
|
||||||
gchar **result;
|
GList *result;
|
||||||
|
|
||||||
g_debug ("Synchronously listing bearers...");
|
g_debug ("Synchronously listing bearers...");
|
||||||
result = mm_modem_list_bearers_sync (ctx->modem, NULL, &error);
|
result = mm_modem_list_bearers_sync (ctx->modem, NULL, &error);
|
||||||
@@ -798,7 +876,7 @@ mmcli_modem_run_synchronous (GDBusConnection *connection)
|
|||||||
gchar *user = NULL;
|
gchar *user = NULL;
|
||||||
gchar *password = NULL;
|
gchar *password = NULL;
|
||||||
gchar *number = NULL;
|
gchar *number = NULL;
|
||||||
gchar *result;
|
MMBearer *bearer;
|
||||||
|
|
||||||
create_bearer_parse_known_input (create_bearer_str,
|
create_bearer_parse_known_input (create_bearer_str,
|
||||||
&apn,
|
&apn,
|
||||||
@@ -808,7 +886,7 @@ mmcli_modem_run_synchronous (GDBusConnection *connection)
|
|||||||
&number);
|
&number);
|
||||||
|
|
||||||
g_debug ("Synchronously creating new bearer in modem...");
|
g_debug ("Synchronously creating new bearer in modem...");
|
||||||
result = mm_modem_create_bearer_sync (ctx->modem,
|
bearer = mm_modem_create_bearer_sync (ctx->modem,
|
||||||
NULL,
|
NULL,
|
||||||
&error,
|
&error,
|
||||||
MM_BEARER_PROPERTY_APN, apn,
|
MM_BEARER_PROPERTY_APN, apn,
|
||||||
@@ -824,7 +902,7 @@ mmcli_modem_run_synchronous (GDBusConnection *connection)
|
|||||||
g_free (password);
|
g_free (password);
|
||||||
g_free (number);
|
g_free (number);
|
||||||
|
|
||||||
create_bearer_process_reply (result, error);
|
create_bearer_process_reply (bearer, error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user