예제 #1
0
//--------------------------------------------------------------------------------------
CD3D11EnumOutputInfo* CD3D11Enumeration::GetOutputInfo( UINT AdapterOrdinal, UINT Output )
{
    CD3D11EnumAdapterInfo* pAdapterInfo = GetAdapterInfo( AdapterOrdinal );
    if( pAdapterInfo && pAdapterInfo->outputInfoList.GetSize() > int( Output ) )
    {
        return pAdapterInfo->outputInfoList.GetAt( Output );
    }

    return NULL;
}
예제 #2
0
DWORD WINAPI CLuzj_ZTEDlg::IpconfigRenew()
{

	int i;
	DWORD ret;
	char  adaptername[MAX_ADAPTER_NAME];
	int count = 0;

	DWORD dwOutBufLen = sizeof(IP_INTERFACE_INFO);
	PIP_INTERFACE_INFO pIfTable = (PIP_INTERFACE_INFO)malloc(dwOutBufLen);
	if(pIfTable == NULL) return -1;
	
	ret = GetInterfaceInfo(pIfTable, &dwOutBufLen);
	if(ret == ERROR_INSUFFICIENT_BUFFER) {
		free(pIfTable); pIfTable = (PIP_INTERFACE_INFO)malloc(dwOutBufLen);
		if(pIfTable == NULL) return -2;
		ret = GetInterfaceInfo(pIfTable, &dwOutBufLen);
	}

	if(ret != NO_ERROR) return -3;

	for(i = 0; i < pIfTable->NumAdapters; i++) {
		wcstombs(adaptername, pIfTable->Adapter[i].Name, MAX_ADAPTER_NAME);

		if(stricmp(adaptername, ToTCPName(Config.m_csNetCard)) == 0) {

			EnableDHCP(GetGUID(adaptername), true);
			
			while(1) {
				if(count <= MAX_DHCP_TIMES) Log(I_INFO, "fetching IP address by DHCP...");	
				IpReleaseAddress(&pIfTable->Adapter[i]);
				ret = IpRenewAddress(&pIfTable->Adapter[i]);
				if(ret == NO_ERROR) break;	
				if(count <= MAX_DHCP_TIMES) {
					if(count == MAX_DHCP_TIMES) {
						count++;
						Log(I_INFO, "dhcp keep quiet.");
					} else {
						Log(I_WARN, "fetch IP address failed. (%d)", ret); count++;
					}
				} 
				Sleep(10000);
			}
			
			char *info = GetAdapterInfo((LPCSTR)Config.m_csNetCard);
			if(info == NULL) Log(I_INFO, "GetAdapterInfo: NULL");
			else Log(I_INFO, info);		

			break;
		}	
	}

	free(pIfTable);
	return 0;
}
예제 #3
0
//--------------------------------------------------------------------------------------
_Use_decl_annotations_
CD3D11EnumOutputInfo* CD3D11Enumeration::GetOutputInfo( UINT AdapterOrdinal, UINT Output ) const
{
    CD3D11EnumAdapterInfo* pAdapterInfo = GetAdapterInfo( AdapterOrdinal );
    if( pAdapterInfo && pAdapterInfo->outputInfoList.size() > size_t( Output ) )
    {
        return pAdapterInfo->outputInfoList[ Output ];
    }

    return nullptr;
}
예제 #4
0
//--------------------------------------------------------------------------------------
CD3DEnumDeviceInfo* CD3DEnumeration::GetDeviceInfo( UINT AdapterOrdinal, D3DDEVTYPE DeviceType )
{
    CD3DEnumAdapterInfo* pAdapterInfo = GetAdapterInfo( AdapterOrdinal );
    if( pAdapterInfo )
    {
        for( NxI32 iDeviceInfo=0; iDeviceInfo<pAdapterInfo->deviceInfoList.GetSize(); iDeviceInfo++ )
        {
            CD3DEnumDeviceInfo* pDeviceInfo = pAdapterInfo->deviceInfoList.GetAt(iDeviceInfo);
            if( pDeviceInfo->DeviceType == DeviceType )
                return pDeviceInfo;
        }
    }

    return NULL;
}
예제 #5
0
//--------------------------------------------------------------------------------------
_Use_decl_annotations_
CD3D11EnumDeviceInfo* CD3D11Enumeration::GetDeviceInfo( UINT AdapterOrdinal, D3D_DRIVER_TYPE DeviceType ) const
{
    CD3D11EnumAdapterInfo* pAdapterInfo = GetAdapterInfo( AdapterOrdinal );
    if( pAdapterInfo )
    {
        for( auto it = pAdapterInfo->deviceInfoList.cbegin(); it != pAdapterInfo->deviceInfoList.cend(); ++it )
        {
            if( (*it)->DeviceType == DeviceType )
                return *it;
        }
    }

    return nullptr;
}
예제 #6
0
//--------------------------------------------------------------------------------------
_Use_decl_annotations_
CD3D11EnumDeviceSettingsCombo* CD3D11Enumeration::GetDeviceSettingsCombo( UINT AdapterOrdinal,
                                                                          DXGI_FORMAT BackBufferFormat, BOOL Windowed ) const
{
    CD3D11EnumAdapterInfo* pAdapterInfo = GetAdapterInfo( AdapterOrdinal );
    if( pAdapterInfo )
    {
        for( size_t iDeviceCombo = 0; iDeviceCombo < pAdapterInfo->deviceSettingsComboList.size(); iDeviceCombo++ )
        {
            CD3D11EnumDeviceSettingsCombo* pDeviceSettingsCombo = pAdapterInfo->deviceSettingsComboList[ iDeviceCombo ];
            if( pDeviceSettingsCombo->BackBufferFormat == BackBufferFormat &&
                pDeviceSettingsCombo->Windowed == Windowed )
                return pDeviceSettingsCombo;
        }
    }

    return nullptr;
}
예제 #7
0
//--------------------------------------------------------------------------------------
CD3D11EnumDeviceSettingsCombo* CD3D11Enumeration::GetDeviceSettingsCombo( UINT AdapterOrdinal,
                                                                          D3D_DRIVER_TYPE DeviceType, UINT Output,
                                                                          DXGI_FORMAT BackBufferFormat, BOOL Windowed )
{
    CD3D11EnumAdapterInfo* pAdapterInfo = GetAdapterInfo( AdapterOrdinal );
    if( pAdapterInfo )
    {
        for( int iDeviceCombo = 0; iDeviceCombo < pAdapterInfo->deviceSettingsComboList.GetSize(); iDeviceCombo++ )
        {
            CD3D11EnumDeviceSettingsCombo* pDeviceSettingsCombo = pAdapterInfo->deviceSettingsComboList.GetAt(
                iDeviceCombo );
            if( pDeviceSettingsCombo->BackBufferFormat == BackBufferFormat &&
                pDeviceSettingsCombo->Windowed == Windowed )
                return pDeviceSettingsCombo;
        }
    }

    return NULL;
}
예제 #8
0
static A_STATUS
AcquireWlanAdapter(ABF_WLAN_INFO *pAbfWlanInfo)
{
    int sd;
    A_STATUS status;

    if (pAbfWlanInfo->Handle != 0) {
        return A_OK;    
    }

    if ((sd = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
        A_ERR("[%s] Error creating socket: %d\n", __FUNCTION__, sd);
        return A_ERROR;
    }

    pAbfWlanInfo->Handle = sd;
    status = GetAdapterInfo(pAbfWlanInfo);
    if (A_FAILED(status)) {
        A_ERR("[%s] Failed to get Adapter Info\n", __FUNCTION__);
        close(sd);
        pAbfWlanInfo->Handle = 0;
        return A_ERROR;
    } else {
        /* Try to get RTS to determinate that wlan is enabled */
        A_UCHAR buf[sizeof(int)+sizeof(WMI_SET_RTS_CMD)];
        ((int *)buf)[0] = AR6000_XIOCTL_AP_GET_RTS;
        status = Abf_WlanDispatchIO(pAbfWlanInfo->pInfo, AR6000_IOCTL_EXTENDED, 
                                (void *)buf, sizeof(buf));
        if (A_FAILED(status)) {
            A_INFO("WMI is ready but wlan is disabled.\n");
            return A_ERROR;
        }
    }

    return A_OK;
}
예제 #9
0
/*
kd> dt ndis!_NDIS_PROTOCOL_BLOCK
+0x000 Header           : _NDIS_OBJECT_HEADER
+0x004 ProtocolDriverContext : Ptr32 Void
+0x008 NextProtocol     : Ptr32 _NDIS_PROTOCOL_BLOCK
+0x00c OpenQueue        : Ptr32 _NDIS_OPEN_BLOCK
win7
*/
BOOLEAN	EnumNetCards()
{
	PNDIS_MINIPORT_BLOCK pMiniBlock=NULL;
	PNDIS_COMMON_OPEN_BLOCK_2k3_early	pOpenBlock=NULL;

	ULONG	MiniDriverBlockHeader	;
	ULONG	NetCardType	=	0;
	LIST_ENTRY		*pListEntry=NULL;
	NETCARDS_INFO		*pNI=NULL;
	NTSTATUS			status = STATUS_SUCCESS;
	ULONG			uTmp=0;
	ADAPTER_INFOEX	*pAdapterInfoEx	=	NULL;
	ADAPTER_INFO	AI;
	WCHAR			*p1,*p2;
	ULONG			index=0;
	UNICODE_STRING	uniTmp;
	DWORD		dwVersion=0;


	

	PKK_NDIS_PROTOCOL_BLOCK	pProtocol	=	(PKK_NDIS_PROTOCOL_BLOCK)GetProtocolHeader();

	dwVersion = GetWindowsVersion();
	p1=p2=NULL;

	//清空列表
	if (!IsListEmpty(&g_NetCardsInfoHeader.Next))
	{
		ExInterlockedRemoveHeadList(&g_NetCardsInfoHeader.Next, &g_NetCardsInfoLock);
// 		LockResource(&g_NetCardsInfoLock, TRUE);
// 		pListEntry = RemoveHeadList(&g_NetCardsInfoHeader.Next);
// 		UnlockResource(&g_NetCardsInfoLock);
		pNI	=	CONTAINING_RECORD(pListEntry, NETCARDS_INFO, Next);
		if (NULL==pNI)
		{

			DbgBreakPoint();

		}
		RtlFreeAnsiString(&pNI->Name);
		kfree(pNI);
	}
	status	=	GetAdapterInfo(NULL, &uTmp);
	if (status==STATUS_BUFFER_TOO_SMALL)
	{
		pAdapterInfoEx	=	kmalloc(uTmp);
		RtlZeroMemory(pAdapterInfoEx, uTmp);
		if (NULL== pAdapterInfoEx)
		{
			return FALSE;
		}
	}
	status = GetAdapterInfo(pAdapterInfoEx, &uTmp);
	if (pAdapterInfoEx->uNumber==0)
	{
		kprintf("GetAdapterInfo() return pAdapterInfoEx->uNumber==0");
		kfree(pAdapterInfoEx);
		return FALSE;
	}

	while (pProtocol)	
	{
		//search for  the nic driver block
		if (dwVersion==Windows_7||dwVersion==Windows_Vista)
		{
			if (((PNDIS_PROTOCOL_BLOCKWin7)pProtocol)->OpenQueue==0)
			{
				goto NextBlock;
			}
		}
		else
		{
			if (pProtocol->OpenQueue==NULL)
			{
				goto NextBlock;
			}
		}

		uTmp=0;
		//现在使用了protocol链表,所以要防止一个miniport多次使用的情况
		if (dwVersion==Windows_Vista||dwVersion==Windows_7)
		{
			PNDIS_OPEN_BLOCKWIN7 pOP7	=	(PNDIS_OPEN_BLOCKWIN7)((PNDIS_PROTOCOL_BLOCKWin7)pProtocol)->OpenQueue;
			pMiniBlock	=	pOP7->MiniportHandle;
		}
		else
		{
			pMiniBlock	=	pProtocol->OpenQueue->MiniportHandle;
		}

		pListEntry	=	g_NetCardsInfoHeader.Next.Flink;
		while(pListEntry&& (pListEntry!=&g_NetCardsInfoHeader.Next))
		{
			pNI	=	CONTAINING_RECORD(pListEntry, NETCARDS_INFO, Next);
			if (pNI==NULL)
			{
				kprintf("Crash......when checking pMiniBlock is in g_NetCardsInfoHeader already\n");
				return FALSE;
			//	DbgBreakPoint();
			}
			if (pNI->pMiniBlock==pMiniBlock)
			{
				uTmp	=	1;
				break;
			}
			pListEntry	=	pListEntry->Flink;
		}
		if (uTmp==1)
		{
			//这个miniport已经使用过了
			goto NextBlock;
		}
		NetCardType		=	IsPhysicalMiniport(pMiniBlock);	//只取物理网卡
		if (NetCardType==0)
		{
			goto NextBlock;
		}
		
		pNI	=	kmalloc(sizeof(NETCARDS_INFO));
		RtlZeroMemory(pNI, sizeof(NETCARDS_INFO));
		if (NetCardType==1)
		{
			SetFlag(pNI->flag, REGULARNETCARD);
			
		}
		if (NetCardType==2)
		{
			SetFlag(pNI->flag, WIRELESSNETCARD);
		}
		/*
		p_mini_block->SymbolicLinkName
		亦可直接Createfile (p_mini_block->SymbolicLinkName....)发OID_802_3_CURRENT_ADDRESS来查询
		*/
		pNI->pMiniBlock	=	pMiniBlock;
		uTmp =0;
		
		for (index=0; index<pAdapterInfoEx->uNumber; index++)
		{
			p1	=	kmalloc(pMiniBlock->SymbolicLinkName.Length+2);
			RtlZeroMemory(p1, pMiniBlock->SymbolicLinkName.Length+2);
			RtlCopyMemory(p1, pMiniBlock->SymbolicLinkName.Buffer, pMiniBlock->SymbolicLinkName.Length);

			AI	=	pAdapterInfoEx->pAI[index];
			p2	=	kmalloc(AI.GUID.Length+2);
			RtlZeroMemory(p2, AI.GUID.Length+2);
			RtlCopyMemory(p2, AI.GUID.Buffer, AI.GUID.Length);
			_wcsupr(p1);_wcsupr(p2);
			if (wcsstr(p1,p2))
			{
				kfree(p1);kfree(p2);
				uTmp	=	1;
				break;	//找到了,已经获取网卡MAC地址
			}
			kfree(p1);kfree(p2);

		}//end for (index=0; index<pAdapterInfoEx->uNumber; index++)
		
		if (uTmp==1)
		{
			RtlCopyMemory(pNI->MacAddr, AI.macAddress, sizeof(pNI->MacAddr));
			pNI->IPAddr	=	 AI.IPAddr;
			pNI->GatewayIpAddr	=	 AI.GatewayIpAddr;
			if (pAdapterInfoEx->pAI[index].bDhcp)
			{
				SetFlag(pNI->flag, DHCPENABLE);
	
			}
			ExInterlockedInsertHeadList(&g_NetCardsInfoHeader.Next, &pNI->Next, &g_NetCardsInfoLock);
// 			LockResource(&g_NetCardsInfoLock, TRUE);
// 			InsertHeadList(&g_NetCardsInfoHeader.Next, &pNI->Next);
// 			UnlockResource(&g_NetCardsInfoLock);
		}
		else
		{
			kfree(pNI);
			pNI	=	NULL;
			goto NextBlock;

		}

// 		if ((p_mini_block->Flags&ISCONNECTED))
// 		{
// 			SetFlag(pNI->flag, ISCONNECTED);
// 		}
		if (AI.status==NdisMediaStateConnected)
		{
			SetFlag(pNI->flag, ISCONNECTED);
		}
		//HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Control\Network\{4D36E972-E325-11CE-BFC1-08002BE10318}

		GetNicNameByGUID(&AI.GUID, &uniTmp);
		RtlUnicodeStringToAnsiString(&pNI->Name, &uniTmp, TRUE);
		kprintf("\r\n 检举网卡信息如下:\r\nMAC : %02X:%02X:%02X:%02X:%02X:%02X   \nIP :0x%x   \nflag:0X%X  \n网关IP:0x%x   \nName: %Z \n\n", pNI->MacAddr[0], pNI->MacAddr[1], pNI->MacAddr[2], pNI->MacAddr[3], pNI->MacAddr[4], pNI->MacAddr[5], (pNI->IPAddr), pNI->flag, (pNI->GatewayIpAddr),&pNI->Name);


NextBlock:
		if (dwVersion==Windows_Vista||dwVersion==Windows_7)
		{
			pProtocol	=	(PKK_NDIS_PROTOCOL_BLOCK )((PNDIS_PROTOCOL_BLOCKWin7)pProtocol)->NextProtocol;
		}
		else
		pProtocol	=	pProtocol->NextProtocol;
	}	//end  while (p_driver_block->NextDriver)	
	

	//释放上面申请的内容
	for (index=0; index<pAdapterInfoEx->uNumber; index++)
	{
		kfree(pAdapterInfoEx->pAI[index].GUID.Buffer);

	}
	kfree(pAdapterInfoEx);

	return 1;
}