Esempio n. 1
0
/*
 * Called to ask the device to scan for networks
 *
 * We don't really scan as the WiMAX SDK daemon scans in the
 * background for us. We just get the results and hand them back via
 * the scan_result_cb callback.
 */
int iwmx_sdk_get_networks(struct wmxsdk *wmxsdk)
{
	int result;

	UINT32 nsp_list_length = 10;
	WIMAX_API_NSP_INFO_EX nsp_list[10];	/* FIXME: up to 32? */

	WIMAX_API_RET r;
	char errstr[512];
	UINT32 errstr_size = sizeof(errstr);

	r = GetNetworkListEx(&wmxsdk->device_id, nsp_list, &nsp_list_length);
	if (r != WIMAX_API_RET_SUCCESS) {
		GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size);
		nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot get network list: %d (%s)", r, errstr);
		result = -EIO;
		goto error_scan;
	}

	if (nsp_list_length == 0) {
		nm_log_dbg(LOGD_WIMAX, "no networks");
	} else
		__iwmx_sdk_scan_common_cb(&wmxsdk->device_id, nsp_list,
					nsp_list_length);
	result = 0;
error_scan:
	return result;
}
Esempio n. 2
0
int wimaxcu_get_network_list_ex(WIMAX_API_DEVICE_ID_P p_device_id, CMD_ARGS scan_mode)
{
    int ret = 0;
    WIMAX_API_RET wmxStatus;
    int time_out = 0;
    WIMAX_API_CONNECTION_MODE connectMode;
    WIMAX_API_DEVICE_STATUS DeviceStatus;
    WIMAX_API_CONNECTION_PROGRESS_INFO ConnectionProgressInfo;
    WIMAX_API_NSP_INFO_EX_P pNspInfo;

    UINT32 numOfNSPs = 20;
    int i = 0;

    // initialize the variable as No Networks found
    g_noNetworksFound = 1;
    g_searchProgress = 0;
    // get the device status
    wmxStatus =
        GetDeviceStatus(p_device_id, &DeviceStatus,
                        &ConnectionProgressInfo);
    if (WIMAX_API_RET_SUCCESS != wmxStatus) {
        PrintWmxStatus(wmxStatus);
        return 2;
    }

    switch (DeviceStatus) {
    case WIMAX_API_DEVICE_STATUS_UnInitialized: /**<  Device is uninitialized */
        printf("ERROR: Device not Initialized\n");
        return 2;
    case WIMAX_API_DEVICE_STATUS_RF_OFF_HW_SW:  /**<  Device RF Off(both H/W and S/W) */
        printf
        ("WARNING: HW and SW Radios are OFF.\nPlease turn ON the HW and SW Radios to perform a scan.\n");
        return 2;
    case WIMAX_API_DEVICE_STATUS_RF_OFF_HW:     /**<  Device RF Off(via H/W switch) */
        printf
        ("WARNING: HW Radio is OFF.\nPlease turn ON the HW Radio to perform a scan.\n");
        return 2;
    case WIMAX_API_DEVICE_STATUS_RF_OFF_SW:     /**<  Device RF Off(via S/W switch) */
        printf
        ("WARNING: SW Radio is OFF.\nPlease turn ON the SW Radio to perform a scan.\n");
        return 2;
    case WIMAX_API_DEVICE_STATUS_Ready:	     /**<  Device is ready */
    case WIMAX_API_DEVICE_STATUS_Scanning:	     /**<  Device is scanning */
        break;
    case WIMAX_API_DEVICE_STATUS_Connecting:    /**<  Connection in progress */
        printf("WARNING: Connection is in progress\n");
        return 2;
    case WIMAX_API_DEVICE_STATUS_Data_Connected:	/**<  Layer 2 connected */
        printf
        ("WARNING: Connection already established!\nPlease disconnect, before attempting to scan.\n");
        return 2;
    default:
        printf("ERROR: Device status Unknown.\n");
        return 2;
    }


    wmxStatus = SubscribeRfTaken(p_device_id, &ind_rf_taken_cb);
    if (WIMAX_API_RET_SUCCESS != wmxStatus) {
        PrintWmxStatus(wmxStatus);
        return 2;
    }
    wmxStatus = GetConnectionMode(p_device_id, &connectMode);
    if (WIMAX_API_RET_SUCCESS != wmxStatus) {
        PrintWmxStatus(wmxStatus);
        return 2;
    }

    if (connectMode == WIMAX_API_CONNECTION_MANUAL_SCAN_MANUAL_CONNECT
            && DeviceStatus == WIMAX_API_DEVICE_STATUS_Scanning) {
        printf
        ("WARNING: Scanning is in progress\nPlease wait for the current scan to complete.\n");
        return 2;
    }

    if (scan_mode == CMD_SCAN_ARG_PREFERRED) {

        wmxStatus =
            SubscribeNetworkSearchEx(p_device_id,
                                     &ind_network_search_cb_ex);
        if (WIMAX_API_RET_SUCCESS != wmxStatus) {
            PrintWmxStatus(wmxStatus);
            return 2;
        }
        /* In Manual mode always scan do not read the cache as we don't know when cache was updated */
        if (connectMode !=
                WIMAX_API_CONNECTION_MANUAL_SCAN_MANUAL_CONNECT) {
            pNspInfo =
                (WIMAX_API_NSP_INFO_EX_P) malloc(MAX_LEN *
                                                 sizeof
                                                 (WIMAX_API_NSP_INFO_EX));
            memset(pNspInfo, 0,
                   sizeof(WIMAX_API_NSP_INFO_EX) * MAX_LEN);
            wmxStatus =
                GetNetworkListEx(p_device_id, pNspInfo, &numOfNSPs);
            if (WIMAX_API_RET_SUCCESS != wmxStatus) {
                PrintWmxStatus(wmxStatus);
                /*
                   If the Device is already scanning, it won't allow one more AppSrv will reject it
                   with the Operation Falied error
                 */
                free(pNspInfo);
                return 1;
            }

            if (numOfNSPs != 0) {
                for (i = 0; i < numOfNSPs; i++) {
                    printf("\nNetwork found.\n");
                    PrintNSPInfoEx(&pNspInfo[i]);
                    if (wimaxcu_is_network_activated_ex
                            (p_device_id, &pNspInfo[i]))
                        printf("\tActivated\n");
                    else
                        printf("\tNot Activated\n");
                }
                return 0;
            }
        }

        wmxStatus = CmdNetworkSearch(p_device_id);

        if (WIMAX_API_RET_SUCCESS != wmxStatus) {
            PrintWmxStatus(wmxStatus);
            if ((DeviceStatus == WIMAX_API_DEVICE_STATUS_Scanning)
                    && (wmxStatus == WIMAX_API_RET_FAILED)) {
                printf
                ("WARNING: Scanning is in progress\nPlease wait for the current scan to complete.\n");
            }
            return 1;
        }

        printf("Scanning %2d%% Done ", g_searchProgress);
        fflush(stdout);
        do {
            if (wmxcu_sem_timeout(&g_semConnectionUtility, 5 * 1000)
                    == 1) {
                time_out++;
                //if (pthread_mutex_trylock(&g_console_owner_mutex) == 0) {
                printf("\r");
                printf("Scanning %2d%% Done ",
                       g_searchProgress);
                // printf("Scanning %2d% Done [", g_searchProgress);

                for (i = 0; i <= time_out; i++) {
                    printf("=");
                }
                printf("-");
//                                      for(i = 0; i<=SCAN_TIMEOUT_IN_10SEC_ITREATIONS - time_out; i++)
//                                      {
//                                              printf(" ");
//                                      }
//                                      printf("]");
                fflush(stdout);
                //pthread_mutex_unlock(&g_console_owner_mutex);
                //}
                wmxStatus =
                    GetDeviceStatus(p_device_id, &DeviceStatus,
                                    &ConnectionProgressInfo);
                if (WIMAX_API_RET_SUCCESS != wmxStatus) {
                    PrintWmxStatus(wmxStatus);
                    return 2;
                }

                if (DeviceStatus == WIMAX_API_DEVICE_STATUS_Ready) {
                    if (g_noNetworksFound == 1)
                        printf("\nNo networks found.\n");
                    break;
                }

                if (time_out > SCAN_TIMEOUT_IN_10SEC_ITREATIONS) {
                    if (g_noNetworksFound == 1) {
                        printf
                        ("\nNo networks found.\n");
                    } else {
                        printf
                        ("\nScan Operation timeout.\n");
                        // As Scan operation timed out
                        ret = 1;
                    }
                    break;
                }
            } else {
                break;
            }
        } while (1);

    } else if (scan_mode == CMD_SCAN_ARG_WIDE) {

        wmxStatus = SubscribeNetworkSearchWideScanEx(p_device_id,
                    &ind_network_search_wide_scan_cb_ex);
        if (WIMAX_API_RET_SUCCESS != wmxStatus) {
            PrintWmxStatus(wmxStatus);
            return 2;
        }
        // Display the warning message:
        printf("WARNING: Wide scan may take upto 2 minutes... \n");
        wmxStatus = CmdNetworkSearchWideScan(p_device_id);
        if (WIMAX_API_RET_SUCCESS != wmxStatus) {
            PrintWmxStatus(wmxStatus);
            /*
               If the Device is already scanning, it won't allow one more AppSrv will reject it
               with the Operation Falied wrror
             */
            if ((DeviceStatus == WIMAX_API_DEVICE_STATUS_Scanning)
                    && (wmxStatus == WIMAX_API_RET_FAILED)) {
                printf
                ("WARNING: Scanning is in progress\nPlease wait for the current scan to complete.\n ");

            }
            return 1;
        }

        if (wmxcu_sem_timeout(&g_semConnectionUtility, 120 * 1000) == 1)
            printf("No networks found.\n");
    }
    wmxStatus = UnsubscribeRfTaken(p_device_id);
    if (WIMAX_API_RET_SUCCESS != wmxStatus) {
        PrintWmxStatus(wmxStatus);
        return 2;
    }
    wmxStatus = UnsubscribeNetworkSearchEx(p_device_id);
    if (WIMAX_API_RET_SUCCESS != wmxStatus) {
        PrintWmxStatus(wmxStatus);
        return 2;
    }
    wmxStatus = UnsubscribeNetworkSearchWideScanEx(p_device_id);
    if (WIMAX_API_RET_SUCCESS != wmxStatus) {
        PrintWmxStatus(wmxStatus);
        return 2;
    }
    return ret;
}