bearer-mbim: parse replies on failure

Based on a patch from: Bjørn Mork <bjorn@mork.no>

Some messages provide an additional NwError cause code from
the network in case of failure. This means that we need to
parse the reply even if the status indicates failure, to be
able to return the exact failure cause.
This commit is contained in:
Aleksander Morgado
2013-12-19 18:43:14 +01:00
parent ab12d17bfb
commit 52d34ce0db
+90 -54
View File
@@ -429,24 +429,36 @@ connect_set_ready (MbimDevice *device,
response = mbim_device_command_finish (device, res, &error);
if (response &&
mbim_message_command_done_get_result (response, &error) &&
mbim_message_connect_response_parse (
response,
&session_id,
&activation_state,
NULL, /* voice_call_state */
&ip_type,
NULL, /* context_type */
&nw_error,
&error)) {
if (nw_error)
error = mm_mobile_equipment_error_from_mbim_nw_error (nw_error);
else {
ctx->ip_type = ip_type;
mm_dbg ("Session ID '%u': %s (IP type: %s)",
session_id,
mbim_activation_state_get_string (activation_state),
mbim_context_ip_type_get_string (ip_type));
(mbim_message_command_done_get_result (response, &error) ||
error->code == MBIM_STATUS_ERROR_FAILURE)) {
GError *inner_error = NULL;
if (mbim_message_connect_response_parse (
response,
&session_id,
&activation_state,
NULL, /* voice_call_state */
&ip_type,
NULL, /* context_type */
&nw_error,
&inner_error)) {
if (nw_error) {
if (error)
g_error_free (error);
error = mm_mobile_equipment_error_from_mbim_nw_error (nw_error);
} else {
ctx->ip_type = ip_type;
mm_dbg ("Session ID '%u': %s (IP type: %s)",
session_id,
mbim_activation_state_get_string (activation_state),
mbim_context_ip_type_get_string (ip_type));
}
} else {
/* Prefer the error from the result to the parsing error */
if (!error)
error = inner_error;
else
g_error_free (inner_error);
}
}
@@ -523,27 +535,39 @@ packet_service_set_ready (MbimDevice *device,
response = mbim_device_command_finish (device, res, &error);
if (response &&
mbim_message_command_done_get_result (response, &error) &&
mbim_message_packet_service_response_parse (
response,
&nw_error,
&packet_service_state,
&highest_available_data_class,
&uplink_speed,
&downlink_speed,
&error)) {
if (nw_error)
error = mm_mobile_equipment_error_from_mbim_nw_error (nw_error);
else {
gchar *str;
(mbim_message_command_done_get_result (response, &error) ||
error->code == MBIM_STATUS_ERROR_FAILURE)) {
GError *inner_error = NULL;
str = mbim_data_class_build_string_from_mask (highest_available_data_class);
mm_dbg ("Packet service update:");
mm_dbg (" state: '%s'", mbim_packet_service_state_get_string (packet_service_state));
mm_dbg (" data class: '%s'", str);
mm_dbg (" uplink: '%" G_GUINT64_FORMAT "' bps", uplink_speed);
mm_dbg (" downlink: '%" G_GUINT64_FORMAT "' bps", downlink_speed);
g_free (str);
if (mbim_message_packet_service_response_parse (
response,
&nw_error,
&packet_service_state,
&highest_available_data_class,
&uplink_speed,
&downlink_speed,
&error)) {
if (nw_error) {
if (error)
g_error_free (error);
error = mm_mobile_equipment_error_from_mbim_nw_error (nw_error);
} else {
gchar *str;
str = mbim_data_class_build_string_from_mask (highest_available_data_class);
mm_dbg ("Packet service update:");
mm_dbg (" state: '%s'", mbim_packet_service_state_get_string (packet_service_state));
mm_dbg (" data class: '%s'", str);
mm_dbg (" uplink: '%" G_GUINT64_FORMAT "' bps", uplink_speed);
mm_dbg (" downlink: '%" G_GUINT64_FORMAT "' bps", downlink_speed);
g_free (str);
}
} else {
/* Prefer the error from the result to the parsing error */
if (!error)
error = inner_error;
else
g_error_free (inner_error);
}
}
@@ -902,22 +926,34 @@ disconnect_set_ready (MbimDevice *device,
response = mbim_device_command_finish (device, res, &error);
if (response &&
mbim_message_command_done_get_result (response, &error) &&
mbim_message_connect_response_parse (
response,
&session_id,
&activation_state,
NULL, /* voice_call_state */
NULL, /* ip_type */
NULL, /* context_type */
&nw_error,
&error)) {
if (nw_error)
error = mm_mobile_equipment_error_from_mbim_nw_error (nw_error);
else
mm_dbg ("Session ID '%u': %s",
session_id,
mbim_activation_state_get_string (activation_state));
(mbim_message_command_done_get_result (response, &error) ||
error->code == MBIM_STATUS_ERROR_FAILURE)) {
GError *inner_error = NULL;
if (mbim_message_connect_response_parse (
response,
&session_id,
&activation_state,
NULL, /* voice_call_state */
NULL, /* ip_type */
NULL, /* context_type */
&nw_error,
&error)) {
if (nw_error) {
if (error)
g_error_free (error);
error = mm_mobile_equipment_error_from_mbim_nw_error (nw_error);
} else
mm_dbg ("Session ID '%u': %s",
session_id,
mbim_activation_state_get_string (activation_state));
} else {
/* Prefer the error from the result to the parsing error */
if (!error)
error = inner_error;
else
g_error_free (inner_error);
}
}
if (error) {