Exemplo n.º 1
0
BOOL SendMsg (
SOCKET  s, 
PBYTE   pBuf, 
DWORD   cbBuf)
{
	if (0 == cbBuf)
	return(TRUE);

	//----------------------------------------------------------
	//  Send the size of the message.

	if (!SendBytes (s, (PBYTE)&cbBuf, sizeof (cbBuf)))
	return(FALSE);

	//----------------------------------------------------------
	//  Send the body of the message.

	if (!SendBytes (
				s, 
				pBuf, 
				cbBuf))
	{
		return(FALSE);
	}

	return(TRUE);
}    
Exemplo n.º 2
0
int main(void) {
	unsigned int type2_addr;
	unsigned int type2_size;
	unsigned int type2_length;
	unsigned char Frame[MAX_FRAME_SIZE];
	uint8_t Len;
	uint8_t EchoLen;
	pL2Hdr pL2 = (pL2Hdr)Frame;
	uint8_t i;

	// negotiate a Type2 POV with the Competition Framework
	NegotiateType2Pov(&type2_addr, &type2_size, &type2_length);

	// send a normally routed packet to build the L2 CAM tables in cb_switch
	bzero(Frame, MAX_FRAME_SIZE);
	BuildL4Segment(ECHO_L4ADDR, 0x41, (unsigned char *)"AA", 2, Frame);
	BuildL3Packet(0x0a010202, 0x0a010102, Frame);
	EchoLen = BuildL2Frame(0x0001, 0x1000, 0, Frame);
	SendBytes(STDOUT, Frame, EchoLen);

	// receive the ADP request that the router will generate when trying
	// to send back the echo response packet
	bzero(Frame, MAX_FRAME_SIZE);
	ReadBytes(STDIN, Frame, 19);
	
	// answer the ADP request 
	bzero(Frame, MAX_FRAME_SIZE);
	Len = BuildAdpResponse(0x0a010102, 0x1000, 0x0001, 0x1000, 0, Frame);
	SendBytes(STDOUT, Frame, Len);

	// read the echo response
	bzero(Frame, MAX_FRAME_SIZE);
	ReadBytes(STDIN, Frame, EchoLen);

	for (i = 0; i < 4; i++) {
		// send a pwdgen request to cb_3 bypassing the router
		// use src L2 addr with 00 for last two bits
		bzero(Frame, MAX_FRAME_SIZE);
		BuildL4Segment(PWDGEN_L4ADDR, 0x41, (unsigned char *)"AA", 2, Frame);
		BuildL3Packet(0x0a010202, 0x0a010102, Frame);
		Len = BuildL2Frame(0xaaaa, 0x1000+i, 2, Frame);
		SendBytes(STDOUT, Frame, Len);
	
		// receive the pwdgen response
		// read in the L2hdr first
		ReadBytes(STDIN, Frame, L2_HDR_LEN);
		// read in the rest of the Frame
		ReadBytes(STDIN, Frame+L2_HDR_LEN, pL2->Len);
	
		// Parse the pwdgen response
		ParsePwdgenResponse(Frame, 4+i);
	}

	// send the recovered page bytes to the competition framework
	SendBytes(FRAMEWORK, decoded_magic_page+4, 4);

}
Exemplo n.º 3
0
void SendTest(unsigned char B, unsigned int H, unsigned long int I, char b, int h, long int i, float f) {
    char bytes[] = {
        129,
        252,
        1,
        B,
        2,
        ((char*)&H)[0],
        ((char*)&H)[1],
        4,
        ((char*)&I)[0],
        ((char*)&I)[1],
        ((char*)&I)[2],
        ((char*)&I)[3],
        17,
        b,
        18,
        ((char*)&h)[0],
        ((char*)&h)[1],
        20,
        ((char*)&i)[0],
        ((char*)&i)[1],
        ((char*)&i)[2],
        ((char*)&i)[3],
        36,
        ((char*)&f)[0],
        ((char*)&f)[1],
        ((char*)&f)[2],
        ((char*)&f)[3],
        128
    };
    SendBytes(bytes, 28);
}
Exemplo n.º 4
0
void SendCommand( const char *pszCommandData )
{
	size_t command_len = cgc_strlen( pszCommandData );

	SendBytes( 1, (char *)pszCommandData, command_len );
	// transmit_all( 1, (unsigned char *)pszCommandData, command_len );
}
Exemplo n.º 5
0
void
DynamixelComm::Send(unsigned char * b)
{
  b[b[3]+3] = CalculateChecksum(b);

  SendBytes((char *)b, b[3]+4);
}
Exemplo n.º 6
0
// sends response code and 2-byte data value
uint8_t SendResp(uint8_t Code, unsigned char *Data) {
	if (!SendBytes((unsigned char *)&Code, 1)) {
		return(0);
	}
	if (Data == NULL) {
		uint16_t NA = 0;
		if (!SendBytes((unsigned char *)&NA, 2)) {
			return(0);
		}
	} else {
		if (!SendBytes(Data, 2)) {
			return(0);
		}
	}
	return(1);
}
Exemplo n.º 7
0
void SendClient(int session_id,char *data,unsigned short len_data)
{
	session_node *s;
	
	s = GetSessionByID(session_id);
	if (s == NULL)
	{
		/* the session has already closed, so happens all the time */
		/* eprintf("SendClient can't output to non-session %i\n",session_id); */
		return;
	}
	
	switch (s->state)
	{
	case STATE_GAME :
		SendGameClient(s,data,len_data,epoch);
		break;
	case STATE_SYNCHED :
		SendGameClient(s,data,len_data,0);
		break;
	case STATE_ADMIN :
	case STATE_MAINTENANCE :
	case STATE_TRYSYNC :
		SendBytes(s,data,len_data);
		break;
	}
}
Exemplo n.º 8
0
// Resolve L2 Adjacency
uint16_t ResolveL2Adjacency(uint32_t TargetAddr, uint8_t InterfaceId) {
	uint8_t i;
	uint16_t L2Addr;
	unsigned char Frame[MAX_FRAME_LEN];
	pL2Hdr pL2 = (pL2Hdr)Frame;
	pL2Adjacency pL2Adj = (pL2Adjacency)(Frame+sizeof(L2Hdr));
	pL2Ftr pL2Footer = (pL2Ftr)(Frame+sizeof(L2Hdr)+sizeof(L2Adjacency));
	uint8_t FrameLen;

	bzero(Frame, MAX_FRAME_LEN);

	if (InterfaceId > MaxInterfaces) {
		return(0);
	}

	// form up a L2 Adjacency Discovery Packet
	pL2->Dst = 0xffff;
	pL2->Src = LookupL2Adjacency(L3Interfaces[InterfaceId].Addr);
	pL2->Len = sizeof(L2Adjacency)+sizeof(L2Ftr);
	pL2->NxtHdr = L2_ADJACENCY_DISCOVERY_TYPE;
	pL2->Vlan = L3Interfaces[InterfaceId].Vlan;
	pL2Adj->L3Addr = TargetAddr;
	pL2Adj->L2Addr = 0x0000;
	pL2Footer->Chksum = L2_CalculateChecksum(Frame);
	FrameLen = sizeof(L2Hdr)+pL2->Len;
	
	// send the L2 ADP
	if (SendBytes(L3Interfaces[InterfaceId].Tx_FD, FrameLen, Frame) != FrameLen) {
		return(0);
	}
	
	return(1);
}
Exemplo n.º 9
0
NS_IMETHODIMP
FCGXStream::SendResponseFragment(const char *aString, PRUint32 aLength)
{
    if (mFD != INVALID_SOCKET)
        SendBytes(aString, aLength);
    return mFD != INVALID_SOCKET ? NS_OK : NS_ERROR_ABORT;
}
Exemplo n.º 10
0
int ResetDev(Communicator& comm,int macNo /*=255*/)
 {
	 if(NOT_CONNECT==comm.m_nCommtype)
		 return SCERR_INVALID_COMM;
	 if(macNo>255||macNo<1)
		 return SCERR_MACNO_OUTRANGE;
	 int cmd=0xe8;
	 int dataLen=0;
	 BYTE tempBuffer[16];
	 BYTE SRBuffer[64];
	 int packetLen=PrepareBytes(macNo,cmd,tempBuffer,&dataLen,SRBuffer);
	 //发送命令
	 int retCode=0;
	// CommProcess(comm,SRBuffer,packetLen,retCode,SRBuffer,recLen);
	 if(COMM_UDP==comm.m_nCommtype)
		 retCode=SendUDPData(comm.udpConn->s,comm.udpConn->dstIP,comm.udpConn->dstPort, SRBuffer,packetLen);
	 else if(COMM_COM==comm.m_nCommtype)
		 retCode=SendBytes(comm.comConn->comPort,SRBuffer,packetLen);
	 else if(COMM_TCPCLIENT==comm.m_nCommtype||COMM_TCPSERVER==comm.m_nCommtype)
		 retCode=SendData(comm.tcpClientConn->s,SRBuffer,packetLen);

	 if(retCode<0)
		return -1;
	 return 0;
 }
