Ejemplo n.º 1
0
//005543f0	-> 100%
void CMasterLevelSystem::GDReqMasterLevelInfoSave(LPOBJ lpObj)	//OK
{
	if( !lpObj->m_bMasterLevelDBLoad )
	{
		return;
	}
	// ----
	MLP_REQ_MASTERLEVEL_INFOSAVE pMsg;
	pMsg.h.set((LPBYTE)&pMsg, 0x31, sizeof(MLP_REQ_MASTERLEVEL_INFOSAVE));
	// ----
	memcpy(pMsg.szCharName, lpObj->Name, MAX_IDSTRING);
	pMsg.szCharName[MAX_IDSTRING] = 0;
	pMsg.nMLevel		= lpObj->m_nMasterLevel;
	pMsg.i64MLExp		= lpObj->m_i64MasterLevelExp;
	pMsg.i64NextMLExp	= lpObj->m_i64NextMasterLevelExp;
	pMsg.nMLPoint		= LOWORD(lpObj->m_iMasterLevelPoint);
	// ----
	cDBSMng.Send((char*)&pMsg, pMsg.h.size);
	// ----
	LogAddTD("[%s][%s] MasterLevel Info Save [MLevel:%d][MLExp:%I64d][MLNextExp:%I64d][MLPoint:%d]",
		lpObj->AccountID, lpObj->Name, lpObj->m_nMasterLevel, 
		LODWORD(lpObj->m_i64MasterLevelExp), HIDWORD(lpObj->m_i64MasterLevelExp), 
		LODWORD(lpObj->m_i64NextMasterLevelExp), HIDWORD(lpObj->m_i64NextMasterLevelExp),
		lpObj->m_iMasterLevelPoint);
}
Ejemplo n.º 2
0
BOOL ReadSectors( HANDLE hDevice, ULONGLONG ullStartSector, DWORD dwSectors, DWORD dwBytesPerSector, LPBYTE lpSectBuff, LPOVERLAPPED lpOverlap, DWORD *pdwErrorCode )
{
	ULONGLONG ullOffset = ullStartSector * dwBytesPerSector;
	DWORD dwLen = dwSectors * dwBytesPerSector;
	DWORD dwReadLen = 0;
	DWORD dwErrorCode = 0;

	if (lpOverlap)
	{
		lpOverlap->Offset = LODWORD(ullOffset);
		lpOverlap->OffsetHigh = HIDWORD(ullOffset);
	}
	else
	{
		LARGE_INTEGER liFileSize = {0};
		liFileSize.QuadPart = (LONGLONG)ullOffset;

		if (!SetFilePointerEx(hDevice,liFileSize,NULL,FILE_BEGIN))
		{
			*pdwErrorCode = GetLastError();
			return FALSE;
		}
	}

	if (!ReadFile(hDevice,lpSectBuff,dwLen,&dwReadLen,lpOverlap))
	{
		dwErrorCode = ::GetLastError();

		if(dwErrorCode == ERROR_IO_PENDING) // 结束异步I/O
		{
			if (WaitForSingleObject(lpOverlap->hEvent, INFINITE) != WAIT_FAILED)
			{
				if(!::GetOverlappedResult(hDevice, lpOverlap, &dwReadLen, FALSE))
				{
					*pdwErrorCode = ::GetLastError();
					return FALSE;
				}
				else
				{
					return TRUE;
				}
			}
			else
			{
				*pdwErrorCode = ::GetLastError();
				return FALSE;
			}

		}
		else
		{
			*pdwErrorCode = dwErrorCode;
			return FALSE;
		}
	}
	else
	{
		return TRUE;
	}
}
Ejemplo n.º 3
0
BOOL WriteFileAsyn( HANDLE hFile, ULONGLONG ullOffset, DWORD &dwSize, LPBYTE lpBuffer, LPOVERLAPPED lpOverlap, PDWORD pdwErrorCode )
{
	DWORD dwWriteLen = 0;
	DWORD dwErrorCode = 0;

	if (lpOverlap)
	{
		lpOverlap->Offset = LODWORD(ullOffset);
		lpOverlap->OffsetHigh = HIDWORD(ullOffset);
	}
	else
	{
		LARGE_INTEGER liFileSize = {0};
		liFileSize.QuadPart = (LONGLONG)ullOffset;

		if (!SetFilePointerEx(hFile,liFileSize,NULL,FILE_BEGIN))
		{
			*pdwErrorCode = GetLastError();
			return FALSE;
		}
	}

	if (!WriteFile(hFile,lpBuffer,dwSize,&dwWriteLen,lpOverlap))
	{
		dwErrorCode = ::GetLastError();

		if(dwErrorCode == ERROR_IO_PENDING) // 结束异步I/O
		{
			if (WaitForSingleObject(lpOverlap->hEvent, INFINITE) != WAIT_FAILED)
			{
				if(!::GetOverlappedResult(hFile, lpOverlap, &dwWriteLen, FALSE))
				{
					*pdwErrorCode = ::GetLastError();
					return FALSE;
				}
				else
				{
					dwSize = dwWriteLen;
					return TRUE;
				}
			}
			else
			{
				*pdwErrorCode = ::GetLastError();
				return FALSE;
			}

		}
		else
		{
			*pdwErrorCode = dwErrorCode;
			return FALSE;
		}
	}
	else
	{
		dwSize = dwWriteLen;
		return TRUE;
	}
}
Ejemplo n.º 4
0
// Completes a frame-step operation.
HRESULT EVRCustomPresenter::CompleteFrameStep(IMFSample *pSample)
{
  HRESULT hr = S_OK;
  MFTIME hnsSampleTime = 0;
  MFTIME hnsSystemTime = 0;

  // Update our state.
  m_FrameStep.state = FRAMESTEP_COMPLETE;
  m_FrameStep.pSampleNoRef = NULL;

  // Notify the EVR that the frame-step is complete.
  NotifyEvent(EC_STEP_COMPLETE, FALSE, 0); // FALSE = completed (not cancelled)

  // If we are scrubbing (rate == 0), also send the "scrub time" event.
  if (IsScrubbing())
  {
    // Get the time stamp from the sample.
    hr = pSample->GetSampleTime(&hnsSampleTime);
    if (FAILED(hr))
    {
      // No time stamp. Use the current presentation time.
      if (m_pClock)
      {
        hr = m_pClock->GetCorrelatedTime(0, &hnsSampleTime, &hnsSystemTime);
      }
      hr = S_OK; // Not an error condition.
    }

    NotifyEvent(EC_SCRUB_TIME, LODWORD(hnsSampleTime), HIDWORD(hnsSampleTime));
  }

  return hr;
}
Ejemplo n.º 5
0
void *MMapFile::get(__int64 offset, int *sizep) const
{
  if (!sizep)
    return NULL;

  assert(!m_pView);

  int size = *sizep;

  if (!m_iSize || offset + size > m_iSize)
  {
    extern void quit(); extern int g_display_errors;
    if (g_display_errors) 
    {
      PrintColorFmtMsg_ERR(_T("\nInternal compiler error #12345: error mmapping file (%I64d, %d) is out of range.\n"), offset, size);
    }
    quit();
  }

  // fix offset
  __int64 alignedoffset = offset - (offset % m_iAllocationGranularity);
  size += offset - alignedoffset;

#ifdef _WIN32
  assert(MAKEQWORD(LODWORD(alignedoffset),HIDWORD(alignedoffset)) == alignedoffset);
  m_pView = MapViewOfFile(m_hFileMap, m_bReadOnly ? FILE_MAP_READ : FILE_MAP_WRITE, HIDWORD(alignedoffset), LODWORD(alignedoffset), size);
#else
  m_pView = mmap(0, size, m_bReadOnly ? PROT_READ : PROT_READ | PROT_WRITE, MAP_SHARED, m_hFileDesc, alignedoffset);
  m_iMappedSize = *sizep = size;
#endif

#ifdef _WIN32
  if (!m_pView)
#else
  if (m_pView == MAP_FAILED)
#endif
  {
    extern void quit(); extern int g_display_errors;
    if (g_display_errors) 
    {
      PrintColorFmtMsg_ERR(_T("\nInternal compiler error #12345: error mmapping datablock to %d.\n"), size);
    }
    quit();
  }

  return (void *)((char *)m_pView + offset - alignedoffset);
}
Ejemplo n.º 6
0
LPVOID GetRelativeBranchDestination(LPVOID lpInst,hdes *hs)
{
#ifdef _AMD64_
    return (LPVOID)MAKEDWORDLONG((LODWORD(lpInst)+hs->len+hs->imm.imm32),HIDWORD(lpInst));
#else
    return (LPVOID)((DWORD)lpInst+hs->len+hs->imm.imm32);
#endif
}
Ejemplo n.º 7
0
VOID
MEMvAllocateShared(
	PSAllocMap pamMem
	)
{
	if (!g_bInit)
		pamMem->dwRawVAddr = (DWORD)mALLOc((size_t)pamMem->dwRawSize * (size_t)sizeof(BYTE));

	/* If allocation failed, virtual/phisical address == NULL */
	if ((PVOID)pamMem->dwRawVAddr == NULL) {
		LODWORD(pamMem->qwRawPAddr) = 0;
		HIDWORD(pamMem->qwRawPAddr) = 0;
		return;
	} else
		memset((PVOID)pamMem->dwRawVAddr, 0, (size_t)pamMem->dwRawSize * (size_t)sizeof(BYTE));

	LODWORD(pamMem->qwRawPAddr) = pamMem->dwRawVAddr;
	HIDWORD(pamMem->qwRawPAddr) = 0;
}
Ejemplo n.º 8
0
Archivo: utdebug.c Proyecto: nhanh0/hah
void
acpi_ut_value_exit (
    u32                     line_number,
    acpi_debug_print_info   *dbg_info,
    acpi_integer            value)
{

    acpi_ut_debug_print (ACPI_LV_FUNCTIONS, line_number, dbg_info,
                         "%s %8.8X%8.8X\n", acpi_gbl_fn_exit_str, HIDWORD(value), LODWORD(value));

    acpi_gbl_nesting_level--;
}
Ejemplo n.º 9
0
void CGestures::DumpGesture(LPCWSTR tp, const GESTUREINFO& gi)
{
	wchar_t szDump[256];

	_wsprintf(szDump, SKIPLEN(countof(szDump))
		L"Gesture(x%08X {%i,%i} %s",
		(DWORD)gi.hwndTarget, gi.ptsLocation.x, gi.ptsLocation.y,
		tp); // tp - имя жеста

	switch (gi.dwID)
	{
	case GID_PRESSANDTAP:
		{
			DWORD h = LODWORD(gi.ullArguments); _wsprintf(szDump+_tcslen(szDump), SKIPLEN(32)
				L" Dist={%i,%i}", (int)(short)LOWORD(h), (int)(short)HIWORD(h));
			break;
		}

	case GID_ROTATE:
		{
			DWORD h = LODWORD(gi.ullArguments); _wsprintf(szDump+_tcslen(szDump), SKIPLEN(32)
				L" %i", (int)LOWORD(h));
			break;
		}
	}

	if (gi.dwFlags&GF_BEGIN)
		wcscat_c(szDump, L" GF_BEGIN");

	if (gi.dwFlags&GF_END)
		wcscat_c(szDump, L" GF_END");

	if (gi.dwFlags&GF_INERTIA)
	{
		wcscat_c(szDump, L" GF_INERTIA");
		DWORD h = HIDWORD(gi.ullArguments); _wsprintf(szDump+_tcslen(szDump), SKIPLEN(32)
			L" {%i,%i}", (int)(short)LOWORD(h), (int)(short)HIWORD(h));
	}



	if (gpSetCls->isAdvLogging >= 2)
	{
		gpConEmu->LogString(szDump);
	}
	else
	{
		#ifdef USE_DUMPGEST
		wcscat_c(szDump, L")\n");
		DEBUGSTR(szDump);
		#endif
	}
}
Ejemplo n.º 10
0
int MMapFile::setfile(int hFile, __int64 dwSize)
#endif
{
  clear();

#ifdef _WIN32
  m_hFile = hFile;
#else
  m_hFileDesc = hFile;
#endif
  m_bTempHandle = FALSE;

#ifdef _WIN32
  if (m_hFile == INVALID_HANDLE_VALUE)
#else
  if (m_hFileDesc == -1)
#endif
    return 0;

  m_iSize = dwSize;

  if (m_iSize <= 0)
    return 0;

#ifdef _WIN32
  assert(MAKEQWORD(LODWORD(m_iSize),HIDWORD(m_iSize)) == m_iSize);
  m_hFileMap = CreateFileMapping(m_hFile, NULL, PAGE_READONLY, HIDWORD(m_iSize), LODWORD(m_iSize) , NULL);

  if (!m_hFileMap)
    return 0;
#endif

  m_bReadOnly = TRUE;

  return 1;
}
Ejemplo n.º 11
0
acpi_status
acpi_ex_system_io_space_handler (
	u32                     function,
	ACPI_PHYSICAL_ADDRESS   address,
	u32                     bit_width,
	u32                     *value,
	void                    *handler_context,
	void                    *region_context)
{
	acpi_status             status = AE_OK;


	FUNCTION_TRACE ("Ex_system_io_space_handler");


	ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
		"System_iO %d (%d width) Address=%8.8X%8.8X\n", function, bit_width,
		HIDWORD (address), LODWORD (address)));

	/* Decode the function parameter */

	switch (function) {

	case ACPI_READ_ADR_SPACE:

		*value = 0;
		status = acpi_os_read_port ((ACPI_IO_ADDRESS) address, value, bit_width);
		break;


	case ACPI_WRITE_ADR_SPACE:

		status = acpi_os_write_port ((ACPI_IO_ADDRESS) address, *value, bit_width);
		break;


	default:
		status = AE_BAD_PARAMETER;
		break;
	}

	return_ACPI_STATUS (status);
}
Ejemplo n.º 12
0
//00554540	-> 100%
void CMasterLevelSystem::GCMasterLevelInfo(LPOBJ lpObj)	//OK
{
	if( !lpObj->m_bMasterLevelDBLoad )
	{
		this->GDReqMasterLevelInfo(lpObj);
		return;
	}
	// ----
	PMSG_MASTERLEVEL_INFO pMsg;
	PHeadSubSetB(&pMsg.h.c, 0xF3, 0x50, sizeof(PMSG_MASTERLEVEL_INFO));
	// ----
	pMsg.nMLevel		= lpObj->m_nMasterLevel;
	// ----
	pMsg.btMLExp1		= SET_NUMBERH(SET_NUMBERHW(HIDWORD(lpObj->m_i64MasterLevelExp)));
	pMsg.btMLExp2		= SET_NUMBERL(SET_NUMBERHW(HIDWORD(lpObj->m_i64MasterLevelExp)));
	pMsg.btMLExp3		= SET_NUMBERH(SET_NUMBERLW(HIDWORD(lpObj->m_i64MasterLevelExp)));
	pMsg.btMLExp4		= SET_NUMBERL(SET_NUMBERLW(HIDWORD(lpObj->m_i64MasterLevelExp)));
	pMsg.btMLExp5		= SET_NUMBERH(SET_NUMBERHW(LODWORD(lpObj->m_i64MasterLevelExp)));
	pMsg.btMLExp6		= SET_NUMBERL(SET_NUMBERHW(LODWORD(lpObj->m_i64MasterLevelExp)));
	pMsg.btMLExp7		= SET_NUMBERH(SET_NUMBERLW(LODWORD(lpObj->m_i64MasterLevelExp)));
	pMsg.btMLExp8		= SET_NUMBERL(SET_NUMBERLW(LODWORD(lpObj->m_i64MasterLevelExp)));
	// ----
	pMsg.btMLNextExp1	= SET_NUMBERH(SET_NUMBERHW(HIDWORD(lpObj->m_i64NextMasterLevelExp)));
	pMsg.btMLNextExp2	= SET_NUMBERL(SET_NUMBERHW(HIDWORD(lpObj->m_i64NextMasterLevelExp)));
	pMsg.btMLNextExp3	= SET_NUMBERH(SET_NUMBERLW(HIDWORD(lpObj->m_i64NextMasterLevelExp)));
	pMsg.btMLNextExp4	= SET_NUMBERL(SET_NUMBERLW(HIDWORD(lpObj->m_i64NextMasterLevelExp)));
	pMsg.btMLNextExp5	= SET_NUMBERH(SET_NUMBERHW(LODWORD(lpObj->m_i64NextMasterLevelExp)));
	pMsg.btMLNextExp6	= SET_NUMBERL(SET_NUMBERHW(LODWORD(lpObj->m_i64NextMasterLevelExp)));
	pMsg.btMLNextExp7	= SET_NUMBERH(SET_NUMBERLW(LODWORD(lpObj->m_i64NextMasterLevelExp)));
	pMsg.btMLNextExp8	= SET_NUMBERL(SET_NUMBERLW(LODWORD(lpObj->m_i64NextMasterLevelExp)));
	// ----
	pMsg.nMLPoint		= LOWORD(lpObj->m_iMasterLevelPoint);
	pMsg.wMaxLife		= (double)lpObj->AddLife + lpObj->MaxLife;
	pMsg.wMaxMana		= (double)lpObj->AddMana + lpObj->MaxMana;
	pMsg.wMaxShield		= LOWORD(lpObj->iAddShield) + LOWORD(lpObj->iMaxShield);
	pMsg.wMaxBP			= LOWORD(lpObj->AddBP) + LOWORD(lpObj->MaxBP);
	// ----
	DataSend(lpObj->m_Index, (LPBYTE)&pMsg, pMsg.h.size);
}
Ejemplo n.º 13
0
// -----------------------------------------------------------------------------------------------------------------------------------------
void CSkillTree::SendMasterData(int iIndex)
{
	LPOBJ lpObj = &gObj[iIndex];

	if ( gUser.gObjIsMasteringLevel(lpObj) == false )
	{
		return;
	}

	PMSG_MASTERLEVEL_SEND pMsg;

	pMsg.h.set((LPBYTE)&pMsg,0xF3,0x50,sizeof(pMsg));
	pMsg.MasterLevel = lpObj->MasterLevel;
	pMsg.MasterExp[0] = HIBYTE(HIWORD(HIDWORD(lpObj->MLExperience))); // Highest BYTE
	pMsg.MasterExp[1] = LOBYTE(HIWORD(HIDWORD(lpObj->MLExperience)));
	pMsg.MasterExp[2] = HIBYTE(LOWORD(HIDWORD(lpObj->MLExperience)));
	pMsg.MasterExp[3] = LOBYTE(LOWORD(HIDWORD(lpObj->MLExperience)));
	pMsg.MasterExp[4] = HIBYTE(HIWORD(LODWORD(lpObj->MLExperience)));
	pMsg.MasterExp[5] = LOBYTE(HIWORD(LODWORD(lpObj->MLExperience)));
	pMsg.MasterExp[6] = HIBYTE(LOWORD(LODWORD(lpObj->MLExperience)));
	pMsg.MasterExp[7] = LOBYTE(LOWORD(LODWORD(lpObj->MLExperience))); // Lowest BYTE
	pMsg.MasterNextExp[0] = HIBYTE(HIWORD(HIDWORD(lpObj->MLNextExp))); // Highest BYTE
	pMsg.MasterNextExp[1] = LOBYTE(HIWORD(HIDWORD(lpObj->MLNextExp)));
	pMsg.MasterNextExp[2] = HIBYTE(LOWORD(HIDWORD(lpObj->MLNextExp)));
	pMsg.MasterNextExp[3] = LOBYTE(LOWORD(HIDWORD(lpObj->MLNextExp)));
	pMsg.MasterNextExp[4] = HIBYTE(HIWORD(LODWORD(lpObj->MLNextExp)));
	pMsg.MasterNextExp[5] = LOBYTE(HIWORD(LODWORD(lpObj->MLNextExp)));
	pMsg.MasterNextExp[6] = HIBYTE(LOWORD(LODWORD(lpObj->MLNextExp)));
	pMsg.MasterNextExp[7] = LOBYTE(LOWORD(LODWORD(lpObj->MLNextExp))); // Lowest BYTE
	pMsg.MasterPoints = lpObj->MasterPoints;
	pMsg.MaxLife = lpObj->MaxLife+lpObj->AddLife;
	pMsg.MaxMana = lpObj->MaxMana+lpObj->AddMana;
	pMsg.iMaxShield = lpObj->iMaxShield+lpObj->iAddShield;
	pMsg.MaxBP = lpObj->MaxBP+lpObj->AddBP;

	gSendProto.DataSend(iIndex, (UCHAR*)&pMsg, pMsg.h.size);
}
Ejemplo n.º 14
0
/*
 * Description:
 *      Set WPA algorithm & keys
 *
 * Parameters:
 *  In:
 *      pDevice -
 *      param -
 *  Out:
 *
 * Return Value:
 *
 */
