int CNetManager::init(string &strErr) { INT32 ret=0; INT32 netMode=NET_NONE; INT32 netModeL2=NET_NONE; CNetConnection *handle=NULL; //设置当前网络模式 if (CNetDBWork::loadNetMode(&netMode, strErr) != SQLITE_OK) { DBG_PRINT(("未设置网络模式, strErr=%s", strErr.c_str())) netMode=NET_NONE; } DBG_PRINT(("netMode=%d", netMode)) if ((ret=SetConnectionMode(netMode, &handle, strErr)) != NET_SUCCESS) { return ret; } //第二层只支持VPN模式。 //只要_CONFIG_VPN_MODULE宏开启,则强制设为VPN,否则强制设为NONE。by zl 20131015 if (CNetDBWork::loadNetModeL2(&netModeL2, strErr) != SQLITE_OK) { DBG_PRINT(("未设置二次拨号网络模式, strErr=%s", strErr.c_str())) netModeL2=NET_NONE; } #if (_CONFIG_VPN_MODULE != 0) if (netModeL2 != NET_VPN) { CNetDBWork::saveNetModeL2(NET_VPN, strErr); netModeL2=NET_VPN; } #else if (netModeL2 != NET_NONE) { CNetDBWork::saveNetModeL2(NET_NONE, strErr); netModeL2=NET_NONE; } #endif DBG_PRINT(("netModeL2=%d", netModeL2)) if ((ret=SetConnectionModeL2(netModeL2, &handle, strErr)) != NET_SUCCESS) { return ret; } //获取默认服务器IP CNetDBWork::loadAPPServerIP(m_defServerIP, m_defServerPort, strErr); if (m_defServerFile == "") m_defServerFile.assign(SERVER_FILE_DEF); //开机自动拨号过程 if ((ret=autoDialProc(strErr)) != NET_SUCCESS) { return ret; } return NET_SUCCESS; }
//----------------------------------------------------- // // MAIN // //----------------------------------------------------- int main(int argc, char *argv[]) { DWORD dwNumChars; int dDirectMode; if (argc != 2) { Syntax(); } // // Retrieve the computer name. // dwNumChars = MAX_COMPUTERNAME_LENGTH; if(!GetComputerName(mbsMachineName, &dwNumChars)) { printf("Failed to get computer name. Exiting...\n"); exit(1); } // // Detect a DS connection and determine the working mode. // dDirectMode = SetConnectionMode(); if(strcmp(argv[1], "-s") == 0) Sender(dDirectMode); else if (strcmp(argv[1], "-r") == 0) Receiver(dDirectMode); else Syntax(); printf("\nOK\n"); return(0); }
/* * Initialize the WiMAX API, register with it, setup callbacks * */ static int iwmx_sdk_setup(struct wmxsdk *wmxsdk) { int result, status; WIMAX_API_RET r; char errstr[512]; UINT32 errstr_size = sizeof(errstr); result = -ENFILE; /* device_id initialized by iwmx_sdk_dev_add */ r = WiMaxDeviceOpen(&wmxsdk->device_id); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot open device: %d (%s)", r, errstr); goto error_wimaxdeviceopen; } /* * We scan in auto mode (in the background) * * Otherwise is messy -- if we have NetworkManager triggering a scan * when we call iwmx_nm_scan() -> iwmx_sdk_scan(), most of the * times that causes a race condition when the UI asks for a * scan right before displaying the network menu. As there is * no way to cancel an ongoing scan before connecting, we are * stuck. So we do auto bg and have iwmx_sdk_scan() just return * the current network list. */ r = SetConnectionMode(&wmxsdk->device_id, WIMAX_API_CONNECTION_AUTO_SCAN_MANUAL_CONNECT); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot set connectin mode to manual: %d (%s)", r, errstr); goto error_connection_mode; } r = SubscribeControlPowerManagement(&wmxsdk->device_id, __iwmx_sdk_rf_state_cb); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot subscribe to radio change events: %u (%s)", r, errstr); result = -EIO; goto error_subscribe_rf_state; } r = SubscribeDeviceStatusChange(&wmxsdk->device_id, __iwmx_sdk_state_change_cb); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot subscribe to state chaneg events: %d (%s)", r, errstr); goto error_subscribe_state_change; } r = SubscribeNetworkSearchWideScanEx(&wmxsdk->device_id, __iwmx_sdk_wide_scan_cb); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot subscribe to wide scan events: %d (%s)", r, errstr); goto error_subscribe_wide_scan; } r = SubscribeNetworkSearchEx(&wmxsdk->device_id, __iwmx_sdk_scan_cb); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot subscribe to scan events: %d (%s)", r, errstr); goto error_subscribe_scan; } r = SubscribeConnectToNetwork(&wmxsdk->device_id, __iwmx_sdk_connect_cb); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot subscribe to connect events: %d (%s)", r, errstr); goto error_subscribe_connect; } r = SubscribeDisconnectToNetwork(&wmxsdk->device_id, __iwmx_sdk_disconnect_cb); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot subscribe to disconnect events: %d (%s)", r, errstr); goto error_subscribe_disconnect; } r = SubscribeMediaStatusUpdate(&wmxsdk->device_id, __iwmx_sdk_media_status_update_cb); if (r != WIMAX_API_RET_SUCCESS) { GetErrorString(&wmxsdk->device_id, r, errstr, &errstr_size); nm_log_err(LOGD_WIMAX, "wmxsdk: Cannot subscribe to media status events: %d (%s)", r, errstr); goto error_subscribe_media_status; } status = iwmx_sdk_get_device_status(wmxsdk); if ((int) status < 0) status = WIMAX_API_DEVICE_STATUS_UnInitialized; g_mutex_lock(&wmxsdk->status_mutex); wmxsdk->status = status; g_mutex_unlock(&wmxsdk->status_mutex); _schedule_state_change(wmxsdk, status, WIMAX_API_DEVICE_STATUS_UnInitialized, WIMAX_API_STATUS_REASON_Normal, WIMAX_API_DEVICE_CONNECTION_PROGRESS_Ranging); return 0; UnsubscribeMediaStatusUpdate(&wmxsdk->device_id); error_subscribe_media_status: UnsubscribeDisconnectToNetwork(&wmxsdk->device_id); error_subscribe_disconnect: UnsubscribeConnectToNetwork(&wmxsdk->device_id); error_subscribe_connect: UnsubscribeNetworkSearchEx(&wmxsdk->device_id); error_subscribe_scan: UnsubscribeNetworkSearchWideScanEx(&wmxsdk->device_id); error_subscribe_wide_scan: UnsubscribeDeviceStatusChange(&wmxsdk->device_id); error_subscribe_state_change: UnsubscribeControlPowerManagement(&wmxsdk->device_id); error_subscribe_rf_state: error_connection_mode: WiMaxDeviceClose(&wmxsdk->device_id); error_wimaxdeviceopen: return result; }
/* Function: GetNetworkList(WIMAX_API_DEVICE_ID_P p_device_id) Purpose: This API casuses the device to perform a scan operation and returns a list of detected NSPs. This is a blocking API. It returns to the caller after a single full scan cycle is completed. Parameters: WIMAX_API_DEVICE_ID_P p_device_id - device info like device index, permission etc */ int wimaxcu_get_network_list(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_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 = SubscribeNetworkSearch(p_device_id, &ind_network_search_cb); 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_P) malloc(MAX_LEN * sizeof(WIMAX_API_NSP_INFO)); memset(pNspInfo, 0, sizeof(WIMAX_API_NSP_INFO) * MAX_LEN); wmxStatus = GetNetworkList(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"); PrintNSPInfo(&pNspInfo[i]); if (wimaxcu_is_network_activated (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; } // // } else { // printf("1No networks found.\n"); // break; // } if (time_out > SCAN_TIMEOUT_IN_10SEC_ITREATIONS) { if (g_noNetworksFound == 1) { printf ("\n No networks found.\n"); } else { printf ("\n Scan Operation timeout.\n"); // As Scan operation timed out ret = 1; } break; } } else { break; } } while (1); } else if (scan_mode == CMD_SCAN_ARG_WIDE) { // Get User Connect Mode WIMAX_API_CONNECTION_MODE userConnectMode; wmxStatus = GetConnectionMode(p_device_id, &userConnectMode); if (WIMAX_API_RET_SUCCESS != wmxStatus) { PrintWmxStatus(wmxStatus); return 1; } if ((connectMode == WIMAX_API_CONNECTION_SEMI_MANUAL_SCAN_AUTO_CONNECT) || (connectMode == WIMAX_API_CONNECTION_AUTO_SCAN_AUTO_CONNECT) || (connectMode == WIMAX_API_CONNECTION_SEMI_MANUAL_SCAN_MANUAL_CONNECT)) { if (connectMode == WIMAX_API_CONNECTION_SEMI_MANUAL_SCAN_MANUAL_CONNECT) { printf ("Changing Scan mode to Manual Scan mode \n"); } else { printf("Changing Scan mode to manual \n"); printf("Changing Connect mode to manual \n"); } userConnectMode = WIMAX_API_CONNECTION_MANUAL_SCAN_MANUAL_CONNECT; wmxStatus = SetConnectionMode(p_device_id, userConnectMode); if (WIMAX_API_RET_SUCCESS != wmxStatus) { PrintWmxStatus(wmxStatus); return 1; } } wmxStatus = SubscribeNetworkSearchWideScan(p_device_id, &ind_network_search_wide_scan_cb); 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 = UnsubscribeNetworkSearch(p_device_id); if (WIMAX_API_RET_SUCCESS != wmxStatus) { PrintWmxStatus(wmxStatus); return 2; } wmxStatus = UnsubscribeNetworkSearchWideScan(p_device_id); if (WIMAX_API_RET_SUCCESS != wmxStatus) { PrintWmxStatus(wmxStatus); return 2; } return ret; }
/* * 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, ¤tConnectMode); 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; }
ATIDAQHardwareInterface::ATIDAQHardwareInterface() { this->m_thDAQTask = new TaskHandle; SetConnectionMode( DAQmx_Val_Diff ); }