Exemplo n.º 11
0
void SendDone() {
    char bytes[] = {
        129,
        2,
        128
    };
    SendBytes(bytes, 3);
}
Exemplo n.º 12
0
bool SendMsg(
  SOCKET aSocket, 
  BYTE* apBuf, 
  DWORD adwBuf)
{
  if(!adwBuf)
    return true;

  if (!SendBytes(aSocket, (BYTE*)&adwBuf, sizeof(adwBuf)))
      return false;

  if(!SendBytes(aSocket, apBuf, adwBuf))
  {
    return false;
  }
  return true;
}
Exemplo n.º 13
0
void SendGetSwitchOneState() {
    char bytes[] = {
        129,
        30,
        128
    };
    SendBytes(bytes, 3);
}
Exemplo n.º 14
0
void SendPasDeVerreEvent() {
    char bytes[] = {
        129,
        6,
        128
    };
    SendBytes(bytes, 3);
}
Exemplo n.º 15
0
void SendError() {
    char bytes[] = {
        129,
        253,
        128
    };
    SendBytes(bytes, 3);
}
Exemplo n.º 16
0
void SendGetSwitchTwoState() {
    char bytes[] = {
        129,
        32,
        128
    };
    SendBytes(bytes, 3);
}
Exemplo n.º 17
0
void SendBougiesHitTopConfirm() {
    char bytes[] = {
        129,
        11,
        128
    };
    SendBytes(bytes, 3);
}
Exemplo n.º 18
0
void SendGetSwitchThreeState() {
    char bytes[] = {
        129,
        34,
        128
    };
    SendBytes(bytes, 3);
}
Exemplo n.º 19
0
void SendBougiesOffConfirm() {
    char bytes[] = {
        129,
        15,
        128
    };
    SendBytes(bytes, 3);
}
Exemplo n.º 20
0
void SendBougiesHitBotConfirm() {
    char bytes[] = {
        129,
        13,
        128
    };
    SendBytes(bytes, 3);
}
Exemplo n.º 21
0
uint8_t SendResponse(uint8_t Code, uint8_t NumElements, uint32_t *Elements) {
	Response r;

	r.Code = Code;
	r.NumElements = NumElements;
	if (SendBytes((unsigned char *)&r, sizeof(Response)) != sizeof(Response)) {
		return(0);
	}
	
	// send the elements
	if (NumElements > 0) {
		if (SendBytes((unsigned char *)Elements, NumElements*sizeof(uint32_t))) {
			return(0);
		}
	}

	return(1);
}
Exemplo n.º 22
0
void SendEmergencyState(unsigned char emergency_state) {
    char bytes[] = {
        129,
        21,
        1,
        emergency_state,
        128
    };
    SendBytes(bytes, 5);
}
Exemplo n.º 23
0
void SendId(unsigned char id) {
    char bytes[] = {
        129,
        255,
        1,
        id,
        128
    };
    SendBytes(bytes, 5);
}
Exemplo n.º 24
0
void SendSwitchTwo(unsigned char state) {
    char bytes[] = {
        129,
        33,
        1,
        state,
        128
    };
    SendBytes(bytes, 5);
}
Exemplo n.º 25
0
void SendStartLaisseState(unsigned char state) {
    char bytes[] = {
        129,
        41,
        1,
        state,
        128
    };
    SendBytes(bytes, 5);
}
Exemplo n.º 26
0
void SendBackBumperState(unsigned char state) {
    char bytes[] = {
        129,
        141,
        1,
        state,
        128
    };
    SendBytes(bytes, 5);
}
Exemplo n.º 27
0
void GameSyncInputChar(session_node *s,char ch)
{
   int sync_len;
   unsigned char *sync_buf;

   switch (s->game->game_state)
   {
   case GAME_BEACON :
      sync_buf = beacon_str;
      sync_len = LENGTH_BEACON;
      break;
   case GAME_FINAL_SYNC :
      sync_buf = detect_str;
      sync_len = LENGTH_DETECT;
      break;
   default :
      eprintf("GameSyncInputChar can't get here\n");
   }

   if (ch == sync_buf[s->game->game_sync_index])
      s->game->game_sync_index++;
   else
   {
      if (s->game->game_state == GAME_FINAL_SYNC)
      {
	 /* bad char here means line noise */
/* 	 dprintf("bad char on final sync\n"); */
	 GameSendResync(s);
	 GameSyncInit(s);
	 return;
      }
      s->game->game_sync_index = 0;
   }

/*   dprintf("GameSync got char %i, pos %i for sync\n",ch,s->game->game_sync_index); */

   if (s->game->game_sync_index == sync_len)
   {
      switch (s->game->game_state)
      {
      case GAME_BEACON :
         SendBytes(s,(char *) tell_cli_str,LENGTH_TELL_CLI); /* sends exact bytes, no header */
	 s->game->game_state = GAME_FINAL_SYNC;
	 s->game->game_sync_index = 0;
	 InterfaceUpdateSession(s);
	 break;
      case GAME_FINAL_SYNC :
	 s->game->game_state = GAME_NORMAL;
	 InterfaceUpdateSession(s);
	 break;
      }
/*      dprintf("Changed to game state %i\n",s->game->game_state); */
   }
   
}
Exemplo n.º 28
0
void GetBMSinfo(void)
{
    //BMS  管理
    if(BMSflag ==0)
    {
        SendBytes(BMS,20);
        SendBytes(BMS,20);
        BMSflag = 1;
    }
    else
    {
        if(BMS_End_flag)
        {
            CurrentElectricity  = (GSM_Receive_Buf[131]-48)*4096
                                  + (GSM_Receive_Buf[132]-48)*256
                                  + (GSM_Receive_Buf[133]-48)*16
                                  + (GSM_Receive_Buf[134]-48);
            if((CurrentElectricity <0x1F18)
                    && (CurrentElectricity > 0xF8C)
                    && (LowElectricityflag != 1)) //电池电量少于总电量25%但大于20%
            {
                LowElectricityflag = 1;
                DirectLED1 = 1;
            }
            else  if(CurrentElectricity < 0xF8C)   //电池电量少于总电量20%
            {
                LowElectricityflag = 2;
                gCarThreshold.errCode |= HIGH_TEMPATURE_EXCEPTION;  
                    
                gCarThreshold.operationMode = STOP_OPERATION;
                gCarThresholdEepromUpdateFlag = 1;            
            }
            else
            {
                LowElectricityflag = 0;
            }
            BMS_End_flag = 0;
            memset(GSM_Receive_Buf, 0, 150);
        }
        BMSflag = 0;
    }
}
Exemplo n.º 29
0
// Handle L2 Adjacency Discovery Packet
uint8_t HandleL2AdjacencyDiscoveryPacket(unsigned char *Frame) {
	unsigned char ResponseFrame[MAX_FRAME_LEN];
	pL2Hdr pL2 = (pL2Hdr)ResponseFrame;
	pL2Adjacency pL2AdjResp = (pL2Adjacency)(ResponseFrame+sizeof(L2Hdr));
	uint8_t Id;
	pL2Hdr pL2Disc = (pL2Hdr)Frame;
	pL2Adjacency pL2Adj = (pL2Adjacency)(Frame+sizeof(L2Hdr));
	uint8_t FrameLen;

	if (!Frame) {
		return(0);
	}

	// see if the Addr is one of ours
	for (Id = 0; Id < MaxInterfaces; Id++) {
		if (L3Interfaces[Id].Addr == pL2Adj->L3Addr &&
		    L3Interfaces[Id].Vlan == pL2Disc->Vlan) {
			break;
		}
	}
	
	// nope, nothing to do
	if (Id == MaxInterfaces) {
		return(1);
	}

	// yep, form up a response
	pL2->Dst = pL2Disc->Src;
	if ((pL2->Src = LookupL2Adjacency(L3Interfaces[Id].Addr)) == 0) {
		// shouldn't get here
		return(0);
	}
	pL2->Len = sizeof(L2Adjacency)+sizeof(L2Ftr);
	#ifdef CB3
	pL2->Vlan = 0;
	#else
	pL2->Vlan = L3Interfaces[Id].Vlan;
	#endif
	pL2->NxtHdr = L2_ADJACENCY_RESPONSE_TYPE;
	pL2AdjResp->L3Addr = L3Interfaces[Id].Addr;
	pL2AdjResp->L2Addr = pL2->Src;
	pL2AdjResp->Age = 0;
	pL2AdjResp->Vlan = 0;
	*(uint32_t *)(ResponseFrame+sizeof(L2Hdr)+sizeof(L2Adjacency)) = L2_CalculateChecksum(ResponseFrame);

	// send the frame
	FrameLen = sizeof(L2Hdr)+pL2->Len;
	if (SendBytes(L3Interfaces[Id].Tx_FD, FrameLen, ResponseFrame) != FrameLen) {
		return(0);
	}

	return(1);

}
Exemplo n.º 30
0
void SendNombreVerres(unsigned int n) {
    char bytes[] = {
        129,
        5,
        2,
        ((char*)&n)[0],
        ((char*)&n)[1],
        128
    };
    SendBytes(bytes, 6);
}