int wpa_set_keys(PSDevice pDevice, void *ctx)
{
	struct viawget_wpa_param *param = ctx;
	PSMgmtObject pMgmt = &pDevice->sMgmtObj;
	DWORD dwKeyIndex = 0;
	BYTE abyKey[MAX_KEY_LEN];
	BYTE abySeq[MAX_KEY_LEN];
	QWORD KeyRSC;
	BYTE byKeyDecMode = KEY_CTL_WEP;
	int ret = 0;
	int uu;
	int ii;

	if (param->u.wpa_key.alg_name > WPA_ALG_CCMP)
		return -EINVAL;

	DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "param->u.wpa_key.alg_name = %d \n",
		param->u.wpa_key.alg_name);
	if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
		pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
		pDevice->bEncryptionEnable = FALSE;
		pDevice->byKeyIndex = 0;
		pDevice->bTransmitKey = FALSE;
		for (uu=0; uu<MAX_KEY_TABLE; uu++) {
			MACvDisableKeyEntry(pDevice, uu);
		}
		return ret;
	}

	if (param->u.wpa_key.key && param->u.wpa_key.key_len > sizeof(abyKey))
		return -EINVAL;

	memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len);

	dwKeyIndex = (DWORD)(param->u.wpa_key.key_index);

	if (param->u.wpa_key.alg_name == WPA_ALG_WEP) {
		if (dwKeyIndex > 3) {
			return -EINVAL;
		} else {
			if (param->u.wpa_key.set_tx) {
				pDevice->byKeyIndex = (BYTE)dwKeyIndex;
				pDevice->bTransmitKey = TRUE;
				dwKeyIndex |= (1 << 31);
			}
			KeybSetDefaultKey(  pDevice,
					&(pDevice->sKey),
					dwKeyIndex & ~(BIT30 | USE_KEYRSC),
					param->u.wpa_key.key_len,
					NULL,
					abyKey,
					KEY_CTL_WEP
				);

		}
		pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
		pDevice->bEncryptionEnable = TRUE;
		return ret;
	}


	if (param->u.wpa_key.seq && param->u.wpa_key.seq_len > sizeof(abySeq))
		return -EINVAL;

	memcpy(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len);

	if (param->u.wpa_key.seq_len > 0) {
		for (ii = 0 ; ii < param->u.wpa_key.seq_len ; ii++) {
			if (ii < 4)
				LODWORD(KeyRSC) |= (abySeq[ii] << (ii * 8));
			else
				HIDWORD(KeyRSC) |= (abySeq[ii] << ((ii-4) * 8));
		}
		dwKeyIndex |= 1 << 29;
	}

	if (param->u.wpa_key.key_index >= MAX_GROUP_KEY) {
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return  dwKeyIndex > 3\n");
		return -EINVAL;
	}

	if (param->u.wpa_key.alg_name == WPA_ALG_TKIP) {
		pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
	}

	if (param->u.wpa_key.alg_name == WPA_ALG_CCMP) {
		pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
	}

	if (param->u.wpa_key.set_tx)
		dwKeyIndex |= (1 << 31);


	if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
		byKeyDecMode = KEY_CTL_CCMP;
	else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
		byKeyDecMode = KEY_CTL_TKIP;
	else
		byKeyDecMode = KEY_CTL_WEP;

	// Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled
	if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
		if (param->u.wpa_key.key_len == MAX_KEY_LEN)
			byKeyDecMode = KEY_CTL_TKIP;
		else if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
			byKeyDecMode = KEY_CTL_WEP;
		else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
			byKeyDecMode = KEY_CTL_WEP;
	} else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
		if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
			byKeyDecMode = KEY_CTL_WEP;
		else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
			byKeyDecMode = KEY_CTL_WEP;
	}

	// Check TKIP key length
	if ((byKeyDecMode == KEY_CTL_TKIP) &&
		(param->u.wpa_key.key_len != MAX_KEY_LEN)) {
		// TKIP Key must be 256 bits
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return - TKIP Key must be 256 bits!\n");
		return -EINVAL;
    }
	// Check AES key length
	if ((byKeyDecMode == KEY_CTL_CCMP) &&
		(param->u.wpa_key.key_len != AES_KEY_LEN)) {
		// AES Key must be 128 bits
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return - AES Key must be 128 bits\n");
		return -EINVAL;
	}

	if (is_broadcast_ether_addr(&param->addr[0]) || (param->addr == NULL)) {
		/* if broadcast, set the key as every key entry's group key */
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Groupe Key Assign.\n");

		if ((KeybSetAllGroupKey(pDevice, &(pDevice->sKey), dwKeyIndex,
							param->u.wpa_key.key_len,
							(PQWORD) &(KeyRSC),
							(PBYTE)abyKey,
							byKeyDecMode
					) == TRUE) &&
			(KeybSetDefaultKey(pDevice,
					&(pDevice->sKey),
					dwKeyIndex,
					param->u.wpa_key.key_len,
					(PQWORD) &(KeyRSC),
					(PBYTE)abyKey,
					byKeyDecMode
				) == TRUE) ) {
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");
		} else {
			return -EINVAL;
		}
	} else {
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Assign.\n");
		// BSSID not 0xffffffffffff
		// Pairwise Key can't be WEP
		if (byKeyDecMode == KEY_CTL_WEP) {
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key can't be WEP\n");
			return -EINVAL;
		}
		dwKeyIndex |= (1 << 30); // set pairwise key
		if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
			//DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - WMAC_CONFIG_IBSS_STA\n"));
			return -EINVAL;
		}
		if (KeybSetKey(pDevice, &(pDevice->sKey), &param->addr[0],
				dwKeyIndex, param->u.wpa_key.key_len,
				(PQWORD) &(KeyRSC), (PBYTE)abyKey, byKeyDecMode
				) == TRUE) {
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");
		} else {
			// Key Table Full
			if (!compare_ether_addr(&param->addr[0], pDevice->abyBSSID)) {
				//DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
				return -EINVAL;
			} else {
				// Save Key and configure just before associate/reassociate to BSSID
				// we do not implement now
				return -EINVAL;
			}
		}
	} // BSSID not 0xffffffffffff
	if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
		pDevice->byKeyIndex = (BYTE)param->u.wpa_key.key_index;
		pDevice->bTransmitKey = TRUE;
	}
	pDevice->bEncryptionEnable = TRUE;

	return ret;
}
Ejemplo n.º 15
0
 int wpa_set_keys(PSDevice pDevice, void *ctx, bool fcpfkernel)
{
    struct viawget_wpa_param *param=ctx;
    PSMgmtObject pMgmt = pDevice->pMgmt;
    unsigned long dwKeyIndex = 0;
    unsigned char abyKey[MAX_KEY_LEN];
    unsigned char abySeq[MAX_KEY_LEN];
    QWORD   KeyRSC;
//    NDIS_802_11_KEY_RSC KeyRSC;
    unsigned char byKeyDecMode = KEY_CTL_WEP;
	int ret = 0;
	int uu, ii;


	if (param->u.wpa_key.alg_name > WPA_ALG_CCMP ||
			param->u.wpa_key.key_len >= MAX_KEY_LEN ||
			param->u.wpa_key.seq_len >= MAX_KEY_LEN)
		return -EINVAL;

    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "param->u.wpa_key.alg_name = %d \n", param->u.wpa_key.alg_name);
	if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
        pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
        pDevice->bEncryptionEnable = false;
        pDevice->byKeyIndex = 0;
        pDevice->bTransmitKey = false;
        KeyvRemoveAllWEPKey(&(pDevice->sKey), pDevice->PortOffset);
        for (uu=0; uu<MAX_KEY_TABLE; uu++) {
            MACvDisableKeyEntry(pDevice->PortOffset, uu);
        }
        return ret;
    }

    //spin_unlock_irq(&pDevice->lock);
    if(param->u.wpa_key.key && fcpfkernel) {
       memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len);
     }
    else {
	spin_unlock_irq(&pDevice->lock);
	if (param->u.wpa_key.key &&
	    copy_from_user(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len)) {
	    spin_lock_irq(&pDevice->lock);
	    return -EINVAL;
    	}
spin_lock_irq(&pDevice->lock);
    	}

    dwKeyIndex = (unsigned long)(param->u.wpa_key.key_index);

	if (param->u.wpa_key.alg_name == WPA_ALG_WEP) {
        if (dwKeyIndex > 3) {
            return -EINVAL;
        }
        else {
            if (param->u.wpa_key.set_tx) {
                pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
                pDevice->bTransmitKey = true;
		        dwKeyIndex |= (1 << 31);
            }
            KeybSetDefaultKey(&(pDevice->sKey),
                                dwKeyIndex & ~(BIT30 | USE_KEYRSC),
                                param->u.wpa_key.key_len,
                                NULL,
                                abyKey,
                                KEY_CTL_WEP,
                                pDevice->PortOffset,
                                pDevice->byLocalID);

        }
        pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
        pDevice->bEncryptionEnable = true;
        return ret;
	}

	    //spin_unlock_irq(&pDevice->lock);
        if(param->u.wpa_key.seq && fcpfkernel) {
           memcpy(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len);
        	}
       else {
	   	spin_unlock_irq(&pDevice->lock);
	if (param->u.wpa_key.seq &&
	    copy_from_user(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len)) {
	    spin_lock_irq(&pDevice->lock);
	    return -EINVAL;
       	}
spin_lock_irq(&pDevice->lock);
}

	if (param->u.wpa_key.seq_len > 0) {
		for (ii = 0 ; ii < param->u.wpa_key.seq_len ; ii++) {
		     if (ii < 4)
			    LODWORD(KeyRSC) |= (abySeq[ii] << (ii * 8));
			 else
			    HIDWORD(KeyRSC) |= (abySeq[ii] << ((ii-4) * 8));
	         //KeyRSC |= (abySeq[ii] << (ii * 8));
		}
		dwKeyIndex |= 1 << 29;
	}

    if (param->u.wpa_key.key_index >= MAX_GROUP_KEY) {
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return  dwKeyIndex > 3\n");
        return -EINVAL;
    }

	if (param->u.wpa_key.alg_name == WPA_ALG_TKIP) {
        pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
    }

	if (param->u.wpa_key.alg_name == WPA_ALG_CCMP) {
        pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
    }

	if (param->u.wpa_key.set_tx)
		dwKeyIndex |= (1 << 31);


    if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
        byKeyDecMode = KEY_CTL_CCMP;
    else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
        byKeyDecMode = KEY_CTL_TKIP;
    else
        byKeyDecMode = KEY_CTL_WEP;

    // Fix HCT test that set 256 bits KEY and Ndis802_11Encryption3Enabled
    if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
        if (param->u.wpa_key.key_len == MAX_KEY_LEN)
            byKeyDecMode = KEY_CTL_TKIP;
        else if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
            byKeyDecMode = KEY_CTL_WEP;
        else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
            byKeyDecMode = KEY_CTL_WEP;
    } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
        if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
            byKeyDecMode = KEY_CTL_WEP;
        else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
            byKeyDecMode = KEY_CTL_WEP;
    }

    // Check TKIP key length
    if ((byKeyDecMode == KEY_CTL_TKIP) &&
        (param->u.wpa_key.key_len != MAX_KEY_LEN)) {
        // TKIP Key must be 256 bits
        //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - TKIP Key must be 256 bits\n"));
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return- TKIP Key must be 256 bits!\n");
        return -EINVAL;
    }
    // Check AES key length
    if ((byKeyDecMode == KEY_CTL_CCMP) &&
        (param->u.wpa_key.key_len != AES_KEY_LEN)) {
        // AES Key must be 128 bits
        //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - AES Key must be 128 bits\n"));
        return -EINVAL;
    }

   // spin_lock_irq(&pDevice->lock);
    if (is_broadcast_ether_addr(&param->addr[0]) || (param->addr == NULL)) {
        // If is_broadcast_ether_addr, set the key as every key entry's group key.
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Groupe Key Assign.\n");

        if ((KeybSetAllGroupKey(&(pDevice->sKey),
                            dwKeyIndex,
                            param->u.wpa_key.key_len,
                            (PQWORD) &(KeyRSC),
                            (unsigned char *)abyKey,
                            byKeyDecMode,
                            pDevice->PortOffset,
                            pDevice->byLocalID) == true) &&
            (KeybSetDefaultKey(&(pDevice->sKey),
                            dwKeyIndex,
                            param->u.wpa_key.key_len,
                            (PQWORD) &(KeyRSC),
                            (unsigned char *)abyKey,
                            byKeyDecMode,
                            pDevice->PortOffset,
                            pDevice->byLocalID) == true) ) {
             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");

        } else {
            //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -KeybSetDefaultKey Fail.0\n"));
           // spin_unlock_irq(&pDevice->lock);
            return -EINVAL;
        }

    } else {
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Assign.\n");
        // BSSID not 0xffffffffffff
        // Pairwise Key can't be WEP
        if (byKeyDecMode == KEY_CTL_WEP) {
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key can't be WEP\n");
            //spin_unlock_irq(&pDevice->lock);
            return -EINVAL;
        }

        dwKeyIndex |= (1 << 30); // set pairwise key
        if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
            //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA - WMAC_CONFIG_IBSS_STA\n"));
            //spin_unlock_irq(&pDevice->lock);
            return -EINVAL;
        }
        if (KeybSetKey(&(pDevice->sKey),
                       &param->addr[0],
                       dwKeyIndex,
                       param->u.wpa_key.key_len,
                       (PQWORD) &(KeyRSC),
                       (unsigned char *)abyKey,
                        byKeyDecMode,
                        pDevice->PortOffset,
                        pDevice->byLocalID) == true) {
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");

        } else {
            // Key Table Full
            if (!compare_ether_addr(&param->addr[0], pDevice->abyBSSID)) {
                //DBG_PRN_WLAN03(("return NDIS_STATUS_INVALID_DATA -Key Table Full.2\n"));
                //spin_unlock_irq(&pDevice->lock);
                return -EINVAL;

            } else {
                // Save Key and configure just before associate/reassociate to BSSID
                // we do not implement now
                //spin_unlock_irq(&pDevice->lock);
                return -EINVAL;
            }
        }
    } // BSSID not 0xffffffffffff
    if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
        pDevice->byKeyIndex = (unsigned char)param->u.wpa_key.key_index;
        pDevice->bTransmitKey = true;
    }
    pDevice->bEncryptionEnable = true;
    //spin_unlock_irq(&pDevice->lock);

