void nRF5xCharacteristicDescriptorDiscoverer::terminate(Discovery* discovery, ble_error_t err) {
    // temporary copy, user code can try to launch a new discovery in the onTerminate
    // callback. So, this discovery should not appear in such case.
    Discovery tmp = *discovery;
    *discovery = Discovery();
    tmp.terminate(err);
}
ble_error_t nRF5xCharacteristicDescriptorDiscoverer::launch(
    const DiscoveredCharacteristic& characteristic,
    const CharacteristicDescriptorDiscovery::DiscoveryCallback_t& discoveryCallback,
    const CharacteristicDescriptorDiscovery::TerminationCallback_t& terminationCallback
) {
    Gap::Handle_t connHandle = characteristic.getConnectionHandle();
    // it is ok to deduce that the start handle for descriptors is after
    // the characteristic declaration and the characteristic value declaration
    // see BLUETOOTH SPECIFICATION Version 4.2 [Vol 3, Part G] (3.3)
    Gap::Handle_t descriptorStartHandle = characteristic.getDeclHandle() + 2;
    Gap::Handle_t descriptorEndHandle = characteristic.getLastHandle();

    // check if there is any descriptor to discover
    if (descriptorEndHandle < descriptorStartHandle) {
        CharacteristicDescriptorDiscovery::TerminationCallbackParams_t termParams = {
            characteristic,
            BLE_ERROR_NONE
        };
        terminationCallback.call(&termParams);
        return BLE_ERROR_NONE;
    }

    // check if we can run this discovery
    if (isConnectionInUse(connHandle)) {
        return BLE_STACK_BUSY;
    }

    // get a new discovery slot, if none are available, just return
    Discovery* discovery = getAvailableDiscoverySlot();
    if(discovery == NULL) {
        return BLE_STACK_BUSY;
    }

    // try to launch the discovery
    ble_error_t err = gattc_descriptors_discover(connHandle, descriptorStartHandle, descriptorEndHandle);
    if(!err) {
        // commit the new discovery to its slot
        *discovery = Discovery(characteristic, discoveryCallback, terminationCallback);
    }

    return err;
}
示例#3
0
BOOL 
CNdasDevice::GetDeviceInfo(
	const LPX_ADDRESS& localAddress, 
	const LPX_ADDRESS& remoteAddress,
	UCHAR ucType,
	UCHAR ucVersion)
{
	ximeta::CAutoLock autolock(this);

	//
	// Get Device Information
	//
	LANSCSI_PATH lspath = {0};

	// Discover does not need any user id
	lspath.iUserID = 0x0000;
	lspath.iPassword = GetHWPassword();

	lspath.HWType = ucType;
	lspath.HWVersion = ucVersion;
	lspath.HWProtoType = ucType;
	lspath.HWProtoVersion = 
		(LANSCSIIDE_VERSION_1_1 == ucVersion) ?
		LSIDEPROTO_VERSION_1_1 : 
		LSIDEPROTO_VERSION_1_0;

	//
	// create an LPX (auto) socket
	//

	AutoSocket autoSock = CreateLpxConnection(&remoteAddress, &localAddress);

	//
	// autoSock will close the handle when it goes out of scope
	//

	if (INVALID_SOCKET == (SOCKET) autoSock) 
	{
		//
		// TODO: EVENTLOG NDAS_DEVICE_ERROR_LPX_SOCKET_FAILED
		//
		DBGPRT_ERR_EX(_FT("Error Create Connection: "));
		SetLastDeviceError(NDAS_DEVICE_ERROR_LPX_SOCKET_FAILED);
		return FALSE;
	}

	//
	// Discover
	//
	lspath.connsock = autoSock;
	INT iResult = Discovery(&lspath);
	if (0 != iResult) {
		//
		// TODO: EVENTLOG NDAS_DEVICE_ERROR_DISCOVER_FAILED
		//
		DBGPRT_ERR_EX(_FT("Discovery failed! - returned (%d) : "), iResult);
		SetLastDeviceError(NDAS_DEVICE_ERROR_DISCOVER_FAILED);
		return FALSE;
	}

	//
	// If discovering succeeded, set pController's
	// LANSCSI path to discovered LANSCSI path
	//
	m_hwInfo.nMaxRequestBlocks = lspath.iMaxBlocks;
	m_hwInfo.nSlots = lspath.iNumberofSlot;
	m_hwInfo.nTargets = lspath.iNRTargets;
	m_hwInfo.nMaxTargets = lspath.iMaxTargets;
	m_hwInfo.nMaxLUs = lspath.iMaxLUs;

	::CopyMemory(&m_localLpxAddress, &localAddress, sizeof(LPX_ADDRESS));
	::CopyMemory(&m_remoteLpxAddress, &remoteAddress, sizeof(LPX_ADDRESS));

	//
	// actual hardware type and version is filled in lspath
	//

	m_hwInfo.ucType = lspath.HWType;
	m_hwInfo.ucVersion = lspath.HWVersion;

	//
	// at discovery only lspath.PerTarget[i].NORWHost and NOROHost are valid.
	//

	for (DWORD i = 0; i < MAX_NDAS_UNITDEVICE_COUNT; i++) 
	{
		m_fUnitDevicePresent[i] = lspath.PerTarget[i].bPresent;
		if (NULL != m_pUnitDevices[i]) 
		{
			m_pUnitDevices[i]->SetHostUsageCount(
				lspath.PerTarget[i].NRROHost,
				lspath.PerTarget[i].NRRWHost);
		}

	}

	return TRUE;
}
示例#4
0
BOOL NDAS_GetStatus(UNIT_DISK_LOCATION *pUnitDisk, PNDAS_STATUS pStatus)
{
	BOOL bReturn = FALSE;
	IDE_COMMAND_IO cmd[2];
	LONG lResult;

	HKEY hKeyNetDisks;
	HKEY hKey;
	UINT i;
    CHAR     achKey[MAX_KEY_LENGTH];   // buffer for subkey name
    DWORD    cbName;                   // size of name string 
    FILETIME ftLastWriteTime;      // last write time 
	CHAR szAddress[MAX_VALUE_NAME], szAddress2[18];
	UCHAR szSerial[MAX_VALUE_NAME];
	DWORD dwType;
	DWORD dwSize;
	
	LPX_ADDRESS address;
	LANSCSI_PATH path;

	DISK_INFORMATION_BLOCK *pDiskInfoV1;
	DISK_INFORMATION_BLOCK_V2 *pDiskInfoV2;
	
	DebugPrint(1, ("[NDASOpLib] NDAS_GetStatus : %02X:%02X:%02X:%02X:%02X:%02X\n",
		(int)pUnitDisk->MACAddr[0],
		(int)pUnitDisk->MACAddr[1],
		(int)pUnitDisk->MACAddr[2],
		(int)pUnitDisk->MACAddr[3],
		(int)pUnitDisk->MACAddr[4],
		(int)pUnitDisk->MACAddr[5]
		));

	ZeroMemory(&path, sizeof(LANSCSI_PATH));
	CopyMemory(address.Node, pUnitDisk->MACAddr, 6);

	if(NULL == pStatus)
		goto out;

	ZeroMemory(pStatus, sizeof(NDAS_STATUS));

	// Registry check start.
	// AING_TO_DO : use NDAS registry functions
	lResult = RegOpenKeyEx(
		HKEY_LOCAL_MACHINE,
		KEY_NAME_NETDISKS,
		0,
		KEY_READ,
		&hKeyNetDisks
		);

	if(ERROR_SUCCESS != lResult)
		goto out;

	sprintf(szAddress2, "%02x:%02x:%02x:%02x:%02x:%02x",
		pUnitDisk->MACAddr[0],
		pUnitDisk->MACAddr[1],
		pUnitDisk->MACAddr[2],
		pUnitDisk->MACAddr[3],
		pUnitDisk->MACAddr[4],
		pUnitDisk->MACAddr[5]);

	i = 0;

	while(1)
	{
		cbName = MAX_KEY_LENGTH;
		lResult = RegEnumKeyEx(
			hKeyNetDisks,
			i++,
			achKey,
			&cbName,
			NULL,
			NULL,
			NULL,
			&ftLastWriteTime);

		if(ERROR_SUCCESS != lResult)
			goto out;

		lResult = RegOpenKeyEx(
			hKeyNetDisks,
			achKey,
			0,
			KEY_READ,
			&hKey
			);

		if(ERROR_SUCCESS != lResult)
			goto out;

		dwSize = MAX_VALUE_NAME;
		
		lResult = RegQueryValueEx(
			hKey,
			"Address",
			0,
			&dwType,
			szAddress,
			&dwSize);

		if(ERROR_SUCCESS != lResult)
			continue;

		if(stricmp(szAddress, szAddress2))
			continue;

		pStatus->IsRegistered = 1;

		dwSize = MAX_VALUE_NAME;
		
		lResult = RegQueryValueEx(
			hKey,
			"SerialKey",
			0,
			&dwType,
			szSerial,
			&dwSize);

		DebugPrint(1, ("[NDASOpLib] NDAS_GetStatus : lResult  = %d szSerial = %x %x %x %x %x %x %x %x %x, %d\n", 
			lResult,
			(int)szSerial[0],
			(int)szSerial[1],
			(int)szSerial[2],
			(int)szSerial[3],
			(int)szSerial[4],
			(int)szSerial[5],
			(int)szSerial[6],
			(int)szSerial[7],
			(int)szSerial[8],
			(szSerial[8] == 0xff)
			));
		
		if(ERROR_SUCCESS == lResult && szSerial[8] == 0xff)
		{
			pStatus->IsRegisteredWritable = 1;
		}

		break;
	}

	// Registry check end.

	// Connect
	if(!MakeConnection(&address, &path) || (unsigned int)NULL == path.connsock)
	{
		DebugPrint(1, ("[NDASOpLib] NDAS_GetStatus : MakeConnection Failed\n"));
		goto out;
	}

	pStatus->IsAlive = 1;

	// Login
	// if we don't write, login read only
	path.iUserID = (pUnitDisk->SlotNumber +1);

	path.iCommandTag = 0;
	path.HPID = 0;
	path.iHeaderEncryptAlgo = 0;
	path.iDataEncryptAlgo = 0;
	NDAS_SetPassword(address.Node, &path.iPassword);
	path.iSessionPhase = LOGOUT_PHASE;

	if(Login(&path, LOGIN_TYPE_NORMAL))
	{
		DebugPrint(1, ("[NDASOpLib] NDAS_GetStatus : Login Failed\n"));
		goto out;
	}
	
	if(GetDiskInfo(&path, pUnitDisk->SlotNumber))
	{
		DebugPrint(1, ("[NDASOpLib] NDAS_GetStatus : GetDiskInfo Failed\n"));
		goto out;
	}

	if(Logout(&path))
	{
		DebugPrint(1, ("[NDASOpLib] NDAS_GetStatus : Logout Failed\n"));
		goto out;
	}

	if(0 != Discovery(&path))
	{
		DebugPrint(1, ("[NDASOpLib] NDAS_GetStatus : Discovery Failed\n"));
		goto out;
	}

	closesocket(path.connsock);

	pStatus->IsDiscovered = 1;
	pStatus->HWVersion = path.HWVersion;
	pStatus->HWProtoVersion = path.HWProtoVersion;
	pStatus->NrUserReadWrite = path.PerTarget[pUnitDisk->SlotNumber].NRRWHost;
	pStatus->NrUserReadOnly = path.PerTarget[pUnitDisk->SlotNumber].NRROHost;

	if(MEDIA_TYPE_BLOCK_DEVICE != path.PerTarget[pUnitDisk->SlotNumber].MediaType)
	{
		switch(path.PerTarget[pUnitDisk->SlotNumber].MediaType)
		{
		case MEDIA_TYPE_CDROM_DEVICE:
			pStatus->DiskType = DISK_TYPE_DVD;
			pStatus->IsSupported = 1;
			break;

		case MEDIA_TYPE_OPMEM_DEVICE:
			pStatus->DiskType = DISK_TYPE_MO;
			pStatus->IsSupported = 1;
			break;
		default:
			pStatus->IsSupported = 0;
		}

		DebugPrint(1, ("[NDASOpLib] NDAS_GetStatus : Packet type %d\n", path.PerTarget[pUnitDisk->SlotNumber].MediaType));
		bReturn = TRUE;
		goto out;
	}

	cmd[0].command = WIN_READ;
	cmd[0].iSector = -1;
	pDiskInfoV1 = (PDISK_INFORMATION_BLOCK)cmd[0].data;
	cmd[1].command = WIN_READ;
	cmd[1].iSector = -2;
	pDiskInfoV2 = (PDISK_INFORMATION_BLOCK_V2)cmd[1].data;

	NDAS_IdeIO(pUnitDisk, 2, cmd, NULL);

	if(DISK_INFORMATION_SIGNATURE_V2 == pDiskInfoV2->Signature)
	{
		pStatus->MajorVersion = pDiskInfoV2->MajorVersion;
		pStatus->MinorVersion = pDiskInfoV2->MinorVersion;

		if(IS_NDAS_DIB_V2_VERSION_HIGH(*pDiskInfoV2))
			goto out;

		pStatus->IsSupported = 1;

		pStatus->DiskType = 
			(1 == pDiskInfoV2->nDiskCount) ? DISK_TYPE_NORMAL :
			(NMT_RAID1 == pDiskInfoV2->iMediaType) ? DISK_TYPE_BIND_RAID1 :
			(NMT_VDVD == pDiskInfoV2->iMediaType) ? DISK_TYPE_VDVD :
			DISK_TYPE_AGGREGATION;
	}
	else if(DISK_INFORMATION_SIGNATURE == pDiskInfoV1->Signature)
	{
		pStatus->MajorVersion = pDiskInfoV1->MajorVersion;
		pStatus->MinorVersion = pDiskInfoV1->MinorVersion;
		
		if(IS_WRONG_VERSION(*pDiskInfoV1))
			goto out;
	
		pStatus->IsSupported = 1;

		pStatus->DiskType = 
			(UNITDISK_TYPE_SINGLE == pDiskInfoV1->DiskType) ? DISK_TYPE_NORMAL :
			(UNITDISK_TYPE_AGGREGATION_FIRST == pDiskInfoV1->DiskType) ? DISK_TYPE_AGGREGATION :
			(UNITDISK_TYPE_AGGREGATION_SECOND == pDiskInfoV1->DiskType) ? DISK_TYPE_AGGREGATION :
			(UNITDISK_TYPE_AGGREGATION_THIRD == pDiskInfoV1->DiskType) ? DISK_TYPE_AGGREGATION :
			(UNITDISK_TYPE_AGGREGATION_FOURTH == pDiskInfoV1->DiskType) ? DISK_TYPE_AGGREGATION :
			(UNITDISK_TYPE_MIRROR_MASTER == pDiskInfoV1->DiskType) ? DISK_TYPE_BIND_RAID1 :
			(UNITDISK_TYPE_MIRROR_SLAVE == pDiskInfoV1->DiskType) ? DISK_TYPE_BIND_RAID1 :
			(UNITDISK_TYPE_VDVD == pDiskInfoV1->DiskType) ? DISK_TYPE_VDVD : 0;
	}
	else
	{
		pStatus->MajorVersion = 0;
		pStatus->MinorVersion = 0;
		pStatus->DiskType = DISK_TYPE_NORMAL;
		pStatus->IsSupported = 1;
	}

	bReturn = TRUE;
out:
	if(path.connsock)
		closesocket(path.connsock);

	return bReturn;
}
bool nRF5xCharacteristicDescriptorDiscoverer::Discovery::isEmpty() const {
    return *this == Discovery();
}