From f74c9ebe8fd1d50ebac0aee1edd14f2a5d448fab Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 11 May 2011 15:06:50 -0500 Subject: [PATCH] wimax: don't attempt to connect while device is scanning The WiMAX SDK will reject connect requests while the device is scanning, which happens when right after suspend or when the wimax radio is turned on. Postpone the connect attempt until the device says it's not scanning anymore instead of having the connect attempt fail and be retried. --- src/wimax/nm-device-wimax.c | 54 +++++++++++++++++++++++++++---------- 1 file changed, 40 insertions(+), 14 deletions(-) diff --git a/src/wimax/nm-device-wimax.c b/src/wimax/nm-device-wimax.c index 12db7e2728..404d7553a1 100644 --- a/src/wimax/nm-device-wimax.c +++ b/src/wimax/nm-device-wimax.c @@ -717,29 +717,43 @@ real_act_stage1_prepare (NMDevice *device, NMDeviceStateReason *reason) NMActRequest *req; GSList *iter; const char *path; + NMWimaxNsp *nsp = NULL; clear_link_timeout (NM_DEVICE_WIMAX (device)); + *reason = NM_DEVICE_STATE_REASON_NONE; + req = nm_device_get_act_request (device); if (!req) - goto err; + return NM_ACT_STAGE_RETURN_FAILURE; path = nm_act_request_get_specific_object (req); if (!path) - goto err; + return NM_ACT_STAGE_RETURN_FAILURE; + /* Find the NSP in the scan list */ for (iter = priv->nsp_list; iter; iter = iter->next) { - NMWimaxNsp *nsp = NM_WIMAX_NSP (iter->data); + NMWimaxNsp *candidate = NM_WIMAX_NSP (iter->data); - if (!strcmp (path, nm_wimax_nsp_get_dbus_path (nsp))) { - set_current_nsp (NM_DEVICE_WIMAX (device), nsp); - return NM_ACT_STAGE_RETURN_SUCCESS; + if (!strcmp (path, nm_wimax_nsp_get_dbus_path (candidate))) { + nsp = candidate; + break; } } - err: - *reason = NM_DEVICE_STATE_REASON_NONE; - return NM_ACT_STAGE_RETURN_FAILURE; + /* Couldn't find the NSP for some reason */ + if (nsp == NULL) + return NM_ACT_STAGE_RETURN_FAILURE; + + set_current_nsp (NM_DEVICE_WIMAX (device), nsp); + + /* If the device is scanning, it won't connect, so we have to wait until + * it's not scanning to proceed to stage 2. + */ + if (priv->status == WIMAX_API_DEVICE_STATUS_Scanning) + return NM_ACT_STAGE_RETURN_POSTPONE; + + return NM_ACT_STAGE_RETURN_SUCCESS; } static NMActStageReturn @@ -857,11 +871,11 @@ wmx_state_change_cb (struct wmxsdk *wmxsdk, if (priv->current_nsp) nsp_name = nm_wimax_nsp_get_name (priv->current_nsp); - nm_log_dbg (LOGD_WIMAX, "(%s): wimax state change %s -> %s (reason %d)", - iface, - iwmx_sdk_dev_status_to_str (old_status), - iwmx_sdk_dev_status_to_str (new_status), - reason); + nm_log_info (LOGD_WIMAX, "(%s): wimax state change %s -> %s (reason %d)", + iface, + iwmx_sdk_dev_status_to_str (old_status), + iwmx_sdk_dev_status_to_str (new_status), + reason); switch (new_status) { case WIMAX_API_DEVICE_STATUS_UnInitialized: @@ -915,6 +929,18 @@ wmx_state_change_cb (struct wmxsdk *wmxsdk, NM_DEVICE_STATE_REASON_CONFIG_FAILED); return; } + + /* If stage2 was postponed because the device was scanning or something, + * then check if we need to move to stage2 now that the device might be + * ready. + */ + if (state == NM_DEVICE_STATE_PREPARE) { + if ( new_status == WIMAX_API_DEVICE_STATUS_Ready + || new_status == WIMAX_API_DEVICE_STATUS_Connecting) { + nm_device_activate_schedule_stage2_device_config (NM_DEVICE (self)); + return; + } + } } /* Handle disconnection */