/*
    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO " key=%x-%x-%x-%x-%x-xxxxx \n",
               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][0],
               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][1],
               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][2],
               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][3],
               pMgmt->sNodeDBTable[iNodeIndex].abyWepKey[byKeyIndex][4]
              );
*/

	return ret;

}
Ejemplo n.º 16
0
void DSSM_BinaryInput<ElemType>::Init(wstring fileName, size_t dim)
{

    m_dim = dim;
    mbSize = 0;
    /*
    m_hndl = CreateFileA(fileName.c_str(), GENERIC_READ,
        FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    */
    m_hndl = CreateFile(fileName.c_str(), GENERIC_READ,
                        FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    if (m_hndl == INVALID_HANDLE_VALUE)
    {
        char message[256];
        sprintf_s(message, "Unable to Open/Create file %ls, error %x", fileName.c_str(), GetLastError());
        RuntimeError(message);
    }

    m_filemap = CreateFileMapping(m_hndl, NULL, PAGE_READONLY, 0, 0, NULL);

    SYSTEM_INFO sysinfo;
    GetSystemInfo(&sysinfo);
    DWORD sysGran = sysinfo.dwAllocationGranularity;

    header_buffer = MapViewOfFile(m_filemap,     // handle to map object
                                  FILE_MAP_READ, // get correct permissions
                                  HIDWORD(0),
                                  LODWORD(0),
                                  sizeof(int64_t) * 2 + sizeof(int32_t));

    // cout << "After mapviewoffile" << endl;

    memcpy(&numRows, header_buffer, sizeof(int64_t));
    memcpy(&numCols, (char*) header_buffer + sizeof(int64_t), sizeof(int32_t));
    memcpy(&totalNNz, (char*) header_buffer + sizeof(int64_t) + sizeof(int32_t), sizeof(int64_t));

    // cout << "After gotvalues" << endl;
    int64_t base_offset = sizeof(int64_t) * 2 + sizeof(int32_t);

    int64_t offsets_padding = base_offset % sysGran;
    base_offset -= offsets_padding;

    int64_t header_size = numRows * sizeof(int64_t) + offsets_padding;

    void* offsets_orig = MapViewOfFile(m_filemap,     // handle to map object
                                       FILE_MAP_READ, // get correct permissions
                                       HIDWORD(base_offset),
                                       LODWORD(base_offset),
                                       header_size);

    offsets_buffer = (char*) offsets_orig + offsets_padding;

    if (offsets != NULL)
    {
        free(offsets);
    }
    offsets = (int64_t*) malloc(sizeof(int64_t) * numRows);
    memcpy(offsets, offsets_buffer, numRows * sizeof(int64_t));

    int64_t header_offset = base_offset + offsets_padding + numRows * sizeof(int64_t);

    int64_t data_padding = header_offset % sysGran;
    header_offset -= data_padding;

    void* data_orig = MapViewOfFile(m_filemap,     // handle to map object
                                    FILE_MAP_READ, // get correct permissions
                                    HIDWORD(header_offset),
                                    LODWORD(header_offset),
                                    0);
    data_buffer = (char*) data_orig + data_padding;
}
Ejemplo n.º 17
0
static ULONGLONG UnsignedMultiplyHigh( ULONGLONG ull1, ULONGLONG ull2 )
{
    return HIDWORD( ull1 ) * HIDWORD( ull2 ) + HIDWORD( HIDWORD( ull1 )
        * LODWORD( ull2 ) + LODWORD( ull1 ) * HIDWORD( ull2 )
        + HIDWORD( LODWORD( ull1 ) * LODWORD( ull2 ) ) );
}
Ejemplo n.º 18
0
  DWORD FileDetailsReadMap(const TCHAR* filePath, QWORD&  qwSize, FILETIME& fileTime, DWORD& dwCheckSum
		, HANDLE evAbort) // bool volatile * pisAbort)
	{
		_ASSERTE(filePath);
		_ASSERTE(lstrlen(filePath));
		DWORD dwCrc32;
		DWORD dwErrorCode = NO_ERROR;
		HANDLE hFile = NULL, hFilemap = NULL;

		dwCrc32 = 0x0;
		LPBYTE pCrc = (LPBYTE)&dwCrc32; 
		FILETIME fileTime0;

		QWORD qwFileSize, qwFileSize0;
		try
		{
			// Open the file
			hFile = CreateFile(filePath,
				GENERIC_READ,
				FILE_SHARE_READ,
				NULL,
				OPEN_EXISTING,
				FILE_ATTRIBUTE_ARCHIVE | FILE_ATTRIBUTE_HIDDEN | FILE_ATTRIBUTE_READONLY | FILE_ATTRIBUTE_SYSTEM | FILE_FLAG_SEQUENTIAL_SCAN,				NULL);
			if(hFile == INVALID_HANDLE_VALUE)
				throw GetLastErrorEx;

		  QWORD qwFileOffset = 0;
			DWORD dwByteCount, dwViewSize;
			LPVOID dwBaseAddress;

			{
				DWORD dwLo = 0, dwHi = 0;
				dwLo = GetFileSize(hFile, &dwHi);
				if(dwLo == INVALID_FILE_SIZE 
					&& (dwErrorCode = GetLastError()) != NO_ERROR)
					throw ExitEx;
				qwFileSize = qwFileSize0 = MAKEQWORD(dwHi, dwLo);
			}

			if (!GetFileTime(hFile, &fileTime0, NULL, NULL)) 
				throw GetLastErrorEx;
			// Get the file size
			//if(!GetFileSizeQW(hFile, qwFileSize))
			//	dwErrorCode = ERROR_BAD_LENGTH;
			//else 
			if(0 != qwFileSize)	// We cannot CRC zero byte files
			{
				// Create the file mapping
				hFilemap = CreateFileMapping(hFile,
					NULL,
					PAGE_READONLY,
					0,
					0,
					NULL);

				if(NULL == hFilemap)
					throw GetLastErrorEx;

				LPBYTE pByte;
				//LPDWORD pDWord;

				// Loop while we map a section of the file and CRC it
				while(0 < qwFileSize)
				{
					//if (*pisAbort)
					if (WaitForSingleObject(evAbort, 0) != WAIT_TIMEOUT)
					{
						dwErrorCode = ERROR_CANCELLED;
						throw ExitEx;
					}
					if(qwFileSize < MAX_VIEW_SIZE)
						dwViewSize = LODWORD(qwFileSize);
					else
						dwViewSize = MAX_VIEW_SIZE;

					dwBaseAddress = MapViewOfFile(hFilemap,
						FILE_MAP_READ,
						HIDWORD(qwFileOffset),
						LODWORD(qwFileOffset),
						dwViewSize);

					dwByteCount = dwViewSize;
					pByte = (LPBYTE)dwBaseAddress;
					BYTE checkSumOffset = 0;
					while(0 < dwByteCount--)
					{
						*(pCrc + checkSumOffset) ^= *pByte;
						pByte++;
						checkSumOffset++;
						if (4 <= checkSumOffset)
							checkSumOffset = 0;
					}

					UnmapViewOfFile((LPVOID)dwBaseAddress);
					qwFileOffset += dwViewSize;
					qwFileSize -= dwViewSize;
				}  // while(qwFileSize > 0)
			} // if(qwFileSize != 0)
		}
		catch(char c)
		{
			if (GetLastErrorEx == c)
				dwErrorCode = GetLastError();
		}
		catch(...)
		{
			// An unknown exception happened
			dwErrorCode = ERROR_CRC;
		}

		if(hFile != NULL) CloseHandle(hFile);
		if(hFilemap != NULL) CloseHandle(hFilemap);

		if (NO_ERROR == dwErrorCode)
		{
			qwSize = qwFileSize0;
			dwCheckSum = dwCrc32;
			fileTime = fileTime0;
		}
		return dwErrorCode;
	}
Ejemplo n.º 19
0
OsStatus_t
AhciCommandDispatch(
    _In_ AhciTransaction_t* Transaction,
    _In_ Flags_t            Flags,
    _In_ void*              Command, 
    _In_ size_t             CommandLength,
    _In_ void*              AtapiCommand, 
    _In_ size_t             AtapiCommandLength)
{
    AHCICommandHeader_t* CommandHeader;
    AHCICommandTable_t*  CommandTable;
    uintptr_t            BufferPointer;
    size_t               BytesLeft = Transaction->SectorCount * Transaction->Device->SectorSize;
    int                  PrdtIndex = 0;

    TRACE("AhciCommandDispatch(Port %u, Flags 0x%x, Length %u, TransferSize 0x%x)",
        Transaction->Device->Port->Id, Flags, CommandLength, BytesLeft);

    // Assert that buffer is DWORD aligned, this must be true
    if (((uintptr_t)Transaction->Address & 0x3) != 0) {
        ERROR("AhciCommandDispatch::Buffer was not dword aligned (0x%x)",
            Transaction->Device->Port->Id, Transaction->Address);
        goto Error;
    }

    // Assert that buffer length is an even byte-count requested
    if ((BytesLeft & 0x1) != 0) {
        ERROR("AhciCommandDispatch::BufferLength is odd, must be even",
            Transaction->Device->Port->Id);
        goto Error;
    }

    // Get a reference to the command slot and reset the data in the command table
    CommandHeader = &Transaction->Device->Port->CommandList->Headers[Transaction->Slot];
    CommandTable  = (AHCICommandTable_t*)((uint8_t*)Transaction->Device->Port->CommandTable
            + (AHCI_COMMAND_TABLE_SIZE * Transaction->Slot));
    memset(CommandTable, 0, AHCI_COMMAND_TABLE_SIZE);

    // Sanitizie packet lenghts
    if (CommandLength > 64 || AtapiCommandLength > 16) {
        ERROR("AHCI::Commands are exceeding the allowed length, FIS (%u), ATAPI (%u)",
            CommandLength, AtapiCommandLength);
        goto Error;
    }

    // Copy data over into the packets based on type
    if (Command != NULL) {
        memcpy(&CommandTable->FISCommand[0], Command, CommandLength);
    }
    if (AtapiCommand != NULL) {
        memcpy(&CommandTable->FISAtapi[0], AtapiCommand, AtapiCommandLength);
    }

    // Build PRDT entries
    TRACE("Building PRDT Table");
    BufferPointer = Transaction->Address;
    while (BytesLeft > 0) {
        AHCIPrdtEntry_t* Prdt = &CommandTable->PrdtEntry[PrdtIndex];
        size_t TransferLength = MIN(AHCI_PRDT_MAX_LENGTH, BytesLeft);

        // Set buffer information and transfer sizes
        Prdt->DataBaseAddress      = LODWORD(BufferPointer);
        Prdt->DataBaseAddressUpper = (sizeof(void*) > 4) ? HIDWORD(BufferPointer) : 0;
        Prdt->Descriptor           = TransferLength - 1; // N - 1

        TRACE("PRDT %u, Address 0x%x, Length 0x%x", PrdtIndex, Prdt->DataBaseAddress, Prdt->Descriptor);

        // Adjust counters
        BufferPointer += TransferLength;
        BytesLeft     -= TransferLength;
        PrdtIndex++;

        // If this is the last PRDT packet, set IOC
        if (BytesLeft == 0) {
            Prdt->Descriptor |= AHCI_PRDT_IOC;
        }
    }

    // Update command table to the new command
    CommandHeader->PRDByteCount = 0;
    CommandHeader->TableLength  = (uint16_t)PrdtIndex;
    CommandHeader->Flags        = (uint16_t)(CommandLength >> 2);
    TRACE("PRDT Count %u, Number of DW's %u", CommandHeader->TableLength, CommandHeader->Flags);

    // Update transfer with the dispatch flags
    if (Flags & DISPATCH_ATAPI) {
        CommandHeader->Flags |= (1 << 5);
    }
    if (Flags & DISPATCH_WRITE) {
        CommandHeader->Flags |= (1 << 6);
    }
    if (Flags & DISPATCH_PREFETCH) {
        CommandHeader->Flags |= (1 << 7);
    }
    if (Flags & DISPATCH_CLEARBUSY) {
        CommandHeader->Flags |= (1 << 10);
    }

    // Set the port multiplier
    CommandHeader->Flags |= (DISPATCH_MULTIPLIER(Flags) << 12);
    Transaction->Header.Key.Value.Integer = Transaction->Slot;

    // Add transaction to list
    CollectionAppend(Transaction->Device->Port->Transactions, &Transaction->Header);
    TRACE("Enabling command on slot %u", Transaction->Slot);
    AhciPortStartCommandSlot(Transaction->Device->Port, Transaction->Slot);

#ifdef __TRACE
    // Dump state
    thrd_sleepex(5000);
    AhciDumpCurrentState(Transaction->Device->Controller, Transaction->Device->Port);
#endif
    return OsSuccess;

Error:
    return OsError;
}
Ejemplo n.º 20
0
_WCRTLINK __int64 __lseeki64( int handle, __int64 offset, int origin )
{
#if defined( __NT__ ) || defined( __OS2__ ) || defined( __LINUX__ )
    __int64         pos;

    __handle_check( handle, -1 );

  #if defined( __OS2__ )
    {
    #if !defined( _M_I86 )
        APIRET          rc;

        if( __os2_DosSetFilePtrL != NULL ) {
            rc = __os2_DosSetFilePtrL( handle, offset, origin, &pos );
            if( rc != 0 ) {
                return( __set_errno_dos( rc ) );
            }
        } else {
    #endif
            if( offset > LONG_MAX || offset < LONG_MIN ) {
                __set_errno( EINVAL );
                return( -1LL );
            }
            pos = (unsigned long)__lseek( handle, offset, origin );
            if( pos == INVALID_SET_FILE_POINTER ) {
                pos = -1LL;
            }
    #if !defined( _M_I86 )
        }
    #endif
    }
  #elif defined( __NT__ )
    {
        DWORD           rc;
        LONG            offset_hi;
        int             error;
    
        offset_hi = HIDWORD( offset );
        rc = SetFilePointer( __getOSHandle( handle ), LODWORD( offset ), &offset_hi, origin );
        if( rc == INVALID_SET_FILE_POINTER ) {  // this might be OK so
            error = GetLastError();             // check for sure JBS 04-nov-99
            if( error != NO_ERROR ) {
                return( __set_errno_dos( error ) );
            }
        }
        U64Set( (unsigned_64 *)&pos, rc, offset_hi );
    }
  #elif defined( __LINUX__ )
    if( _llseek( handle, LODWORD( offset ), HIDWORD( offset ), &pos, origin ) ) {
        pos = -1LL;
    }
  #endif
    return( pos );
#else
    long            pos;

    if( offset > LONG_MAX || offset < LONG_MIN ) {
        __set_errno( EINVAL );
        return( -1LL );
    }
    pos = __lseek( handle, offset, origin );
    if( pos == INVALID_SET_FILE_POINTER ) {
        return( -1LL );
    }
    return( (unsigned long)pos );
#endif
}
Ejemplo n.º 21
0
void
acpi_db_dump_object (
	acpi_object             *obj_desc,
	u32                     level)
{
	u32                     i;


	if (!obj_desc) {
		acpi_os_printf ("[Null Object]\n");
		return;
	}

	for (i = 0; i < level; i++) {
		acpi_os_printf (" ");
	}

	switch (obj_desc->type) {
	case ACPI_TYPE_ANY:

		acpi_os_printf ("[Object Reference] = %p\n", obj_desc->reference.handle);
		break;


	case ACPI_TYPE_INTEGER:

		acpi_os_printf ("[Integer] = %8.8X%8.8X\n", HIDWORD (obj_desc->integer.value),
				 LODWORD (obj_desc->integer.value));
		break;


	case ACPI_TYPE_STRING:

		acpi_os_printf ("[String] Value: ");
		for (i = 0; i < obj_desc->string.length; i++) {
			acpi_os_printf ("%c", obj_desc->string.pointer[i]);
		}
		acpi_os_printf ("\n");
		break;


	case ACPI_TYPE_BUFFER:

		acpi_os_printf ("[Buffer] = ");
		acpi_ut_dump_buffer ((u8 *) obj_desc->buffer.pointer, obj_desc->buffer.length, DB_DWORD_DISPLAY, _COMPONENT);
		break;


	case ACPI_TYPE_PACKAGE:

		acpi_os_printf ("[Package] Contains %d Elements: \n", obj_desc->package.count);

		for (i = 0; i < obj_desc->package.count; i++) {
			acpi_db_dump_object (&obj_desc->package.elements[i], level+1);
		}
		break;


	case INTERNAL_TYPE_REFERENCE:

		acpi_os_printf ("[Object Reference] = %p\n", obj_desc->reference.handle);
		break;


	case ACPI_TYPE_PROCESSOR:

		acpi_os_printf ("[Processor]\n");
		break;


	case ACPI_TYPE_POWER:

		acpi_os_printf ("[Power Resource]\n");
		break;


	default:

		acpi_os_printf ("[Unknown Type] %X \n", obj_desc->type);
		break;
	}
}
__ptr_t
__mmap64 (__ptr_t addr, size_t len, int prot, int flags, int fd,
		__off64_t offset)
{
	__ptr_t map = (__ptr_t) NULL;
	caddr_t gran_addr = (caddr_t) addr;
	HANDLE handle = INVALID_HANDLE_VALUE;
	DWORD cfm_flags = 0, mvf_flags = 0, sysgran = getgranularity ();
	__off64_t gran_offset = offset, filelen = _filelengthi64(fd);
	int mmlen = len;
	
	switch (prot) {
		case PROT_READ | PROT_WRITE | PROT_EXEC:
		case PROT_WRITE | PROT_EXEC:
			cfm_flags = PAGE_EXECUTE_READWRITE;
			mvf_flags = FILE_MAP_ALL_ACCESS;
			break;
		case PROT_READ | PROT_WRITE:
			cfm_flags = PAGE_READWRITE;
			mvf_flags = FILE_MAP_ALL_ACCESS;
			break;
		case PROT_WRITE:
			cfm_flags = PAGE_READWRITE;
			mvf_flags = FILE_MAP_WRITE;
			break;
		case PROT_READ:
			cfm_flags = PAGE_READONLY;
			mvf_flags = FILE_MAP_READ;
			break;
		case PROT_NONE:
			cfm_flags = PAGE_NOACCESS;
			mvf_flags = FILE_MAP_READ;
			break;
		case PROT_EXEC:
			cfm_flags = PAGE_EXECUTE;
			mvf_flags = FILE_MAP_READ;
			break;
	}
	if (flags & MAP_PRIVATE) {
		if (IsWin9x ())
			cfm_flags = PAGE_WRITECOPY;
		mvf_flags = FILE_MAP_COPY;
	}
	fprintf (stderr, "Addr before:   %p\n", gran_addr);
	fprintf (stderr, "Offset before: %#I64X\n", gran_offset);
	if (flags & MAP_FIXED) {
		gran_offset = offset;
		gran_addr = addr;
	}
	else {
		gran_offset = offset & ~(sysgran - 1);
		gran_addr = (caddr_t) (((DWORD) gran_addr / sysgran) * sysgran);
	}
	fprintf (stderr, "Addr after:    %p\n", gran_addr);
	fprintf (stderr, "Offset after:  %#I64X\n", gran_offset);
	mmlen = (filelen < gran_offset + len ? filelen - gran_offset : len);

	handle = CreateFileMapping ((HANDLE) _get_osfhandle(fd), NULL, cfm_flags,
		0, mmlen, NULL);
	if (!handle) {
		set_werrno;
		WinErr ("CreateFileMapping");
		return MAP_FAILED;
	}
	map = (__ptr_t) MapViewOfFileEx (handle, mvf_flags, HIDWORD(gran_offset),
		LODWORD(gran_offset), (SIZE_T) mmlen, (LPVOID) gran_addr);
	if (map == NULL && (flags & MAP_FIXED) ) {
		fprintf (stderr, "Starting address: %p\n", (LPVOID) gran_addr);
		WinErr ("First try of MapViewOfFileEx failed");
		map = (__ptr_t) MapViewOfFileEx (handle, mvf_flags, HIDWORD(gran_offset),
			LODWORD(gran_offset), (SIZE_T) mmlen, (LPVOID) NULL);
	}
	CloseHandle(handle);
	if (map == NULL) {
		set_werrno;
		WinErr ("MapViewOfFileEx");
		return MAP_FAILED;
	}
	return map;
}
Ejemplo n.º 23
0
bool CPluginW2800::GetPanelItemInfo(const CEPanelInfo& PnlInfo, bool bSelected, INT_PTR iIndex, WIN32_FIND_DATAW& Info, wchar_t** ppszFullPathName)
{
	if (!InfoW2800 || !InfoW2800->PanelControl)
		return false;

	FILE_CONTROL_COMMANDS iCmd = bSelected ? FCTL_GETSELECTEDPANELITEM : FCTL_GETPANELITEM;
	INT_PTR iItemsNumber = bSelected ? ((PanelInfo*)PnlInfo.panelInfo)->SelectedItemsNumber : ((PanelInfo*)PnlInfo.panelInfo)->ItemsNumber;

	if ((iIndex < 0) || (iIndex >= iItemsNumber))
	{
		_ASSERTE(FALSE && "iItem out of bounds");
		return false;
	}

	INT_PTR sz = PanelControlApi(PANEL_ACTIVE, iCmd, iIndex, NULL);

	if (sz <= 0)
		return false;

	PluginPanelItem* pItem = (PluginPanelItem*)calloc(sz, 1); // размер возвращается в байтах
	if (!pItem)
		return false;

	FarGetPluginPanelItem gppi = {sizeof(gppi), sz, pItem};
	if (PanelControlApi(PANEL_ACTIVE, iCmd, iIndex, &gppi) <= 0)
	{
		free(pItem);
		return false;
	}

	ZeroStruct(Info);

	Info.dwFileAttributes = LODWORD(pItem->FileAttributes);
	Info.ftCreationTime = pItem->CreationTime;
	Info.ftLastAccessTime = pItem->LastAccessTime;
	Info.ftLastWriteTime = pItem->LastWriteTime;
	Info.nFileSizeLow = LODWORD(pItem->FileSize);
	Info.nFileSizeHigh = HIDWORD(pItem->FileSize);

	if (pItem->FileName)
	{
		LPCWSTR pszName = pItem->FileName;
		int iLen = lstrlen(pszName);
		// If full paths exceeds MAX_PATH chars - return in Info.cFileName the file name only
		if (iLen >= countof(Info.cFileName))
			pszName = PointToName(pItem->FileName);
		lstrcpyn(Info.cFileName, pszName, countof(Info.cFileName));
		if (ppszFullPathName)
			*ppszFullPathName = lstrdup(pItem->FileName);
	}
	else if (ppszFullPathName)
	{
		_ASSERTE(*ppszFullPathName == NULL);
		*ppszFullPathName = NULL;
	}

	if (pItem->AlternateFileName)
	{
		lstrcpyn(Info.cAlternateFileName, pItem->AlternateFileName, countof(Info.cAlternateFileName));
	}

	free(pItem);

	return true;
}
Ejemplo n.º 24
0
acpi_status
acpi_ex_system_memory_space_handler (
	u32                     function,
	ACPI_PHYSICAL_ADDRESS   address,
	u32                     bit_width,
	u32                     *value,
	void                    *handler_context,
	void                    *region_context)
{
	acpi_status             status = AE_OK;
	void                    *logical_addr_ptr = NULL;
	acpi_mem_space_context  *mem_info = region_context;
	u32                     length;


	FUNCTION_TRACE ("Ex_system_memory_space_handler");


	/* Validate and translate the bit width */

	switch (bit_width) {
	case 8:
		length = 1;
		break;

	case 16:
		length = 2;
		break;

	case 32:
		length = 4;
		break;

	default:
		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Invalid System_memory width %d\n",
			bit_width));
		return_ACPI_STATUS (AE_AML_OPERAND_VALUE);
		break;
	}


	/*
	 * Does the request fit into the cached memory mapping?
	 * Is 1) Address below the current mapping? OR
	 *    2) Address beyond the current mapping?
	 */
	if ((address < mem_info->mapped_physical_address) ||
		(((acpi_integer) address + length) >
			((acpi_integer) mem_info->mapped_physical_address + mem_info->mapped_length))) {
		/*
		 * The request cannot be resolved by the current memory mapping;
		 * Delete the existing mapping and create a new one.
		 */
		if (mem_info->mapped_length) {
			/* Valid mapping, delete it */

			acpi_os_unmap_memory (mem_info->mapped_logical_address,
					   mem_info->mapped_length);
		}

		mem_info->mapped_length = 0; /* In case of failure below */

		/* Create a new mapping starting at the address given */

		status = acpi_os_map_memory (address, SYSMEM_REGION_WINDOW_SIZE,
				  (void **) &mem_info->mapped_logical_address);
		if (ACPI_FAILURE (status)) {
			return_ACPI_STATUS (status);
		}

		/* Save the physical address and mapping size */

		mem_info->mapped_physical_address = address;
		mem_info->mapped_length = SYSMEM_REGION_WINDOW_SIZE;
	}


	/*
	 * Generate a logical pointer corresponding to the address we want to
	 * access
	 */

	/* TBD: should these pointers go to 64-bit in all cases ? */

	logical_addr_ptr = mem_info->mapped_logical_address +
			  ((acpi_integer) address - (acpi_integer) mem_info->mapped_physical_address);

	ACPI_DEBUG_PRINT ((ACPI_DB_INFO,
		"System_memory %d (%d width) Address=%8.8X%8.8X\n", function, bit_width,
		HIDWORD (address), LODWORD (address)));

   /* Perform the memory read or write */

	switch (function) {

	case ACPI_READ_ADR_SPACE:

		switch (bit_width) {
		case 8:
			*value = (u32)* (u8 *) logical_addr_ptr;
			break;

		case 16:
			MOVE_UNALIGNED16_TO_32 (value, logical_addr_ptr);
			break;

		case 32:
			MOVE_UNALIGNED32_TO_32 (value, logical_addr_ptr);
			break;
		}

		break;


	case ACPI_WRITE_ADR_SPACE:

		switch (bit_width) {
		case 8:
			*(u8 *) logical_addr_ptr = (u8) *value;
			break;

		case 16:
			MOVE_UNALIGNED16_TO_16 (logical_addr_ptr, value);
			break;

		case 32:
			MOVE_UNALIGNED32_TO_32 (logical_addr_ptr, value);
			break;
		}

		break;


	default:
		status = AE_BAD_PARAMETER;
		break;
	}

	return_ACPI_STATUS (status);
}
Ejemplo n.º 25
0
void MMapFile::resize(__int64 newsize)
{
  release();

  if (newsize > m_iSize)
  {
#ifdef _WIN32
    if (m_hFileMap)
      CloseHandle(m_hFileMap);

    m_hFileMap = 0;
#endif

    m_iSize = newsize;

#ifdef _WIN32
    if (m_hFile == INVALID_HANDLE_VALUE)
    {
      TCHAR buf[MAX_PATH], buf2[MAX_PATH];

      GetTempPath(MAX_PATH, buf);
      GetTempFileName(buf, _T("nsd"), 0, buf2);

      m_hFile = CreateFile(
        buf2,
        GENERIC_READ | GENERIC_WRITE,
        0,
        NULL,
        CREATE_ALWAYS,
        FILE_ATTRIBUTE_TEMPORARY | FILE_FLAG_DELETE_ON_CLOSE | FILE_FLAG_SEQUENTIAL_SCAN,
        NULL
      );

      m_bTempHandle = TRUE;
    }

    if (m_hFile != INVALID_HANDLE_VALUE)
    {
      m_hFileMap = CreateFileMapping(
        m_hFile,
        NULL,
        m_bReadOnly ? PAGE_READONLY : PAGE_READWRITE,
        HIDWORD(m_iSize),
        LODWORD(m_iSize),
        NULL
      );
    }
#else
    if (m_hFile == NULL)
    {
      m_hFile = tmpfile();
      if (m_hFile != NULL)
      {
        m_hFileDesc = fileno(m_hFile);
        m_bTempHandle = TRUE;
      }
    }

    // resize
    if (m_hFileDesc != -1)
    {
      unsigned char c = 0;

      if (lseek(m_hFileDesc, m_iSize, SEEK_SET) != (off_t)-1)
      {
        if (read(m_hFileDesc, &c, 1) != -1)
        {
          if (lseek(m_hFileDesc, m_iSize, SEEK_SET) != (off_t)-1)
          {
            if (write(m_hFileDesc, &c, 1) != -1)
            {
              return; // no errors
            }
          }
        }
      }
    }

    m_hFileDesc = -1; // some error occurred, bail
#endif

#ifdef _WIN32
    if (!m_hFileMap)
#else
    if (m_hFileDesc == -1)
#endif
    {
      extern void quit(); extern int g_display_errors;
      if (g_display_errors)
      {
        PrintColorFmtMsg_ERR(_T("\nInternal compiler error #12345: error creating mmap the size of %I64d.\n"), m_iSize);
      }
      quit();
    }
  }
}
Ejemplo n.º 26
0
bool
device_receive_frame(
	PSDevice pDevice,
	PSRxDesc pCurrRD
)
{
	PDEVICE_RD_INFO  pRDInfo = pCurrRD->pRDInfo;
	struct net_device_stats *pStats = &pDevice->stats;
	struct sk_buff *skb;
	PSMgmtObject    pMgmt = pDevice->pMgmt;
	PSRxMgmtPacket  pRxPacket = &(pDevice->pMgmt->sRxPacket);
	PS802_11Header  p802_11Header;
	unsigned char *pbyRsr;
	unsigned char *pbyNewRsr;
	unsigned char *pbyRSSI;
	PQWORD          pqwTSFTime;
	unsigned short *pwFrameSize;
	unsigned char *pbyFrame;
	bool bDeFragRx = false;
	bool bIsWEP = false;
	unsigned int cbHeaderOffset;
	unsigned int FrameSize;
	unsigned short wEtherType = 0;
	int             iSANodeIndex = -1;
	int             iDANodeIndex = -1;
	unsigned int ii;
	unsigned int cbIVOffset;
	bool bExtIV = false;
	unsigned char *pbyRxSts;
	unsigned char *pbyRxRate;
	unsigned char *pbySQ;
	unsigned int cbHeaderSize;
	PSKeyItem       pKey = NULL;
	unsigned short wRxTSC15_0 = 0;
	unsigned long dwRxTSC47_16 = 0;
	SKeyItem        STempKey;
	// 802.11h RPI
	unsigned long dwDuration = 0;
	long            ldBm = 0;
	long            ldBmThreshold = 0;
	PS802_11Header pMACHeader;
	bool bRxeapol_key = false;

	skb = pRDInfo->skb;

//PLICE_DEBUG->
	pci_unmap_single(pDevice->pcid, pRDInfo->skb_dma,
			 pDevice->rx_buf_sz, PCI_DMA_FROMDEVICE);
//PLICE_DEBUG<-
	pwFrameSize = (unsigned short *)(skb->data + 2);
	FrameSize = cpu_to_le16(pCurrRD->m_rd1RD1.wReqCount) - cpu_to_le16(pCurrRD->m_rd0RD0.wResCount);

	// Max: 2312Payload + 30HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
	// Min (ACK): 10HD +4CRC + 2Padding + 4Len + 8TSF + 4RSR
	if ((FrameSize > 2364) || (FrameSize <= 32)) {
		// Frame Size error drop this packet.
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---------- WRONG Length 1\n");
		return false;
	}

	pbyRxSts = (unsigned char *)(skb->data);
	pbyRxRate = (unsigned char *)(skb->data + 1);
	pbyRsr = (unsigned char *)(skb->data + FrameSize - 1);
	pbyRSSI = (unsigned char *)(skb->data + FrameSize - 2);
	pbyNewRsr = (unsigned char *)(skb->data + FrameSize - 3);
	pbySQ = (unsigned char *)(skb->data + FrameSize - 4);
	pqwTSFTime = (PQWORD)(skb->data + FrameSize - 12);
	pbyFrame = (unsigned char *)(skb->data + 4);

	// get packet size
	FrameSize = cpu_to_le16(*pwFrameSize);

	if ((FrameSize > 2346)|(FrameSize < 14)) { // Max: 2312Payload + 30HD +4CRC
		// Min: 14 bytes ACK
		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "---------- WRONG Length 2\n");
		return false;
	}
