Ejemplo n.º 1
0
Archivo: work.c Proyecto: kamngur/inet
int manage_ncp(void * packiet_data,uint16_t packiet_len )
{
    int i = 0;
    ethernet_header* eh;
    ip_header * ip;
    udp_header * udp;
    ncp_header * ncp;
    uint16_t data_size;

    get_headers(packiet_data,&eh,&ip,&udp,&ncp);
    data_size = udp->uh_ulen;


    switch (current_state)
    {
    case START:

        ncp_register(&m_ncp,NCP_HEADER_SIZE);
        output_size = create_packiet(output_packiet,ETHER_MAX_LEN,m_ncp,NCP_HEADER_SIZE);
        TransmitPacket(output_packiet,output_size);
        next_state = IDLE;
        break;
    case IDLE:
        if(packiet_len=0)
            break;


        if(ncp->ncp_comm == NCP_DATA)
        {
            i = memcmp(&(ncp->ncp_client),get_host_uuid(),sizeof(uuid));
            if(i == 0)
                next_state = PROCESSING ;
        }
        else
            return 0;

        break;
    // wait for processing order
    case PROCESSING:
        outcome_size = process_ncp(ncp,data_size,outcome_ncp,ETHER_MAX_LEN);
        printf("PROCESSING \n");
        next_state = RESULT;
        break;

    case RESULT:

        ncp_result(&m_ncp,NCP_HEADER_SIZE,0,0);
        output_size = create_packiet(output_packiet,ETHER_MAX_LEN,&m_ncp,outcome_size);
        TransmitPacket(output_packiet,output_size);
        next_state = IDLE;
        break;
    case MAX_STATE:
        printf ("Manage Ncp: unpredicted state\n");
        break;
    default:
        printf ("Manage Ncp: unknow state\n");
    };
    current_state = next_state;
    return 0;
}
Ejemplo n.º 2
0
void uip_timeout_entry(void* parameter)//由于TIMEOUT函数,不参与调度
{
   // struct timer periodic_timer, arp_timer;
    static uint8_t cnt;
    int i;
	/* post message to ethernet thread */

    //if ((rt_sem_take(msg,RT_WAITING_NO)) != -RT_ETIMEOUT) 
    //if (timer_expired(&periodic_timer)) //5s enter once
    {
       //timer_reset(&periodic_timer);
       for (i = 0; i < UIP_CONNS; i++)
       {
	  uip_periodic(i);
	/* If the above function invocation resulted in data that
	   should be sent out on the network, the global variable
	   uip_len is set to a value > 0. */
	  if (uip_len > 0)
          {
	      uip_arp_out();
	      TransmitPacket();
	  }
       }
#if UIP_UDP
       for (i = 0; i < UIP_UDP_CONNS; i++) //
       {
	   uip_udp_periodic(i);
	/* If the above function invocation resulted in data that
	   should be sent out on the network, the global variable
	   uip_len is set to a value > 0. */
	   if (uip_len > 0)
           {
	      uip_arp_out();
	      TransmitPacket();
	    }
        }
#endif /* UIP_UDP */
      
       /* Call the ARP timer function every 10 seconds. */
       //if (timer_expired(&arp_timer)) 
       if (++cnt >= 2) //t
       {
	  //timer_reset(&arp_timer);
	  uip_arp_timer();
          cnt = 0;
       }
    }
  
}
Ejemplo n.º 3
0
void TestTransmitPacket()
{
	u_char buffer[512];
	
	memset(buffer,0xff,512);
	TransmitPacket(buffer,512);
}
Ejemplo n.º 4
0
void main( void )
{  
  // Stop watchdog timer to prevent time out reset 
  WDTCTL = WDTPW + WDTHOLD; 
  // Increase PMMCOREV level to 2 for proper radio operation
  SetVCore(2);                               
  
  ResetRadioCore();
  InitButtonLeds();
  InitTimer(); 
    
  // Clean out the RX Buffer 
  rxPosition = PACKET_LEN+2;
  while(rxPosition--)
  {
    RxBuffer[rxPosition] = 0; 
  }

  InitRadio();  
  ReceiveOn(); 
//Check RSSI here
  while (1)
  { 
    P1IE |= BIT7;                           // Enable button interrupt
    
    __bis_SR_register( LPM3_bits + GIE );   
    __no_operation(); 
    
    if (buttonPressed)                      // Process a button press->transmit
    {
      ReceiveOff();                         // Button means TX, stop RX
      receiving = 0;                         

      TransmitPacket();                 

      buttonPressed = 0;                    // Re-enable button press                           
    }
    if(receiving)
    {
      ReceivePacket(); 
      __no_operation(); 
      // Check CRC
      if(RxBuffer[CRC_LQI_IDX] & CRC_OK)
      //Got it!
      P1OUT ^= BIT0;                    // Toggle LED1 in celebration

    }
    if(!transmitting)
    {
      ReceiveOn(); 
    }
  }


}
Ejemplo n.º 5
0
int arp_register()
{
	uint32_t output_size = 0;
	ncp_header m_ncp ;
	volatile frame * my_frame = get_free_frame();

	create_arp_req(my_frame);
	TransmitPacket(my_frame->f_data, my_frame->f_len);
	release_frame(my_frame);
	return 0;
}
Ejemplo n.º 6
0
int client_register()
{
	uint32_t output_size = 0;

	ncp_header m_ncp ;
	volatile frame * my_frame = get_free_frame();
	ncp_register(&m_ncp,NCP_HEADER_SIZE);

	my_frame->f_len = create_packiet(my_frame->f_data,ETHER_MAX_LEN,&m_ncp,NCP_HEADER_SIZE);
	TransmitPacket(my_frame->f_data, my_frame->f_len);
	release_frame(my_frame);
	return 0;
}
Ejemplo n.º 7
0
int arp_response(frame * arp)
{
	frame *output;
	uint32_t output_size = 0;
	frame  *m_frame = get_free_frame();

	create_arp_res(arp,output);
	TransmitPacket(output->f_data, output->f_len);
	release_frame(output);
	return 0;



}
Ejemplo n.º 8
0
void uip_tcpip_thread(void *parameter)
{
    int i;
    static u8_t cnt;
    while(1)
    {
        rt_thread_delay(CLOCK_SECOND*5);
        for (i = 0; i < UIP_CONNS; i++) 
        {
	    uip_periodic(i);
	/* If the above function invocation resulted in data that
	   should be sent out on the network, the global variable
	   uip_len is set to a value > 0. */
	    if (uip_len > 0)
            {
	        uip_arp_out();
                TransmitPacket();
	    }
        }
#if UIP_UDP
        for (i = 0; i < UIP_UDP_CONNS; i++)
        {
	    uip_udp_periodic(i);
	/* If the above function invocation resulted in data that
	   should be sent out on the network, the global variable
	   uip_len is set to a value > 0. */
	   if (uip_len > 0)
           {
	      uip_arp_out();
              TransmitPacket();
	   }
        }
#endif /* UIP_UDP */  
      /* Call the ARP timer function every 10 seconds. */
	 if (++cnt > 2) uip_arp_timer();
    }
}
Ejemplo n.º 9
0
void Transmitter(void)
{
    TXEN = 1;
    for(;;)
    {
		char c;

		while (!RI)
			;			
		RI = 0;
		c = SBUF;
		TransmitPacket(c);
		PutChar(c);
    }
}
Ejemplo n.º 10
0
HX_RESULT
StaticPushSource::PacketReady(HX_RESULT status, IHXPacket* packet)
{
    if (HXR_OK == status)
    {
	TransmitPacket(HXPacketToServerPacket(packet));
    }
    else
    {
	UINT16 i;
	for (i = 0; i < m_lNumStreams; i++)
	{
	    StreamDone(i);
	    m_pStreams [i].m_bDone = TRUE;
	}
    }

    return HXR_OK;
}
Ejemplo n.º 11
0
STDMETHODIMP
StaticPushSource::SinkBlockCleared(UINT32 ulStream)
{
    HX_ASSERT(m_pStreams);
    HX_ASSERT(m_pStreams[ulStream].m_bBlocked);

    m_pStreams[ulStream].m_bBlocked = FALSE;
    m_nCurrentStream = ulStream;

    // we should already have a packet ready to be sent
    ServerPacket* pPkt = m_pStreams [m_nCurrentStream].GetPacket();	
    if (pPkt)
    {
	TransmitPacket(pPkt);
	HX_RELEASE(pPkt);
    }
    else
    {
	HX_ASSERT(!"no pkt!!!");
    }			

    return HXR_OK;
}