예제 #1
0
int gmShellPlink::pscp_execute(const gmdString& args){
  int i, res;
  gmdString errmsg;

  if(!auth_defined)
    LOGJOBERR("Authentification method are not defined, "
      "check 'login', 'host' and 'plink_args' parameters!");

  if(dump_commands)
    LOGJOBMSG4( (pCSTR) ("------ pscp_execute ------\n"
                         " cmd=" + pscp_pre + args + "\n"
              ));

  for(i=0; i<plink_att_num; i++){

    if(i) {  // Retrying on a network error
      LOGJOBMSG( fmt("PLINK connection failed: %s\nRetrying %d more times",
                     (const gmdChar*)errmsg, plink_att_num - i) );
      gmdMilliSleep(plink_retry_delay);  // delay before a retry
    }

    gmdArrayString out, err;
    //ttimer.Resume();
    res = gmdExecute(pscp_pre + args, out, err);
    //ttimer.Pause();
    if(res == -1) 
      return( set_err(EXECUTE_ERROR, "Error executing PSCP!") );

    if(dump_commands && res != 0)
      LOGJOBMSG4( (pCSTR) ("------ pscp_execute (error)------\n"
                           " cout=" + ArrayToString(out)+"\n"
                           " cerr=" + ArrayToString(err)+"\n"
                ));


    if(res == 0) break;

    errmsg = ArrayToString(err);
    if( !errmsg.StartsWith("Fatal: Network error:") ) break;
  }
  
  if(res) { // Replace 'res' by an internal error code
    if(i >= plink_att_num) res = CONNECTION_ERROR;
    else if( ( errmsg.Contains("no such file or directory") ||
               errmsg.Contains("matched no files") ) &&
             !errmsg.Contains("unable to open")
           ) res = NO_INPUT_FILE;
    else res = COPY_ERROR;
    set_err(res, errmsg);
  }

  return res;
}
예제 #2
0
void ReadThreadHandler(CEXIETHERNET* self)
{
	while (true)
	{
		if (self->fd < 0)
			return;

		fd_set rfds;
		FD_ZERO(&rfds);
		FD_SET(self->fd, &rfds);

		struct timeval timeout;
		timeout.tv_sec = 0;
		timeout.tv_usec = 50000;
		if (select(self->fd + 1, &rfds, NULL, NULL, &timeout) <= 0)
			continue;

		int readBytes = read(self->fd, self->mRecvBuffer, BBA_RECV_SIZE);
		if (readBytes < 0)
		{
			ERROR_LOG(SP1, "Failed to read from BBA, err=%d", readBytes);
		}
		else if (self->readEnabled)
		{
			INFO_LOG(SP1, "Read data: %s", ArrayToString(self->mRecvBuffer, readBytes, 0x10).c_str());
			self->mRecvBufferLength = readBytes;
			self->RecvHandlePacket();
		}
	}
}
예제 #3
0
bool CEXIETHERNET::SendFrame(u8 *frame, u32 size)
{
	DEBUG_LOG(SP1, "SendFrame %x\n%s",
		size, ArrayToString(frame, size, 0x10).c_str());

	DWORD numBytesWrit;
	OVERLAPPED overlap;
	ZeroMemory(&overlap, sizeof(overlap));

	if (!WriteFile(mHAdapter, frame, size, &numBytesWrit, &overlap))
	{
		DWORD res = GetLastError();
		ERROR_LOG(SP1, "Failed to send packet with error 0x%X", res);
	}

	if (numBytesWrit != size)
	{
		ERROR_LOG(SP1, "BBA SendFrame %i only got %i bytes sent!", size, numBytesWrit);
	}

	// Always report the packet as being sent successfully, even though it might be a lie
	SendComplete();

	return true;
}
예제 #4
0
static void ReadThreadHandler(CEXIETHERNET* self)
{
  while (!self->readThreadShutdown.IsSet())
  {
    fd_set rfds;
    FD_ZERO(&rfds);
    FD_SET(self->fd, &rfds);

    struct timeval timeout;
    timeout.tv_sec = 0;
    timeout.tv_usec = 50000;
    if (select(self->fd + 1, &rfds, nullptr, nullptr, &timeout) <= 0)
      continue;

    int readBytes = read(self->fd, self->mRecvBuffer.get(), BBA_RECV_SIZE);
    if (readBytes < 0)
    {
      ERROR_LOG(SP1, "Failed to read from BBA, err=%d", readBytes);
    }
    else if (self->readEnabled.IsSet())
    {
      DEBUG_LOG(SP1, "Read data: %s",
                ArrayToString(self->mRecvBuffer.get(), readBytes, 0x10).c_str());
      self->mRecvBufferLength = readBytes;
      self->RecvHandlePacket();
    }
  }
}
예제 #5
0
	/* This is called continuously from the Wiimote plugin as soon as it has received
	   a reporting mode. _Size is the byte size of the report. */
	void Callback_WiimoteInterruptChannel(int _number, u16 _channelID, const void* _pData, u32 _Size)
	{
		const u8* pData = (const u8*)_pData;

		INFO_LOG(WIIMOTE, "====================");
		INFO_LOG(WIIMOTE, "Callback_WiimoteInterruptChannel: (Wiimote: #%i)", _number);
		DEBUG_LOG(WIIMOTE, "   Data: %s", ArrayToString(pData, _Size, 50).c_str());
		DEBUG_LOG(WIIMOTE, "   Channel: %x", _channelID);

		s_Usb->m_WiiMotes[_number].ReceiveL2capData(_channelID, _pData, _Size);
	}