//PLICE_DEBUG->
	// update receive statistic counter
	STAvUpdateRDStatCounter(&pDevice->scStatistic,
				*pbyRsr,
				*pbyNewRsr,
				*pbyRxRate,
				pbyFrame,
				FrameSize);

	pMACHeader = (PS802_11Header)((unsigned char *)(skb->data) + 8);
//PLICE_DEBUG<-
	if (pDevice->bMeasureInProgress) {
		if ((*pbyRsr & RSR_CRCOK) != 0)
			pDevice->byBasicMap |= 0x01;

		dwDuration = (FrameSize << 4);
		dwDuration /= acbyRxRate[*pbyRxRate%MAX_RATE];
		if (*pbyRxRate <= RATE_11M) {
			if (*pbyRxSts & 0x01) {
				// long preamble
				dwDuration += 192;
			} else {
				// short preamble
				dwDuration += 96;
			}
		} else {
			dwDuration += 16;
		}
		RFvRSSITodBm(pDevice, *pbyRSSI, &ldBm);
		ldBmThreshold = -57;
		for (ii = 7; ii > 0;) {
			if (ldBm > ldBmThreshold)
				break;

			ldBmThreshold -= 5;
			ii--;
		}
		pDevice->dwRPIs[ii] += dwDuration;
		return false;
	}

	if (!is_multicast_ether_addr(pbyFrame)) {
		if (WCTLbIsDuplicate(&(pDevice->sDupRxCache), (PS802_11Header)(skb->data + 4))) {
			pDevice->s802_11Counter.FrameDuplicateCount++;
			return false;
		}
	}

	// Use for TKIP MIC
	s_vGetDASA(skb->data+4, &cbHeaderSize, &pDevice->sRxEthHeader);

	// filter packet send from myself
	if (ether_addr_equal(pDevice->sRxEthHeader.abySrcAddr,
			     pDevice->abyCurrentNetAddr))
		return false;

	if ((pMgmt->eCurrMode == WMAC_MODE_ESS_AP) || (pMgmt->eCurrMode == WMAC_MODE_IBSS_STA)) {
		if (IS_CTL_PSPOLL(pbyFrame) || !IS_TYPE_CONTROL(pbyFrame)) {
			p802_11Header = (PS802_11Header)(pbyFrame);
			// get SA NodeIndex
			if (BSSDBbIsSTAInNodeDB(pMgmt, (unsigned char *)(p802_11Header->abyAddr2), &iSANodeIndex)) {
				pMgmt->sNodeDBTable[iSANodeIndex].ulLastRxJiffer = jiffies;
				pMgmt->sNodeDBTable[iSANodeIndex].uInActiveCount = 0;
			}
		}
	}

	if (pMgmt->eCurrMode == WMAC_MODE_ESS_AP) {
		if (s_bAPModeRxCtl(pDevice, pbyFrame, iSANodeIndex))
			return false;
	}

	if (IS_FC_WEP(pbyFrame)) {
		bool bRxDecryOK = false;

		DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "rx WEP pkt\n");
		bIsWEP = true;
		if ((pDevice->bEnableHostWEP) && (iSANodeIndex >= 0)) {
			pKey = &STempKey;
			pKey->byCipherSuite = pMgmt->sNodeDBTable[iSANodeIndex].byCipherSuite;
			pKey->dwKeyIndex = pMgmt->sNodeDBTable[iSANodeIndex].dwKeyIndex;
			pKey->uKeyLength = pMgmt->sNodeDBTable[iSANodeIndex].uWepKeyLength;
			pKey->dwTSC47_16 = pMgmt->sNodeDBTable[iSANodeIndex].dwTSC47_16;
			pKey->wTSC15_0 = pMgmt->sNodeDBTable[iSANodeIndex].wTSC15_0;
			memcpy(pKey->abyKey,
			       &pMgmt->sNodeDBTable[iSANodeIndex].abyWepKey[0],
			       pKey->uKeyLength
);

			bRxDecryOK = s_bHostWepRxEncryption(pDevice,
							    pbyFrame,
							    FrameSize,
							    pbyRsr,
							    pMgmt->sNodeDBTable[iSANodeIndex].bOnFly,
							    pKey,
							    pbyNewRsr,
							    &bExtIV,
							    &wRxTSC15_0,
							    &dwRxTSC47_16);
		} else {
			bRxDecryOK = s_bHandleRxEncryption(pDevice,
							   pbyFrame,
							   FrameSize,
							   pbyRsr,
							   pbyNewRsr,
							   &pKey,
							   &bExtIV,
							   &wRxTSC15_0,
							   &dwRxTSC47_16);
		}

		if (bRxDecryOK) {
			if ((*pbyNewRsr & NEWRSR_DECRYPTOK) == 0) {
				DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "ICV Fail\n");
				if ((pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA) ||
				    (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPAPSK) ||
				    (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPANONE) ||
				    (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA2) ||
				    (pDevice->pMgmt->eAuthenMode == WMAC_AUTH_WPA2PSK)) {
					if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_TKIP))
						pDevice->s802_11Counter.TKIPICVErrors++;
					else if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP))
						pDevice->s802_11Counter.CCMPDecryptErrors++;
				}
				return false;
			}
		} else {
			DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "WEP Func Fail\n");
			return false;
		}
		if ((pKey != NULL) && (pKey->byCipherSuite == KEY_CTL_CCMP))
			FrameSize -= 8;         // Message Integrity Code
		else
			FrameSize -= 4;         // 4 is ICV
	}

	//
	// RX OK
	//
	//remove the CRC length
	FrameSize -= ETH_FCS_LEN;

	if ((!(*pbyRsr & (RSR_ADDRBROAD | RSR_ADDRMULTI))) && // unicast address
	    (IS_FRAGMENT_PKT((skb->data+4)))
) {
		// defragment
		bDeFragRx = WCTLbHandleFragment(pDevice, (PS802_11Header)(skb->data+4), FrameSize, bIsWEP, bExtIV);
		pDevice->s802_11Counter.ReceivedFragmentCount++;
		if (bDeFragRx) {
			// defrag complete
			skb = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].skb;
			FrameSize = pDevice->sRxDFCB[pDevice->uCurrentDFCBIdx].cbFrameLength;

		} else {
			return false;
		}
	}

