예제 #1
0
int CNetManager::SetConnectionMode(int mode, CNetConnection **handle, string &strErr)
{
	int ret=0;
	int connectState=0;

	if (mode >= NET_VPN)	
	{
		*handle = m_pConnectionL1;
		strErr = "给定的网络模式不正确";
		return NET_MODE_ER;
	}

	//若当前有未断开的连接,禁止切换
	connectState = checkConnect();
	if (connectState == CONNECT_ON_L2)	//VPN连接未断
	{
		*handle = m_pConnectionL1;
		strErr = "请先断开VPN连接";
		return NET_INIT_FAIL;		
	}
	else if (connectState == CONNECT_ON_L1)	//第一层连接未断
	{
		//LAN与WMMP没有建立与断开的过程,可跳过
		if (GetConnectionMode()!=NET_LAN && GetConnectionMode()!=NET_M2M_WMMP)	
		{
			*handle = m_pConnectionL1;
			strErr = "当前连接未断开,无法切换模式";
			return NET_INIT_FAIL;		
		}
	}

	//重新建立实体
	if (m_pConnectionL1 != NULL)
	{
		delete m_pConnectionL1;
		m_pConnectionL1 = NULL;
	}
	
	ret = buildConnectionInstance(mode, &m_pConnectionL1, strErr);
	*handle = m_pConnectionL1;
	if (ret != NET_SUCCESS)
	{
		return ret;
	}

	//第一层网络需调用initNetDevice()
	m_pConnectionL1->initNetDevice(strErr);

	return NET_SUCCESS;
}
예제 #2
0
int CNetManager::buildTransInstance(CNetTransfers **pNetTrans, TransMode *transMode)
{
	CNetTransfers *pT=NULL;
	Sending *pS=NULL;
	int curl_flag=0;

	if (GetConnectionMode() == NET_M2M_WMMP)
	{
		DBG_ASSERT_EXIT(transMode->module!=TRANS_BY_CURL, ("CURL doesnot suport WMMP"));
		curl_flag = 0;
		pS = new SendByWmmp();
	}
	else
	{
		if (transMode->module == TRANS_BY_CURL)
		{
			curl_flag = 1;
		}
		else if (transMode->module == TRANS_BY_TRANSPROC)
		{
			pS = new SendBySocket();
		}
	}
	
	if (curl_flag == 0)
	{
		DBG_ASSERT_EXIT(pS!=NULL, ("pSending is NULL!!"));
		if (transMode->appProtocal == APP_LAYER_HTTP)
		{
			pT = new trans_http(pS);
		}
		else 
		{
			pT = new trans_direct(pS);
		}
	}
	else
	{
#if (_TRANS_MODULE_CURL != 0)
		pT = new trans_CURL();
#else
		DBG_ASSERT_EXIT(0, ("CURL not compile"));		
#endif
	}

	pT->SetDataKeepType(transMode->dataKeepType);

	*pNetTrans = pT;
	DBG_PRINT(("pT: %x", pT))

	return NET_SUCCESS;
	
}
예제 #3
0
/*
 * Function:     GetUserConnectMode
 * Description:  Get the user connection mode
 * Return:       0 for success or 1 for failure
 */
int wimaxcu_get_user_connect_mode(WIMAX_API_DEVICE_ID_P p_device_id)
{
	WIMAX_API_CONNECTION_MODE connectMode;
	WIMAX_API_RET wmxStatus;

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

	PrintUserConnectionMode(connectMode);
	return 0;
}
예제 #4
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;
}
예제 #5
0
/*
 * Function:     SetUserConnectMode
 * Description:  Change the user connect mode
 * Return:       0 for success or 1 for failure
 */
int wimaxcu_set_user_connect_mode(WIMAX_API_DEVICE_ID_P p_device_id,
		       char *connect_mode, char *scan_mode)
{
	int ret;
	WIMAX_API_RET wmxStatus;
	WIMAX_API_CONNECTION_MODE userConnectMode, currentConnectMode;
	WIMAX_API_DEVICE_STATUS DeviceStatus;
	WIMAX_API_CONNECTION_PROGRESS_INFO ConnectionProgressInfo;

	wmxStatus = GetConnectionMode(p_device_id, &currentConnectMode);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		PrintWmxStatus(wmxStatus);
		return 1;
	}

	userConnectMode = currentConnectMode;
	ret =
	    ConvertCharToConnectionMode(connect_mode, scan_mode,
					&userConnectMode);
	if (ret == -1) {
		printf("Specified Scan/Connect mode(s) not recognized.\n");
		PrintUserConnectionMode(currentConnectMode);
		return 1;
	} else if (ret == -2) {
		printf("WARNING: Invalid connect and scan combination.\n");
		printf("Auto connection requires semi scan mode.\n");
		PrintUserConnectionMode(currentConnectMode);
		return 1;
	}

	if (userConnectMode == currentConnectMode) {
		printf("The specified connect mode is already in place.\n");
		PrintUserConnectionMode(currentConnectMode);
		return 1;
	}
	if (ret == 1) {
		wmxStatus =
		    GetDeviceStatus(p_device_id, &DeviceStatus,
				    &ConnectionProgressInfo);
		if (WIMAX_API_RET_SUCCESS != wmxStatus) {
			PrintWmxStatus(wmxStatus);
			return 2;
		}
	}

	if((userConnectMode == WIMAX_API_CONNECTION_SEMI_MANUAL_SCAN_AUTO_CONNECT)&&((DeviceStatus==WIMAX_API_DEVICE_STATUS_RF_OFF_SW)||(DeviceStatus==WIMAX_API_DEVICE_STATUS_RF_OFF_HW)||(DeviceStatus==WIMAX_API_DEVICE_STATUS_RF_OFF_HW_SW))){
		printf("Error:Please turn the Radio On\n");
		return 1;
	}

	wmxStatus = SetConnectionMode(p_device_id, userConnectMode);
	if (WIMAX_API_RET_SUCCESS != wmxStatus) {
		// PrintWmxStatus(wmxStatus);
		if (WIMAX_API_RET_FAILED == wmxStatus) {
			BOOL isEnable;
			wmxStatus =
			    GetConnectedAsCurrentPreferredCapabilityStatus
			    (p_device_id, &isEnable);
			if (wmxStatus == WIMAX_API_RET_SUCCESS) {
				if (isEnable == FALSE) {
					printf
					    ("Current Connected Network Preferred settings are disabled\n");
					printf
					    ("Hence could not set the connect mode to Auto \n");
					printf
					    ("Going back to the pprevious connect mode \n");
					wmxStatus =
					    SetConnectionMode(p_device_id,
							      currentConnectMode);
					if (WIMAX_API_RET_SUCCESS != wmxStatus) {
						PrintWmxStatus(wmxStatus);
					} else {
						PrintUserConnectionMode
						    (currentConnectMode);
					}
					return 1;
				} else {
					printf("Operation Failed \n");
					return 1;
				}
			}
		}
		PrintWmxStatus(wmxStatus);
		return 1;
	}
	// Unset the preferred NSP
	if (userConnectMode == WIMAX_API_CONNECTION_MANUAL_SCAN_MANUAL_CONNECT) {
		g_preferred_NSP_ID = 0;
		SetCurrentPreferredProfiles(p_device_id, &g_preferred_NSP_ID, 0);
	}
	PrintUserConnectionMode(userConnectMode);
	
	return 0;
}