예제 #6
0
std::string ByAlbum(SortAttribute attributes, const SortItem &values)
{
  std::string album = values.at(FieldAlbum).asString();
  if (attributes & SortAttributeIgnoreArticle)
    album = SortUtils::RemoveArticles(album);

  std::string label = StringUtils::Format("%s %s", album.c_str(), ArrayToString(attributes, values.at(FieldArtist)).c_str());

  const CVariant &track = values.at(FieldTrackNumber);
  if (!track.isNull())
    label += StringUtils::Format(" %i", (int)track.asInteger());

  return label;
}
예제 #7
0
std::string ByArtist(SortAttribute attributes, const SortItem &values)
{
  std::string label = ArrayToString(attributes, values.at(FieldArtist));

  const CVariant &album = values.at(FieldAlbum);
  if (!album.isNull())
    label += " " + SortUtils::RemoveArticles(album.asString());

  const CVariant &track = values.at(FieldTrackNumber);
  if (!track.isNull())
    label += StringUtils::Format(" %i", (int)track.asInteger());

  return label;
}
예제 #8
0
int gmShellPlink::execute(const gmdString& cmd, gmdArrayString& out, gmdArrayString& err){
  // Execute Shell command
  int i, res;
  gmdString errmsg;

  execute_begin(cmd, out, err);

  if(!auth_defined)
    return execute_error(
      set_err(CONNECTION_ERROR,
        "PLINK: Authentification method is not defined, "
        "check 'login', 'host' and 'plink_args' parameters!" )
      );

  // Screed double quotes
  gmdString cmd_scr(cmd);
  cmd_scr.Replace("\"", "\\\"");
  // Avoid empty command that switches plink into the interactive mode
  if( cmd_scr.IsEmpty() ) cmd_scr = "#";

  for(i=0; i<plink_att_num; i++){
    if(i) {  // Retrying on a network error
      LOGJOBMSG( fmt("PLINK connection failed: %s\nRetrying %d more times",
                     (const gmdChar*)errmsg, plink_att_num - i) );
      gmdMilliSleep(plink_retry_delay);  // delay before a retry
    }

    if(dump_commands)
      LOGJOBMSG4( (pCSTR)("------ execute (plink)------\n" + plink_pre + cmd_scr + '\"') );

    res = gmdExecute(plink_pre + cmd_scr + '\"', out, err);
    if(res == -1) {
      execute_end(res, out, err);
      return execute_error( set_err(EXECUTE_ERROR, "Error executing PLINK") );
    }
    else if(res == 0)
      break;

    errmsg = ArrayToString(err);
    if( !errmsg.StartsWith("Unable to open connection") ) break;
  }
  
  if(i >= plink_att_num){ 
    execute_end(-1, out, err); // pausing timer
    return  set_err(CONNECTION_ERROR, errmsg);
  }

  return execute_end(res, out, err);
}
예제 #9
0
bool CEXIETHERNET::SendFrame(const u8* frame, u32 size)
{
  INFO_LOG(SP1, "SendFrame %x\n%s", size, ArrayToString(frame, size, 0x10).c_str());

  int writtenBytes = write(fd, frame, size);
  if ((u32)writtenBytes != size)
  {
    ERROR_LOG(SP1, "SendFrame(): expected to write %d bytes, instead wrote %d", size, writtenBytes);
    return false;
  }
  else
  {
    SendComplete();
    return true;
  }
}
예제 #10
0
static void ReadThreadHandler(CEXIETHERNET* self)
{
  while (!self->readThreadShutdown.IsSet())
  {
    DWORD transferred;

    // Read from TAP into internal buffer.
    if (ReadFile(self->mHAdapter, self->mRecvBuffer.get(), BBA_RECV_SIZE, &transferred,
                 &self->mReadOverlapped))
    {
      // Returning immediately is not likely to happen, but if so, reset the event state manually.
      ResetEvent(self->mReadOverlapped.hEvent);
    }
    else
    {
      // IO should be pending.
      if (GetLastError() != ERROR_IO_PENDING)
      {
        ERROR_LOG(SP1, "ReadFile failed (err=0x%X)", GetLastError());
        continue;
      }

      // Block until the read completes.
      if (!GetOverlappedResult(self->mHAdapter, &self->mReadOverlapped, &transferred, TRUE))
      {
        // If CancelIO was called, we should exit (the flag will be set).
        if (GetLastError() == ERROR_OPERATION_ABORTED)
          continue;

        // Something else went wrong.
        ERROR_LOG(SP1, "GetOverlappedResult failed (err=0x%X)", GetLastError());
        continue;
      }
    }

    // Copy to BBA buffer, and fire interrupt if enabled.
    DEBUG_LOG(SP1, "Received %u bytes:\n %s", transferred,
              ArrayToString(self->mRecvBuffer.get(), transferred, 0x10).c_str());
    if (self->readEnabled.IsSet())
    {
      self->mRecvBufferLength = transferred;
      self->RecvHandlePacket();
    }
  }
}
예제 #11
0
bool CEXIETHERNET::SendFrame(const u8* frame, u32 size)
{
#ifdef __linux__
  DEBUG_LOG(SP1, "SendFrame %x\n%s", size, ArrayToString(frame, size, 0x10).c_str());

  int writtenBytes = write(fd, frame, size);
  if ((u32)writtenBytes != size)
  {
    ERROR_LOG(SP1, "SendFrame(): expected to write %d bytes, instead wrote %d", size, writtenBytes);
    return false;
  }
  else
  {
    SendComplete();
    return true;
  }
#else
  NOTIMPLEMENTED("SendFrame");
  return false;
#endif
}
예제 #12
0
bool CEXIETHERNET::SendFrame(u8 *frame, u32 size)
{
	DEBUG_LOG(SP1, "SendFrame %x\n%s",
		size, ArrayToString(frame, size, 0x10).c_str());

	OVERLAPPED overlap;
	ZeroMemory(&overlap, sizeof(overlap));

	// WriteFile will always return false because the TAP handle is async
	WriteFile(mHAdapter, frame, size, nullptr, &overlap);

	DWORD res = GetLastError();
	if (res != ERROR_IO_PENDING)
	{
		ERROR_LOG(SP1, "Failed to send packet with error 0x%X", res);
	}

	// Always report the packet as being sent successfully, even though it might be a lie
	SendComplete();

	return true;
}
예제 #13
0
bool CEXIETHERNET::SendFrame(const u8* frame, u32 size)
{
  DEBUG_LOG(SP1, "SendFrame %u bytes:\n%s", size, ArrayToString(frame, size, 0x10).c_str());

  // Check for a background write. We can't issue another one until this one has completed.
  DWORD transferred;
  if (mWritePending)
  {
    // Wait for previous write to complete.
    if (!GetOverlappedResult(mHAdapter, &mWriteOverlapped, &transferred, TRUE))
      ERROR_LOG(SP1, "GetOverlappedResult failed (err=0x%X)", GetLastError());
  }

  // Copy to write buffer.
  mWriteBuffer.assign(frame, frame + size);
  mWritePending = true;

  // Queue async write.
  if (WriteFile(mHAdapter, mWriteBuffer.data(), size, &transferred, &mWriteOverlapped))
  {
    // Returning immediately is not likely to happen, but if so, reset the event state manually.
    ResetEvent(mWriteOverlapped.hEvent);
  }
  else
  {
    // IO should be pending.
    if (GetLastError() != ERROR_IO_PENDING)
    {
      ERROR_LOG(SP1, "WriteFile failed (err=0x%X)", GetLastError());
      ResetEvent(mWriteOverlapped.hEvent);
      mWritePending = false;
      return false;
    }
  }

  // Always report the packet as being sent successfully, even though it might be a lie
  SendComplete();
  return true;
}
예제 #14
0
void CWII_IPC_HLE_Device_usb_oh0_57e_308::SetRegister(const u32 cmd_ptr)
{
	WARN_LOG(OSHLE, "cmd -> %s",
		ArrayToString(Memory::GetPointer(cmd_ptr), 10, 16).c_str());

	const u8 reg = Memory::Read_U8(cmd_ptr + 1) & ~1;
	const u16 arg1 = Memory::Read_U16(cmd_ptr + 2);
	const u16 arg2 = Memory::Read_U16(cmd_ptr + 4);
	//u16 arg3 = Memory::Read_U16(cmd_ptr + 6);
	//u16 count = Memory::Read_U16(cmd_ptr + 8);

	_dbg_assert_(OSHLE, Memory::Read_U8(cmd_ptr) == 0x9a);
	_dbg_assert_(OSHLE, (Memory::Read_U8(cmd_ptr + 1) & 1) == 0);

	switch (reg)
	{
	case SAMPLER_STATE:
		sampler.sample_on = !!arg1;
		break;
	case SAMPLER_FREQ:
		switch (arg1)
		{
		case FREQ_8KHZ:
			sampler.freq = 8000;
			break;
		case FREQ_11KHZ:
			sampler.freq = 11025;
			break;
		case FREQ_RESERVED:
		case FREQ_16KHZ:
		default:
			sampler.freq = 16000;
			break;
		}
		break;
	case SAMPLER_GAIN:
		switch (arg1 & ~0x300)
		{
		case GAIN_00dB:
			sampler.gain = 0;
			break;
		case GAIN_15dB:
			sampler.gain = 15;
			break;
		case GAIN_30dB:
			sampler.gain = 30;
			break;
		case GAIN_36dB:
		default:
			sampler.gain = 36;
			break;
		}
		break;
	case EC_STATE:
		sampler.ec_reset = !!arg1;
		break;
	case SP_STATE:
		switch (arg1)
		{
		case SP_ENABLE:
			sampler.sp_on = arg2 == 0;
			break;
		case SP_SIN:
			break;
		case SP_SOUT:
			break;
		case SP_RIN:
			break;
		}
		break;
	case SAMPLER_MUTE:
		sampler.mute = !!arg1;
		break;
	}
}
예제 #15
0
// This function receives L2CAP commands from the CPU
void CWII_IPC_HLE_WiiMote::ExecuteL2capCmd(u8* _pData, u32 _Size)
{
	// parse the command
	l2cap_hdr_t* pHeader = (l2cap_hdr_t*)_pData;
	u8* pData = _pData + sizeof(l2cap_hdr_t);
	u32 DataSize = _Size - sizeof(l2cap_hdr_t);
	INFO_LOG(WII_IPC_WIIMOTE, "  CID 0x%04x, Len 0x%x, DataSize 0x%x", pHeader->dcid, pHeader->length, DataSize);

	if (pHeader->length != DataSize)
	{
		INFO_LOG(WII_IPC_WIIMOTE, "Faulty packet. It is dropped.");
		return;
	}

	switch (pHeader->dcid)
	{
	case L2CAP_SIGNAL_CID:
		SignalChannel(pData, DataSize);
		break;

	default:
		{
			_dbg_assert_msg_(WII_IPC_WIIMOTE, DoesChannelExist(pHeader->dcid), "L2CAP: SendACLPacket to unknown channel %i", pHeader->dcid);
			CChannelMap::iterator  itr= m_Channel.find(pHeader->dcid);

			const int number = m_ConnectionHandle & 0xFF;

			if (itr != m_Channel.end())
			{
				SChannel& rChannel = itr->second;
				switch (rChannel.PSM)
				{
				case L2CAP_PSM_SDP:
					HandleSDP(pHeader->dcid, pData, DataSize);
					break;

				case L2CAP_PSM_HID_CNTL:
					if (number < MAX_BBMOTES)
						Wiimote::ControlChannel(number, pHeader->dcid, pData, DataSize);
					break;

				case L2CAP_PSM_HID_INTR:
					{
						if (number < MAX_BBMOTES)
						{
							DEBUG_LOG(WIIMOTE, "Wiimote_InterruptChannel");
							DEBUG_LOG(WIIMOTE, "    Channel ID: %04x", pHeader->dcid);
							std::string Temp = ArrayToString((const u8*)pData, DataSize);
							DEBUG_LOG(WIIMOTE, "    Data: %s", Temp.c_str());

							Wiimote::InterruptChannel(number, pHeader->dcid, pData, DataSize);
						}
					}
					break;

				default:
					ERROR_LOG(WII_IPC_WIIMOTE, "Channel 0x04%x has unknown PSM %x", pHeader->dcid, rChannel.PSM);
					break;
				}
			}
		}
		break;
	}
}
예제 #16
0
std::string ByStudio(SortAttribute attributes, const SortItem &values)
{
  return ArrayToString(attributes, values.at(FieldStudio));
}
예제 #17
0
std::string ByCountry(SortAttribute attributes, const SortItem &values)
{
  return ArrayToString(attributes, values.at(FieldCountry));
}
예제 #18
0
std::string ByGenre(SortAttribute attributes, const SortItem &values)
{
  return ArrayToString(attributes, values.at(FieldGenre));
}
예제 #19
0
CEXIETHERNET::CEXIETHERNET()
{
	tx_fifo = new u8[1518];
	mBbaMem = new u8[BBA_MEM_SIZE];

	mRecvBuffer = new u8 [BBA_RECV_SIZE];
	mRecvBufferLength = 0;

	MXHardReset();

	// Parse MAC address from config, and generate a new one if it doesn't
	// exist or can't be parsed.

	auto &mac_addr_setting = SConfig::GetInstance().m_bba_mac;
	bool mac_addr_valid = false;
	u8 mac_addr[6] = { 0 };

	if (!mac_addr_setting.empty())
	{
		int x = 0;

		for (size_t i = 0; i < mac_addr_setting.size() && x < 12; i++)
		{
			char c = mac_addr_setting.at(i);
			if (c >= '0' && c <= '9')
			{
				mac_addr[x / 2] |= (c - '0') << ((x & 1) ? 0 : 4); x++;
			}
			else if (c >= 'A' && c <= 'F')
			{
				mac_addr[x / 2] |= (c - 'A' + 10) << ((x & 1) ? 0 : 4); x++;
			}
			else if (c >= 'a' && c <= 'f')
			{
				mac_addr[x / 2] |= (c - 'a' + 10) << ((x & 1) ? 0 : 4); x++;
			}
		}

		if (x / 2 == 6)
		{
			memcpy(&mBbaMem[BBA_NAFR_PAR0], mac_addr, 6);
			mac_addr_valid = true;
		}
	}

	if (!mac_addr_valid)
	{
		GenerateMAC(BBA, mac_addr);

		mac_addr_setting = ArrayToString(mac_addr, 6, 10, false);
		SConfig::GetInstance().SaveSettings();

		memcpy(&mBbaMem[BBA_NAFR_PAR0], mac_addr, 6);
	}

	// HACK: .. fully established 100BASE-T link
	mBbaMem[BBA_NWAYS] = NWAYS_LS100 | NWAYS_LPNWAY | NWAYS_100TXF | NWAYS_ANCLPT;

#if defined(_WIN32)
	mHAdapter = INVALID_HANDLE_VALUE;
	mHRecvEvent = INVALID_HANDLE_VALUE;
	mHReadWait = INVALID_HANDLE_VALUE;
#elif defined(__linux__)
	fd = -1;
#endif
}
예제 #20
0
void CWII_IPC_HLE_Device_usb_oh0_57e_308::GetRegister(const u32 cmd_ptr) const
{
	const u8 reg = Memory::Read_U8(cmd_ptr + 1) & ~1;
	const u32 arg1 = cmd_ptr + 2;
	const u32 arg2 = cmd_ptr + 4;

	_dbg_assert_(OSHLE, Memory::Read_U8(cmd_ptr) == 0x9a);
	_dbg_assert_(OSHLE, (Memory::Read_U8(cmd_ptr + 1) & 1) == 1);

	switch (reg)
	{
	case SAMPLER_STATE:
		Memory::Write_U16(sampler.sample_on ? 1 : 0, arg1);
		break;
	case SAMPLER_FREQ:
		switch (sampler.freq)
		{
		case 8000:
			Memory::Write_U16(FREQ_8KHZ, arg1);
			break;
		case 11025:
			Memory::Write_U16(FREQ_11KHZ, arg1);
			break;
		case 16000:
		default:
			Memory::Write_U16(FREQ_16KHZ, arg1);
			break;
		}
		break;
	case SAMPLER_GAIN:
		switch (sampler.gain)
		{
		case 0:
			Memory::Write_U16(0x300 | GAIN_00dB, arg1);
			break;
		case 15:
			Memory::Write_U16(0x300 | GAIN_15dB, arg1);
			break;
		case 30:
			Memory::Write_U16(0x300 | GAIN_30dB, arg1);
			break;
		case 36:
		default:
			Memory::Write_U16(0x300 | GAIN_36dB, arg1);
			break;
		}
		break;
	case EC_STATE:
		Memory::Write_U16(sampler.ec_reset ? 1 : 0, arg1);
		break;
	case SP_STATE:
		switch (Memory::Read_U16(arg1))
		{
		case SP_ENABLE:
			Memory::Write_U16(sampler.sp_on ? 0 : 1, arg2);
			break;
		case SP_SIN:
			break;
		case SP_SOUT:
			Memory::Write_U16(0x39B0, arg2); // 6dB TODO actually calc?
			break;
		case SP_RIN:
			break;
		}
		break;
	case SAMPLER_MUTE:
		Memory::Write_U16(sampler.mute ? 1 : 0, arg1);
		break;
	}

	WARN_LOG(OSHLE, "cmd <- %s",
		ArrayToString(Memory::GetPointer(cmd_ptr), 10, 16).c_str());
}