// Management & Control frame Handle
	if ((IS_TYPE_DATA((skb->data+4))) == false) {
		// Handle Control & Manage Frame

		if (IS_TYPE_MGMT((skb->data+4))) {
			unsigned char *pbyData1;
			unsigned char *pbyData2;

			pRxPacket->p80211Header = (PUWLAN_80211HDR)(skb->data+4);
			pRxPacket->cbMPDULen = FrameSize;
			pRxPacket->uRSSI = *pbyRSSI;
			pRxPacket->bySQ = *pbySQ;
			HIDWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(HIDWORD(*pqwTSFTime));
			LODWORD(pRxPacket->qwLocalTSF) = cpu_to_le32(LODWORD(*pqwTSFTime));
			if (bIsWEP) {
				// strip IV
				pbyData1 = WLAN_HDR_A3_DATA_PTR(skb->data+4);
				pbyData2 = WLAN_HDR_A3_DATA_PTR(skb->data+4) + 4;
				for (ii = 0; ii < (FrameSize - 4); ii++) {
					*pbyData1 = *pbyData2;
					pbyData1++;
					pbyData2++;
				}
			}
			pRxPacket->byRxRate = s_byGetRateIdx(*pbyRxRate);
			pRxPacket->byRxChannel = (*pbyRxSts) >> 2;

			vMgrRxManagePacket((void *)pDevice, pDevice->pMgmt, pRxPacket);

			// hostap Deamon handle 802.11 management
			if (pDevice->bEnableHostapd) {
				skb->dev = pDevice->apdev;
				skb->data += 4;
				skb->tail += 4;
				skb_put(skb, FrameSize);
				skb_reset_mac_header(skb);
				skb->pkt_type = PACKET_OTHERHOST;
				skb->protocol = htons(ETH_P_802_2);
				memset(skb->cb, 0, sizeof(skb->cb));
				netif_rx(skb);
				return true;
			}
		}

		return false;
	} else {
Ejemplo n.º 27
0
 int wpa_set_keys(PSDevice pDevice, void *ctx, bool fcpfkernel)
{
    struct viawget_wpa_param *param=ctx;
    PSMgmtObject pMgmt = pDevice->pMgmt;
    unsigned long dwKeyIndex = 0;
    unsigned char abyKey[MAX_KEY_LEN];
    unsigned char abySeq[MAX_KEY_LEN];
    QWORD   KeyRSC;
    unsigned char byKeyDecMode = KEY_CTL_WEP;
	int ret = 0;
	int uu, ii;


	if (param->u.wpa_key.alg_name > WPA_ALG_CCMP ||
			param->u.wpa_key.key_len >= MAX_KEY_LEN ||
			param->u.wpa_key.seq_len >= MAX_KEY_LEN)
		return -EINVAL;

    DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "param->u.wpa_key.alg_name = %d \n", param->u.wpa_key.alg_name);
	if (param->u.wpa_key.alg_name == WPA_ALG_NONE) {
        pDevice->eEncryptionStatus = Ndis802_11EncryptionDisabled;
        pDevice->bEncryptionEnable = false;
        pDevice->byKeyIndex = 0;
        pDevice->bTransmitKey = false;
        KeyvRemoveAllWEPKey(&(pDevice->sKey), pDevice->PortOffset);
        for (uu=0; uu<MAX_KEY_TABLE; uu++) {
            MACvDisableKeyEntry(pDevice->PortOffset, uu);
        }
        return ret;
    }

    
    if(param->u.wpa_key.key && fcpfkernel) {
       memcpy(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len);
     }
    else {
	spin_unlock_irq(&pDevice->lock);
	if (param->u.wpa_key.key &&
	    copy_from_user(&abyKey[0], param->u.wpa_key.key, param->u.wpa_key.key_len)) {
	    spin_lock_irq(&pDevice->lock);
	    return -EINVAL;
    	}
spin_lock_irq(&pDevice->lock);
    	}

    dwKeyIndex = (unsigned long)(param->u.wpa_key.key_index);

	if (param->u.wpa_key.alg_name == WPA_ALG_WEP) {
        if (dwKeyIndex > 3) {
            return -EINVAL;
        }
        else {
            if (param->u.wpa_key.set_tx) {
                pDevice->byKeyIndex = (unsigned char)dwKeyIndex;
                pDevice->bTransmitKey = true;
		        dwKeyIndex |= (1 << 31);
            }
            KeybSetDefaultKey(&(pDevice->sKey),
                                dwKeyIndex & ~(BIT30 | USE_KEYRSC),
                                param->u.wpa_key.key_len,
                                NULL,
                                abyKey,
                                KEY_CTL_WEP,
                                pDevice->PortOffset,
                                pDevice->byLocalID);

        }
        pDevice->eEncryptionStatus = Ndis802_11Encryption1Enabled;
        pDevice->bEncryptionEnable = true;
        return ret;
	}

	    
        if(param->u.wpa_key.seq && fcpfkernel) {
           memcpy(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len);
        	}
       else {
	   	spin_unlock_irq(&pDevice->lock);
	if (param->u.wpa_key.seq &&
	    copy_from_user(&abySeq[0], param->u.wpa_key.seq, param->u.wpa_key.seq_len)) {
	    spin_lock_irq(&pDevice->lock);
	    return -EINVAL;
       	}
spin_lock_irq(&pDevice->lock);
}

	if (param->u.wpa_key.seq_len > 0) {
		for (ii = 0 ; ii < param->u.wpa_key.seq_len ; ii++) {
		     if (ii < 4)
			    LODWORD(KeyRSC) |= (abySeq[ii] << (ii * 8));
			 else
			    HIDWORD(KeyRSC) |= (abySeq[ii] << ((ii-4) * 8));
	         
		}
		dwKeyIndex |= 1 << 29;
	}

    if (param->u.wpa_key.key_index >= MAX_GROUP_KEY) {
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return  dwKeyIndex > 3\n");
        return -EINVAL;
    }

	if (param->u.wpa_key.alg_name == WPA_ALG_TKIP) {
        pDevice->eEncryptionStatus = Ndis802_11Encryption2Enabled;
    }

	if (param->u.wpa_key.alg_name == WPA_ALG_CCMP) {
        pDevice->eEncryptionStatus = Ndis802_11Encryption3Enabled;
    }

	if (param->u.wpa_key.set_tx)
		dwKeyIndex |= (1 << 31);


    if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled)
        byKeyDecMode = KEY_CTL_CCMP;
    else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled)
        byKeyDecMode = KEY_CTL_TKIP;
    else
        byKeyDecMode = KEY_CTL_WEP;

    
    if (pDevice->eEncryptionStatus == Ndis802_11Encryption3Enabled) {
        if (param->u.wpa_key.key_len == MAX_KEY_LEN)
            byKeyDecMode = KEY_CTL_TKIP;
        else if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
            byKeyDecMode = KEY_CTL_WEP;
        else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
            byKeyDecMode = KEY_CTL_WEP;
    } else if (pDevice->eEncryptionStatus == Ndis802_11Encryption2Enabled) {
        if (param->u.wpa_key.key_len == WLAN_WEP40_KEYLEN)
            byKeyDecMode = KEY_CTL_WEP;
        else if (param->u.wpa_key.key_len == WLAN_WEP104_KEYLEN)
            byKeyDecMode = KEY_CTL_WEP;
    }

    
    if ((byKeyDecMode == KEY_CTL_TKIP) &&
        (param->u.wpa_key.key_len != MAX_KEY_LEN)) {
        
        
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "return- TKIP Key must be 256 bits!\n");
        return -EINVAL;
    }
    
    if ((byKeyDecMode == KEY_CTL_CCMP) &&
        (param->u.wpa_key.key_len != AES_KEY_LEN)) {
        
        
        return -EINVAL;
    }

   
    if (is_broadcast_ether_addr(&param->addr[0]) || (param->addr == NULL)) {
        
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Groupe Key Assign.\n");

        if ((KeybSetAllGroupKey(&(pDevice->sKey),
                            dwKeyIndex,
                            param->u.wpa_key.key_len,
                            (PQWORD) &(KeyRSC),
                            (unsigned char *)abyKey,
                            byKeyDecMode,
                            pDevice->PortOffset,
                            pDevice->byLocalID) == true) &&
            (KeybSetDefaultKey(&(pDevice->sKey),
                            dwKeyIndex,
                            param->u.wpa_key.key_len,
                            (PQWORD) &(KeyRSC),
                            (unsigned char *)abyKey,
                            byKeyDecMode,
                            pDevice->PortOffset,
                            pDevice->byLocalID) == true) ) {
             DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "GROUP Key Assign.\n");

        } else {
            
           
            return -EINVAL;
        }

    } else {
        DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Assign.\n");
        
        
        if (byKeyDecMode == KEY_CTL_WEP) {
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key can't be WEP\n");
            
            return -EINVAL;
        }

        dwKeyIndex |= (1 << 30); 
        if (pMgmt->eConfigMode == WMAC_CONFIG_IBSS_STA) {
            
            
            return -EINVAL;
        }
        if (KeybSetKey(&(pDevice->sKey),
                       &param->addr[0],
                       dwKeyIndex,
                       param->u.wpa_key.key_len,
                       (PQWORD) &(KeyRSC),
                       (unsigned char *)abyKey,
                        byKeyDecMode,
                        pDevice->PortOffset,
                        pDevice->byLocalID) == true) {
            DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "Pairwise Key Set\n");

        } else {
            
            if (!compare_ether_addr(&param->addr[0], pDevice->abyBSSID)) {
                
                
                return -EINVAL;

            } else {
                
                
                
                return -EINVAL;
            }
        }
    } 
    if ((ret == 0) && ((param->u.wpa_key.set_tx) != 0)) {
        pDevice->byKeyIndex = (unsigned char)param->u.wpa_key.key_index;
        pDevice->bTransmitKey = true;
    }
    pDevice->bEncryptionEnable = true;
    


	return ret;

}
Ejemplo n.º 28
0
acpi_status
acpi_ev_gpe_initialize (void)
{
	u32                     i;
	u32                     j;
	u32                     register_index;
	u32                     gpe_number;
	u16                     gpe0register_count;
	u16                     gpe1_register_count;


	FUNCTION_TRACE ("Ev_gpe_initialize");

	/*
	 * Set up various GPE counts
	 *
	 * You may ask,why are the GPE register block lengths divided by 2?
	 * From the ACPI 2.0 Spec, section, 4.7.1.6 General-Purpose Event
	 * Registers, we have,
	 *
	 * "Each register block contains two registers of equal length
	 * GPEx_STS and GPEx_EN (where x is 0 or 1). The length of the
	 * GPE0_STS and GPE0_EN registers is equal to half the GPE0_LEN
	 * The length of the GPE1_STS and GPE1_EN registers is equal to
	 * half the GPE1_LEN. If a generic register block is not supported
	 * then its respective block pointer and block length values in the
	 * FADT table contain zeros. The GPE0_LEN and GPE1_LEN do not need
	 * to be the same size."
	 */
	gpe0register_count          = (u16) DIV_2 (acpi_gbl_FADT->gpe0blk_len);
	gpe1_register_count         = (u16) DIV_2 (acpi_gbl_FADT->gpe1_blk_len);
	acpi_gbl_gpe_register_count = gpe0register_count + gpe1_register_count;

	if (!acpi_gbl_gpe_register_count) {
		REPORT_WARNING (("Zero GPEs are defined in the FADT\n"));
		return_ACPI_STATUS (AE_OK);
	}

	/*
	 * Allocate the Gpe information block
	 */
	acpi_gbl_gpe_registers = ACPI_MEM_CALLOCATE (acpi_gbl_gpe_register_count *
			  sizeof (acpi_gpe_registers));
	if (!acpi_gbl_gpe_registers) {
		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR,
			"Could not allocate the Gpe_registers block\n"));
		return_ACPI_STATUS (AE_NO_MEMORY);
	}

	/*
	 * Allocate the Gpe dispatch handler block
	 * There are eight distinct GP events per register.
	 * Initialization to zeros is sufficient
	 */
	acpi_gbl_gpe_info = ACPI_MEM_CALLOCATE (MUL_8 (acpi_gbl_gpe_register_count) *
			  sizeof (acpi_gpe_level_info));
	if (!acpi_gbl_gpe_info) {
		ACPI_MEM_FREE (acpi_gbl_gpe_registers);
		ACPI_DEBUG_PRINT ((ACPI_DB_ERROR, "Could not allocate the Gpe_info block\n"));
		return_ACPI_STATUS (AE_NO_MEMORY);
	}

	/* Set the Gpe validation table to GPE_INVALID */

	MEMSET (acpi_gbl_gpe_valid, (int) ACPI_GPE_INVALID, ACPI_NUM_GPE);

	/*
	 * Initialize the Gpe information and validation blocks.  A goal of these
	 * blocks is to hide the fact that there are two separate GPE register sets
	 * In a given block, the status registers occupy the first half, and
	 * the enable registers occupy the second half.
	 */

	/* GPE Block 0 */

	register_index = 0;

	for (i = 0; i < gpe0register_count; i++) {
		acpi_gbl_gpe_registers[register_index].status_addr =
				 (u16) (ACPI_GET_ADDRESS (acpi_gbl_FADT->Xgpe0blk.address) + i);

		acpi_gbl_gpe_registers[register_index].enable_addr =
				 (u16) (ACPI_GET_ADDRESS (acpi_gbl_FADT->Xgpe0blk.address) + i + gpe0register_count);

		acpi_gbl_gpe_registers[register_index].gpe_base = (u8) MUL_8 (i);

		for (j = 0; j < 8; j++) {
			gpe_number = acpi_gbl_gpe_registers[register_index].gpe_base + j;
			acpi_gbl_gpe_valid[gpe_number] = (u8) register_index;
		}

		/*
		 * Clear the status/enable registers.  Note that status registers
		 * are cleared by writing a '1', while enable registers are cleared
		 * by writing a '0'.
		 */
		acpi_os_write_port (acpi_gbl_gpe_registers[register_index].enable_addr, 0x00, 8);
		acpi_os_write_port (acpi_gbl_gpe_registers[register_index].status_addr, 0xFF, 8);

		register_index++;
	}

	/* GPE Block 1 */

	for (i = 0; i < gpe1_register_count; i++) {
		acpi_gbl_gpe_registers[register_index].status_addr =
				 (u16) (ACPI_GET_ADDRESS (acpi_gbl_FADT->Xgpe1_blk.address) + i);

		acpi_gbl_gpe_registers[register_index].enable_addr =
				 (u16) (ACPI_GET_ADDRESS (acpi_gbl_FADT->Xgpe1_blk.address) + i + gpe1_register_count);

		acpi_gbl_gpe_registers[register_index].gpe_base =
				 (u8) (acpi_gbl_FADT->gpe1_base + MUL_8 (i));

		for (j = 0; j < 8; j++) {
			gpe_number = acpi_gbl_gpe_registers[register_index].gpe_base + j;
			acpi_gbl_gpe_valid[gpe_number] = (u8) register_index;
		}

		/*
		 * Clear the status/enable registers.  Note that status registers
		 * are cleared by writing a '1', while enable registers are cleared
		 * by writing a '0'.
		 */
		acpi_os_write_port (acpi_gbl_gpe_registers[register_index].enable_addr, 0x00, 8);
		acpi_os_write_port (acpi_gbl_gpe_registers[register_index].status_addr, 0xFF, 8);

		register_index++;
	}

	ACPI_DEBUG_PRINT ((ACPI_DB_INFO, "GPE registers: %X@%8.8X%8.8X (Blk0) %X@%8.8X%8.8X (Blk1)\n",
		gpe0register_count, HIDWORD(acpi_gbl_FADT->Xgpe0blk.address), LODWORD(acpi_gbl_FADT->Xgpe0blk.address),
		gpe1_register_count, HIDWORD(acpi_gbl_FADT->Xgpe1_blk.address), LODWORD(acpi_gbl_FADT->Xgpe1_blk.address)));

	return_ACPI_STATUS (AE_OK);
}