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 */