Exemplo n.º 1
0
void AskEncKey(struct InfoCon *info, struct CHPack *pack)
{
	unsigned short Version;
	unsigned short unk;

	GetWordInPacket(pack, &Version);
	printf("Version Packet : %X\n", Version);
	GetWordInPacket(pack, &unk);

	SendEncKey(info);
	printf("[+] Encryption key sent\n");
	info->sym_keyset = 1;
	info->sequence += 1;
	SendClientInfo(info);
	printf("[+] Client info sent\n");
}
//-----------------------------------------------------------------------------
// Purpose: A svc_signonnum has been received, perform a client side setup
// Output : void CL_SignonReply
//-----------------------------------------------------------------------------
bool CHLTVClientState::SetSignonState ( int state, int count )
{
	//	ConDMsg ("CL_SignonReply: %i\n", cl.signon);

	if ( !CBaseClientState::SetSignonState( state, count ) )
		return false;
	
	Assert ( m_nSignonState == state );

	switch ( m_nSignonState )
	{
		case SIGNONSTATE_CHALLENGE	:	break;
		case SIGNONSTATE_CONNECTED	:	{
											// allow longer timeout
											m_NetChannel->SetTimeout( SIGNON_TIME_OUT );

											m_NetChannel->Clear();
											// set user settings (rate etc)
											NET_SetConVar convars;
											Host_BuildConVarUpdateMessage( &convars, FCVAR_USERINFO, false );

											// let server know that we are a proxy server:
											NET_SetConVar::cvar_t acvar;
											Q_strcpy( acvar.name, "tv_relay" );
											Q_strcpy( acvar.value, "1" );
											convars.m_ConVars.AddToTail( acvar );

											m_NetChannel->SendNetMsg( convars );
										}
										break;

		case SIGNONSTATE_NEW		:	SendClientInfo();
										break;

		case SIGNONSTATE_PRESPAWN	:	break;
		
		case SIGNONSTATE_SPAWN		:	m_pHLTV->SignonComplete();
										break;

		case SIGNONSTATE_FULL		:	m_NetChannel->SetTimeout( tv_timeout.GetFloat() );
										// start new recording if autorecord is enabled
										if ( tv_autorecord.GetBool() )
										{
											hltv->m_DemoRecorder.StartAutoRecording();
											m_NetChannel->SetDemoRecorder( &hltv->m_DemoRecorder );
										}
										break;

		case SIGNONSTATE_CHANGELEVEL:	m_pHLTV->Changelevel();
										m_NetChannel->SetTimeout( SIGNON_TIME_OUT );  // allow 5 minutes timeout
										break;
	}

	if ( m_nSignonState >= SIGNONSTATE_CONNECTED )
	{
		// tell server that we entered now that state
		NET_SignonState signonState(  m_nSignonState, count );
		m_NetChannel->SendNetMsg( signonState );
	}

	return true;
}
Exemplo n.º 3
0
void SocketHandler::Action(void)
{
  DEBUGLOG("%s", __FUNCTION__);
  unsigned char buff[262];
  int cRead;
  uint32_t *request;
  uint8_t adapter_index;
  int faults = 0;
  int skip_bytes = 0;

  while (Running())
  {
    if (sock == 0 && capmt && !capmt->Empty())
    {
      if (faults == 0 || (faults > 0 && checkTimer.TimedOut()))
      {
        DEBUGLOG("OSCam not connected, (re)connecting...");
        OpenConnection();
        if (sock > 0)
        {
          DEBUGLOG("Successfully (re)connected to OSCam");
          faults = 0;
          SendClientInfo();
          capmt->SendAll();
        }
        else
          faults++;
        checkTimer.Set(SOCKET_CHECK_INTERVAL);
      }
      cCondWait::SleepMs(20);
      continue;
    }

    // request
    cRead = recv(sock, &buff[skip_bytes], sizeof(int)-skip_bytes, MSG_DONTWAIT);
    if (cRead <= 0)
    {
      if (cRead == 0)
        CloseConnection();
      cCondWait::SleepMs(20);
      continue;
    }
    request = (uint32_t *) &buff;
    skip_bytes = 0;

    if (ntohl(*request) != DVBAPI_SERVER_INFO)
    {
      // first byte -> adapter_index
      cRead = recv(sock, &adapter_index, 1, MSG_DONTWAIT);
      if (cRead <= 0)
      {
        if (cRead == 0)
          CloseConnection();
        cCondWait::SleepMs(20);
        continue;
      }
      adapter_index -= AdapterIndexOffset;
    }

    *request = ntohl(*request);
    if (*request == CA_SET_PID)
      cRead = recv(sock, buff+4, sizeof(ca_pid_t), MSG_DONTWAIT);
    else if (*request == CA_SET_DESCR)
      cRead = recv(sock, buff+4, sizeof(ca_descr_t), MSG_DONTWAIT);
    else if (*request == CA_SET_DESCR_MODE)
      cRead = recv(sock, buff+4, sizeof(ca_descr_mode_t), MSG_DONTWAIT);
    else if (*request == DMX_SET_FILTER)
      cRead = recv(sock, buff+4, sizeof(struct dmx_sct_filter_params), MSG_DONTWAIT);
    else if (*request == DMX_STOP)
      cRead = recv(sock, buff+4, 2 + 2, MSG_DONTWAIT);
    else if (*request == DVBAPI_SERVER_INFO)
    {
      unsigned char len;
      recv(sock, buff+4, 2, MSG_DONTWAIT);             //proto version
      recv(sock, &len, 1, MSG_DONTWAIT);               //string length
      cRead = recv(sock, buff+6, len, MSG_DONTWAIT);
      buff[6+len] = 0;                                 //terminate the string
    }
    else if (*request == DVBAPI_ECM_INFO)
      recv(sock, buff+4, 14, MSG_DONTWAIT);            //read ECM info const len header only
    else
    {
      ERRORLOG("%s: read failed unknown command: %08x", __FUNCTION__, *request);
      cCondWait::SleepMs(20);
      continue;
    }

    if (cRead <= 0)
    {
      if (cRead == 0)
        CloseConnection();
      cCondWait::SleepMs(20);
      continue;
    }
    if (*request == CA_SET_PID)
    {
      DEBUGLOG("%s: Got CA_SET_PID request, adapter_index=%d", __FUNCTION__, adapter_index);
      memcpy(&ca_pid, &buff[sizeof(int)], sizeof(ca_pid_t));
      ca_pid.pid = ntohl(ca_pid.pid);
      ca_pid.index = ntohl(ca_pid.index);
      decsa->SetCaPid(adapter_index, &ca_pid);
    }
    else if (*request == CA_SET_DESCR)
    {
      memcpy(&ca_descr, &buff[sizeof(int)], sizeof(ca_descr_t));
      ca_descr.index = ntohl(ca_descr.index);
      ca_descr.parity = ntohl(ca_descr.parity);
      decsa->SetDescr(&ca_descr, false);
      DEBUGLOG("%s: Got CA_SET_DESCR request, adapter_index=%d, index=%x", __FUNCTION__, adapter_index, ca_descr.index);
    }
    else if (*request == CA_SET_DESCR_MODE)
    {
      memcpy(&ca_descr_mode, &buff[sizeof(int)], sizeof(ca_descr_mode_t));
      ca_descr_mode.index = ntohl(ca_descr_mode.index);
      ca_descr_mode.algo = (ca_descr_algo) ntohl(ca_descr_mode.algo);
      decsa->SetAlgo(ca_descr_mode.index, ca_descr_mode.algo);
      DEBUGLOG("%s: Got CA_SET_DESCR_MODE request, adapter_index=%d, index=%x", __FUNCTION__, adapter_index, ca_descr.index);
    }
    else if (*request == DMX_SET_FILTER)
    {
      unsigned char demux_index = buff[4];
      unsigned char filter_num = buff[5];
      int i = 6;

      uint16_t *pid_ptr = (uint16_t *) &buff[i];
      sFP2.pid = ntohs(*pid_ptr);
      i += 2;

      memcpy(&sFP2.filter.filter, &buff[i], 16);
      i += 16;
      memcpy(&sFP2.filter.mask, &buff[i], 16);
      i += 16;
      memcpy(&sFP2.filter.mode, &buff[i], 16);
      i += 16;

      uint32_t *timeout_ptr = (uint32_t *) &buff[i];
      sFP2.timeout = ntohl(*timeout_ptr);
      i += 4;

      uint32_t *flags_ptr = (uint32_t *) &buff[i];
      sFP2.flags = ntohl(*flags_ptr);

      DEBUGLOG("%s: Got DMX_SET_FILTER request, adapter_index=%d, pid=%X, demux_idx=%d, filter_num=%d", __FUNCTION__, adapter_index, sFP2.pid, demux_index, filter_num);
      filter->SetFilter(adapter_index, sFP2.pid, 1, demux_index, filter_num, sFP2.filter.filter, sFP2.filter.mask);
    }
    else if (*request == DMX_STOP)
    {
      unsigned char demux_index = buff[4];
      unsigned char filter_num = buff[5];

      uint16_t *pid_ptr = (uint16_t *) &buff[6];
      uint16_t pid = ntohs(*pid_ptr);

      DEBUGLOG("%s: Got DMX_STOP request, adapter_index=%d, pid=%X, demux_idx=%d, filter_num=%d", __FUNCTION__, adapter_index, pid, demux_index, filter_num);
      filter->SetFilter(adapter_index, pid, 0, demux_index, filter_num, NULL, NULL);
    }
    else if (*request == DVBAPI_SERVER_INFO)
    {
      uint16_t *proto_ver_ptr = (uint16_t *) &buff[4];
      protocol_version = ntohs(*proto_ver_ptr);
      DEBUGLOG("%s: Got SERVER_INFO: %s, protocol_version = %d", __FUNCTION__, &buff[6], protocol_version);
    }
    else if (*request == DVBAPI_ECM_INFO)
    {
      char cardsystem[255];
      char reader[255];
      char from[255];
      char protocol[255];
      unsigned char len, hops;
      int i = 4;

      uint16_t *sid_ptr = (uint16_t *) &buff[i];       //ServiceID
      uint16_t sid = ntohs(*sid_ptr);
      i += 2;

      uint16_t *caid_ptr = (uint16_t *) &buff[i];      //CAID
      uint16_t caid = ntohs(*caid_ptr);
      i += 2;

      uint16_t *pid_ptr = (uint16_t *) &buff[i];       //PID
      uint16_t pid = ntohs(*pid_ptr);
      i += 2;

      uint32_t *prid_ptr = (uint32_t *) &buff[i];      //ProviderID
      uint32_t prid = ntohl(*prid_ptr);
      i += 4;

      uint32_t *ecmtime_ptr = (uint32_t *) &buff[i];   //ECM time
      uint32_t ecmtime = ntohl(*ecmtime_ptr);

      //cardsystem name
      recv(sock, &len, 1, MSG_DONTWAIT);               //string length
      recv(sock, cardsystem, len, MSG_DONTWAIT);
      cardsystem[len] = 0;                             //terminate the string

      //reader name
      recv(sock, &len, 1, MSG_DONTWAIT);               //string length
      recv(sock, reader, len, MSG_DONTWAIT);
      reader[len] = 0;                                 //terminate the string

      //source (from)
      recv(sock, &len, 1, MSG_DONTWAIT);               //string length
      recv(sock, from, len, MSG_DONTWAIT);
      from[len] = 0;                                   //terminate the string

      //protocol name
      recv(sock, &len, 1, MSG_DONTWAIT);               //string length
      recv(sock, protocol, len, MSG_DONTWAIT);
      protocol[len] = 0;                               //terminate the string

      recv(sock, &hops, 1, MSG_DONTWAIT);              //hops

      DEBUGLOG("%s: Got ECM_INFO: adapter_index=%d, SID = %04X, CAID = %04X (%s), PID = %04X, ProvID = %06X, ECM time = %d ms, reader = %s, from = %s, protocol = %s, hops = %d", __FUNCTION__, adapter_index, sid, caid, cardsystem, pid, prid, ecmtime, reader, from, protocol, hops);
      capmt->UpdateEcmInfo(adapter_index, sid, caid, pid, prid, ecmtime, cardsystem, reader, from, protocol, hops);
    }
    else
      DEBUGLOG("%s: Unknown request: %02X %02X %02X %02X", __FUNCTION__, request[0], request[1], request[2], request[3]);
  }
}