bluetooth: add timeout for bluetooth connection request
This commit is contained in:
@@ -369,6 +369,9 @@ typedef enum {
|
|||||||
/* The modem could not be found */
|
/* The modem could not be found */
|
||||||
NM_DEVICE_STATE_REASON_MODEM_NOT_FOUND,
|
NM_DEVICE_STATE_REASON_MODEM_NOT_FOUND,
|
||||||
|
|
||||||
|
/* The Bluetooth connection failed or timed out */
|
||||||
|
NM_DEVICE_STATE_REASON_BT_FAILED,
|
||||||
|
|
||||||
/* Unused */
|
/* Unused */
|
||||||
NM_DEVICE_STATE_REASON_LAST = 0xFFFF
|
NM_DEVICE_STATE_REASON_LAST = 0xFFFF
|
||||||
} NMDeviceStateReason;
|
} NMDeviceStateReason;
|
||||||
|
@@ -397,6 +397,11 @@
|
|||||||
The modem could not be found.
|
The modem could not be found.
|
||||||
</tp:docstring>
|
</tp:docstring>
|
||||||
</tp:enumvalue>
|
</tp:enumvalue>
|
||||||
|
<tp:enumvalue suffix="BT_FAILED" value="44">
|
||||||
|
<tp:docstring>
|
||||||
|
The Bluetooth connection timed out or failed.
|
||||||
|
</tp:docstring>
|
||||||
|
</tp:enumvalue>
|
||||||
</tp:enum>
|
</tp:enum>
|
||||||
|
|
||||||
</interface>
|
</interface>
|
||||||
|
@@ -542,11 +542,9 @@ static gboolean
|
|||||||
modem_find_timeout (gpointer user_data)
|
modem_find_timeout (gpointer user_data)
|
||||||
{
|
{
|
||||||
NMDeviceBt *self = NM_DEVICE_BT (user_data);
|
NMDeviceBt *self = NM_DEVICE_BT (user_data);
|
||||||
NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (self);
|
|
||||||
|
|
||||||
priv->timeout_id = 0;
|
NM_DEVICE_BT_GET_PRIVATE (self)->timeout_id = 0;
|
||||||
|
nm_device_state_changed (NM_DEVICE (self),
|
||||||
nm_device_state_changed (NM_DEVICE (user_data),
|
|
||||||
NM_DEVICE_STATE_FAILED,
|
NM_DEVICE_STATE_FAILED,
|
||||||
NM_DEVICE_STATE_REASON_MODEM_NOT_FOUND);
|
NM_DEVICE_STATE_REASON_MODEM_NOT_FOUND);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
@@ -602,16 +600,18 @@ bluez_connect_cb (DBusGProxy *proxy,
|
|||||||
error && error->message ? error->message : "(unknown)");
|
error && error->message ? error->message : "(unknown)");
|
||||||
g_clear_error (&error);
|
g_clear_error (&error);
|
||||||
|
|
||||||
// FIXME: get a better reason code
|
nm_device_state_changed (NM_DEVICE (self),
|
||||||
nm_device_state_changed (NM_DEVICE (self), NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_NONE);
|
NM_DEVICE_STATE_FAILED,
|
||||||
|
NM_DEVICE_STATE_REASON_BT_FAILED);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!device || !strlen (device)) {
|
if (!device || !strlen (device)) {
|
||||||
nm_warning ("Invalid network device returned by bluez");
|
nm_warning ("Invalid network device returned by bluez");
|
||||||
|
|
||||||
// FIXME: get a better reason code
|
nm_device_state_changed (NM_DEVICE (self),
|
||||||
nm_device_state_changed (NM_DEVICE (self), NM_DEVICE_STATE_FAILED, NM_DEVICE_STATE_REASON_NONE);
|
NM_DEVICE_STATE_FAILED,
|
||||||
|
NM_DEVICE_STATE_REASON_BT_FAILED);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (priv->bt_type == NM_BT_CAPABILITY_DUN) {
|
if (priv->bt_type == NM_BT_CAPABILITY_DUN) {
|
||||||
@@ -670,6 +670,18 @@ bluez_property_changed (DBusGProxy *proxy,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static gboolean
|
||||||
|
bt_connect_timeout (gpointer user_data)
|
||||||
|
{
|
||||||
|
NMDeviceBt *self = NM_DEVICE_BT (user_data);
|
||||||
|
|
||||||
|
NM_DEVICE_BT_GET_PRIVATE (self)->timeout_id = 0;
|
||||||
|
nm_device_state_changed (NM_DEVICE (self),
|
||||||
|
NM_DEVICE_STATE_FAILED,
|
||||||
|
NM_DEVICE_STATE_REASON_BT_FAILED);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
|
||||||
static NMActStageReturn
|
static NMActStageReturn
|
||||||
real_act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
|
real_act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
|
||||||
{
|
{
|
||||||
@@ -736,6 +748,10 @@ real_act_stage2_config (NMDevice *device, NMDeviceStateReason *reason)
|
|||||||
G_TYPE_STRING, dun ? BLUETOOTH_DUN_UUID : BLUETOOTH_NAP_UUID,
|
G_TYPE_STRING, dun ? BLUETOOTH_DUN_UUID : BLUETOOTH_NAP_UUID,
|
||||||
G_TYPE_INVALID);
|
G_TYPE_INVALID);
|
||||||
|
|
||||||
|
if (priv->timeout_id)
|
||||||
|
g_source_remove (priv->timeout_id);
|
||||||
|
priv->timeout_id = g_timeout_add_seconds (30, bt_connect_timeout, device);
|
||||||
|
|
||||||
return NM_ACT_STAGE_RETURN_POSTPONE;
|
return NM_ACT_STAGE_RETURN_POSTPONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user