Exemple #1
0
/*DISPATCHER_UIPCALL(smtp_appcall, state)*/
void
smtp_appcall(void *state)
{
  if(uip_connected()) {
    /*    senddata();*/
    return;
  }
  if(uip_acked()) {
    acked();
  }
  if(uip_newdata()) {
    newdata();
  }
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata();
  } else if(uip_poll()) {    
    senddata();
  }
  /*  if(uip_closed()) {
    printf("Dnoe\n");
    }*/


}
Exemple #2
0
/*---------------------------------------------------------------------------*/
void
telnetd_appcall(void *ts)
{
  if(uip_connected()) {
    tcp_markconn(uip_conn, &s);
    buf_init(&buf);
    s.bufptr = 0;
    s.state = STATE_NORMAL;
    shell_start();
  }

  if(s.state == STATE_CLOSE) {
    s.state = STATE_NORMAL;
    uip_close();
    return;
  }
  if(uip_closed() ||
     uip_aborted() ||
     uip_timedout()) {
    closed();
  }
  if(uip_acked()) {
    acked();
  }
  if(uip_newdata()) {
    newdata();
  }
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked() ||
     uip_connected() ||
     uip_poll()) {
    senddata();
  }
}
static void
tty_vt100_main (void)
{
  if (uip_connected())
    STATE->send_all = 1;

  if (uip_acked())
    {
      if (STATE->send_all)
	STATE->send_all = 0;
      STATE->acked = STATE->sent;
    }

  if (uip_newdata ())
    {
      uint8_t len = uip_len;
      for (uint8_t i = 0; i < len; i ++)
	{
	  int8_t ch = ((char *) uip_appdata)[i];

	  if (ch == 12)		/* C-l, retransmit everything. */
	    {
	      STATE->send_all = 1;
	      continue;
	    }

	  _getch_queue (ch);
	}
    }

  if (uip_rexmit() || uip_newdata() || uip_acked() || uip_connected()
      || uip_poll())
    {
      /* Send new data, if any. */
      if (STATE->send_all)
	tty_vt100_send_all ();

      else
	{
	  /* we're just sending an update, ... */
	  if (vt100_head > STATE->acked)
	    {
	      uint8_t len = vt100_head - STATE->acked;
	      memcpy (uip_sappdata, STATE->acked, len);
	      uip_send (uip_sappdata, len);
	    }
	  else if (vt100_head < STATE->acked)
	    {
	      /* vt100_head wrapped around, let's be careful. */
	      uint8_t len = vt100_end - STATE->acked;
	      memcpy (uip_sappdata, STATE->acked, len);
	      uint8_t len2 = vt100_head - vt100_buf;
	      memcpy (uip_sappdata + len, vt100_buf, len2);
	      uip_send (uip_sappdata, len + len2);
	    }

	  STATE->sent = vt100_head;
	}
    }
}
//这是一个TCP 服务器应用回调函数。
//该函数通过UIP_APPCALL(tcp_demo_appcall)调用,实现Web Server的功能.
//当uip事件发生时,UIP_APPCALL函数会被调用,根据所属端口(1200),确定是否执行该函数。
//例如 : 当一个TCP连接被创建时、有新的数据到达、数据已经被应答、数据需要重发等事件
void tcp_server_demo_appcall(void)
{
 	struct tcp_demo_appstate *s = (struct tcp_demo_appstate *)&uip_conn->appstate;
	if(uip_aborted())tcp_server_aborted();		//连接终止
 	if(uip_timedout())tcp_server_timedout();	//连接超时   
	if(uip_closed())tcp_server_closed();		//连接关闭	   
 	if(uip_connected())tcp_server_connected();	//连接成功	    
	if(uip_acked())tcp_server_acked();			//发送的数据成功送达 
	//接收到一个新的TCP数据包 
	if (uip_newdata())//收到客户端发过来的数据
	{
		if((tcp_server_sta&(1<<6))==0)//还未收到数据
		{
			if(uip_len>199)
			{		   
				((uint8_t*)uip_appdata)[199]=0;
			}		    
	    	strcpy((char*)tcp_server_databuf,uip_appdata);				   	  		  
			tcp_server_sta|=1<<6;//表示收到客户端数据
		}
	}else if(tcp_server_sta&(1<<5))//有数据需要发送
	{
		s->textptr=tcp_server_databuf;
		s->textlen=strlen((const char*)tcp_server_databuf);
		tcp_server_sta&=~(1<<5);//清除标记
	}   
	//当需要重发、新数据到达、数据包送达、连接建立时,通知uip发送数据 
	if(uip_rexmit()||uip_newdata()||uip_acked()||uip_connected()||uip_poll())
	{
		tcp_server_senddata();
	}
}	  
Exemple #5
0
/*-----------------------------------------------------------------------------------*/
void
webclient_appcall(void)
{
  if(uip_connected()) {
    s.timer = 0;
    s.state = WEBCLIENT_STATE_STATUSLINE;
    senddata();
    webclient_connected();
    return;
  }

  if(s.state == WEBCLIENT_STATE_CLOSE) {
    webclient_closed();
    uip_abort();
    return;
  }

  if(uip_aborted()) {
    webclient_aborted();
  }
  if(uip_timedout()) {
    webclient_timedout();
  }

  
  if(uip_acked()) {
    s.timer = 0;
    acked();
  }
  if(uip_newdata()) {
    s.timer = 0;
    newdata();
  }
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata();
  } else if(uip_poll()) {
    ++s.timer;
    if(s.timer == WEBCLIENT_TIMEOUT) {
      webclient_timedout();
      uip_abort();
      return;
    }
        /*    senddata();*/
  }

  if(uip_closed()) {
    if(s.httpflag != HTTPFLAG_MOVED) {
      /* Send NULL data to signal EOF. */
      webclient_datahandler(NULL, 0);
    } else {
      if(resolv_lookup(s.host) == NULL) {
	resolv_query(s.host);
      }
      webclient_get(s.host, s.port, s.file);
    }
  }
}
Exemple #6
0
static void
irc_main(void)
{
    if (uip_aborted() || uip_timedout()) {
	IRCDEBUG ("connection aborted\n");
	irc_conn = NULL;
    }

    if (uip_closed()) {
	IRCDEBUG ("connection closed\n");
	irc_conn = NULL;
    }

    if (uip_connected()) {
	IRCDEBUG ("new connection\n");
	STATE->stage = IRC_SEND_USERNICK;
	STATE->sent = IRC_SEND_INIT;
#ifdef ECMD_IRC_SUPPORT
	STATE->reparse = 0;
#endif
	*STATE->outbuf = 0;
    }

    if (STATE->stage == IRC_SEND_JOIN
	&& uip_acked ())
	STATE->stage ++;

    else if (STATE->stage == IRC_CONNECTED
	     && uip_acked ()) {
	*STATE->outbuf = 0;

#ifdef ECMD_IRC_SUPPORT
	if (STATE->reparse)
	    irc_handle_ecmd ();
#endif
    }

    else if (uip_newdata() && uip_len) {
	((char *) uip_appdata)[uip_len] = 0;
	IRCDEBUG ("received data: %s\n", uip_appdata);

	if (irc_parse ()) {
	    uip_close ();	/* Parse error */
	    return;
	}
    }

    if (uip_rexmit ())
	irc_send_data (STATE->sent);

    else if ((STATE->stage > STATE->sent || STATE->stage == IRC_CONNECTED)
	     && (uip_newdata()
		 || uip_acked()
		 || uip_connected()))
	irc_send_data (STATE->stage);

    else if (STATE->stage == IRC_CONNECTED && uip_poll() && *STATE->outbuf)
	irc_send_data (STATE->stage);
}
Exemple #7
0
void yport_net_main(void)
{
  if(uip_connected()) {
    if (yport_conn == NULL) {
      yport_conn = uip_conn;
      uip_conn->wnd = YPORT_BUFFER_LEN - 1;
    }
    else 
      /* if we have already an connection, send an error */
      uip_send("ERROR: Connection blocked\n", 27);
  } else if (uip_acked()) {
    /* If the peer is not our connection, close it */
    if (yport_conn != uip_conn) 
      uip_close();
    else {
      /* Some data we have sent was acked, jipphie */
      /* disable interrupts */
      uint8_t sreg = SREG; cli();
      yport_recv_buffer.len -= yport_recv_buffer.sent;
      /* We should use memmove, because the data may overlap */
      memmove(yport_recv_buffer.data, 
              yport_recv_buffer.data + yport_recv_buffer.sent,
              yport_recv_buffer.len);
      /* enable interrupts again */
      SREG = sreg;
    }
  } else if (uip_closed() || uip_aborted() || uip_timedout()) {
    /* if the closed connection was our connection, clean yport_conn */
    if (yport_conn == uip_conn)
      yport_conn = NULL;
  } else if (uip_newdata()) {
    if (uip_len <= YPORT_BUFFER_LEN && yport_rxstart(uip_appdata, uip_len) != 0) {
      /* Prevent the other side from sending more data */
      uip_stop();
    }
  } 
  if (uip_poll() 
      && uip_conn == yport_conn 
      && uip_stopped(yport_conn)
      && yport_send_buffer.sent == yport_send_buffer.len)
    uip_restart();
  /* Send data */
  if ((uip_poll() 
       || uip_acked()
       || uip_rexmit())
      && yport_conn == uip_conn 
      && yport_recv_buffer.len > 0) {
    /* We have recieved data, lets propagade it */
    /* disable interrupts */
    uint8_t sreg = SREG; cli();
    /* Send the data */
    uip_send(yport_recv_buffer.data, yport_recv_buffer.len);
    /* so many data was send */
    yport_recv_buffer.sent = yport_recv_buffer.len;
    /* enable interrupts again */
    SREG = sreg;
  }
}
Exemple #8
0
/*---------------------------------------------------------------------------*/
void
telnetd_appcall(void *ts)
{
  if(uip_connected()) {
    if(!connected) {
      buf_init(&buf);
      s.bufptr = 0;
      s.state = STATE_NORMAL;
      connected = 1;
      shell_start();
      timer_set(&s.silence_timer, MAX_SILENCE_TIME);
      ts = (char *)0;
    } else {
      uip_send(telnetd_reject_text, strlen(telnetd_reject_text));
      ts = (char *)1;
    }
    tcp_markconn(uip_conn, ts);
  }

  if(!ts) {
    if(s.state == STATE_CLOSE) {
      s.state = STATE_NORMAL;
      uip_close();
      return;
    }
    if(uip_closed() ||
       uip_aborted() ||
       uip_timedout()) {
      shell_stop();
      connected = 0;
    }
    if(uip_acked()) {
      timer_set(&s.silence_timer, MAX_SILENCE_TIME);
      acked();
    }
    if(uip_newdata()) {
      timer_set(&s.silence_timer, MAX_SILENCE_TIME);
      newdata();
    }
    if(uip_rexmit() ||
       uip_newdata() ||
       uip_acked() ||
       uip_connected() ||
       uip_poll()) {
      senddata();
      if(s.numsent > 0) {
	timer_set(&s.silence_timer, MAX_SILENCE_TIME);
      }
    }
    if(uip_poll()) {
      if(timer_expired(&s.silence_timer)) {
        uip_close();
        tcp_markconn(uip_conn, NULL);
      }
    }
  }
}
Exemple #9
0
static void
jabber_main(void)
{
  if (uip_aborted() || uip_timedout())
  {
    JABDEBUG("connection aborted\n");
    jabber_conn = NULL;
  }

  if (uip_closed())
  {
    JABDEBUG("connection closed\n");
    jabber_conn = NULL;
  }

  if (uip_connected())
  {
    JABDEBUG("new connection\n");
    STATE->stage = JABBER_OPEN_STREAM;
    STATE->sent = JABBER_INIT;

#ifdef JABBER_STARTUP_MESSAGE_SUPPORT
    strncpy_P(STATE->target, PSTR(CONF_JABBER_BUDDY), sizeof(STATE->target));
    strncpy_P(STATE->outbuf, jabber_startup_text, sizeof(STATE->outbuf));
    STATE->action = JABBER_ACTION_MESSAGE;
#endif /* JABBER_STARTUP_MESSAGE_SUPPORT */
  }

  if (uip_acked() && STATE->stage == JABBER_CONNECTED)
  {
    STATE->action = JABBER_ACTION_NONE;
    *STATE->outbuf = 0;
  }

  if (uip_newdata() && uip_len)
  {
    /* Zero-terminate */
    ((char *) uip_appdata)[uip_len] = 0;
    JABDEBUG("received data: %s\n", uip_appdata);

    if (jabber_parse())
    {
      uip_close();              /* Parse error */
      return;
    }
  }

  if (uip_rexmit())
    jabber_send_data(STATE->stage, STATE->action);

  else if ((STATE->stage > STATE->sent || STATE->stage == JABBER_CONNECTED)
           && (uip_newdata() || uip_acked() || uip_connected()))
    jabber_send_data(STATE->stage, STATE->action);
  else if (STATE->stage == JABBER_CONNECTED && uip_poll() && STATE->action)
    jabber_send_data(STATE->stage, STATE->action);

}
/******************************************************************************
* void exosite_appcall(void)
*
* This function is uIP's application function.  It is called whenever a uIP 
* event occurs (e.g. when a new connection is established, new data arrives, 
* sent data is acknowledged, data needs to be retransmitted, etc.).
* 
******************************************************************************/ 
void exosite_appcall(void)
{
  if(uip_connected()) {
    s.timer = 0;
    senddata();
    return;
  }

  if(s.state == EXO_STATE_CLOSE) {
    uip_abort();
    return;
  }
  
  if(uip_aborted()) {
  }
  if(uip_timedout()) {
  }

  if(uip_acked()) {
    s.timer = 0;
    acked();
  }

  if(uip_newdata()) {
    s.timer = 0;
    newdata();
  }
 
  if(uip_rexmit() || uip_newdata() || uip_acked()) {
    senddata();
  } else if(uip_poll()) {
    ++s.timer;
    if(s.timer == EXO_TIMEOUT) {
      uip_abort();
      return;
    }
  }
#if 0  
  if(uip_closed()) {
    if(s.httpflag != HTTPFLAG_MOVED) {
      memset(s.rxdata,0,sizeof(s.rxdata));
    } else {
      if(resolv_lookup(s.host) == NULL) {
	      resolv_query(s.host);
      }
    }
  }
#endif

}
Exemple #11
0
/*-----------------------------------------------------------------------------------*/
static u8_t
processes(void)
{
  u8_t i;
  struct dispatcher_proc *p;


  p = DISPATCHER_PROCS();
  for(i = 0; i < hs->count; ++i) {
    if(p != NULL) {
      p = p->next;
    }
  }

  if(uip_acked()) {
    /* If the previously sent data has been acknowledged, we move
       forward one connection. */
    ++hs->count;
    if(p != NULL) {
      p = p->next;
    }
    if(p == NULL) {
      /* If all processes have been printed out, we are done and
	 return 1. */
      return 1;
    }
  }

  sprintf((char *)uip_appdata,
	  "<tr align=\"center\"><td>%3d</td><td>%s</td><td>0x%04x</td><td>0x%04x</td><td>0x%04x</td></tr>\r\n",
	  p->id, p->name,
	  p->idle, p->signalhandler, p->uiphandler);
  uip_send(uip_appdata, strlen((char *)uip_appdata));
  return 0;
}
Exemple #12
0
/*---------------------------------------------------------------------------*/
static char
data_is_sent_and_acked(CC_REGISTER_ARG struct psock *s)
{
  /* If data has previously been sent, and the data has been acked, we
     increase the send pointer and call send_data() to send more
     data. */
  if(s->state != STATE_DATA_SENT || uip_rexmit()) {
    if(s->sendlen > uip_mss()) {
      uip_send(s->sendptr, uip_mss());
    } else {
      uip_send(s->sendptr, s->sendlen);
    }
    s->state = STATE_DATA_SENT;
    return 0;
  } else if(s->state == STATE_DATA_SENT && uip_acked()) {
    if(s->sendlen > uip_mss()) {
      s->sendlen -= uip_mss();
      s->sendptr += uip_mss();
    } else {
      s->sendptr += s->sendlen;
      s->sendlen = 0;
    }
    s->state = STATE_ACKED;
    return 1;
  }
  return 0;
}
Exemple #13
0
/*****************************************************************************
 函 数 名  : example2_app
 功能描述  : just a example function for tcp connect
 输入参数  : void  
 输出参数  : 无
 返 回 值  : 
 调用函数  : 
 被调函数  : 
 
 修改历史      :
  1.日    期   : 2017年4月17日
    作    者   : QSWWD
    修改内容   : 新生成函数

*****************************************************************************/
static void example2_app(void) 
{
	struct example2_state *s;
	s = (struct example2_state *)uip_conn->appstate;
	if(uip_connected()) {
		s->state = WELCOME_SENT;
		uip_send("Welcome!\n\r", 10);
		return;
	}
	if(uip_acked() && s->state == WELCOME_SENT) {
		s->state = WELCOME_ACKED;
	}
	if(uip_newdata()) { 
		uip_send("ok!You are trying to connect to UIP.\n\r", 43);
	}
	if(uip_rexmit()) {
		switch(s->state) {
		case WELCOME_SENT:
			uip_send("Welcome,the rexmit!\n\r", 20);
			break;
		case WELCOME_ACKED:
			uip_send("ok!this is retransmit.\n\r",30);
			break;
		default:
			uip_send("the rexmit ,Your's command is something error.\n\r", 50);
			break;
		}
	}
}
void uip_task_appcall()
{  
	if(uip_connected()) 
	{
		socket_process_new_connect_();
	}else
	if(uip_poll())
	{
		if(uip_stopped(uip_conn))
		{
			socket_process_try_restart_();
		}
		
		socket_process_write_();
	}else
	if(uip_newdata())
	{
		socket_process_new_data_();
		socket_process_write_();
	}else
	if(uip_aborted() || uip_closed())
	{
		socket_process_close_();
	}else
	if(uip_timedout())
	{
		socket_process_timeout_();
		uip_close();
	}else
	if(uip_acked() || uip_rexmit())
	{
		socket_process_write_();
	}
}
Exemple #15
0
void lp_tcp_appcall(void) {
	struct lp_tcp_state *s;

	s = &(uip_conn->appstate);

	if (uip_connected()) {
		s->state = WELCOME_SENT;
		uip_send("Handshake complete!\n", 20);
		return;
	}

	if (uip_acked() && s->state == WELCOME_SENT) {
		s->state = WELCOME_ACKED;
	}

	if (uip_newdata()) {
		P1OUT ^= BIT0;
		uip_send("Received packet\n", 16);
	}

	if (uip_rexmit()) {
		switch(s->state) {
		case WELCOME_SENT:
			uip_send("Handshake complete!\n", 20);
			break;
		case WELCOME_ACKED:
			uip_send("Received packet\n", 16);
			break;
		}
	}
}
Exemple #16
0
Fichier : app.c Projet : tuteng/uip
void example2_app(void) {
struct  example2_state *s;
	s = (struct  example2_state *)uip_conn->appstate;
	if(uip_connected()) {
	s->state = WELCOME_SENT;
	uip_send("Welcome!\n", 9);
return;
}
	if(uip_acked() && s->state == WELCOME_SENT) {
	s->state = WELCOME_ACKED;
	}
	if(uip_newdata()) {
	uip_send("ok1\n", 4);
	led_on();
//	while(1);
	led_off();
	}
	if(uip_rexmit()) {
		switch(s->state) {
			case WELCOME_SENT:
				uip_send("Welcome!\n", 9);
				break;
			case WELCOME_ACKED:
				uip_send("ok2\n", 4);
				break;
		}
	}
}
/*-----------------------------------------------------------------------------------*/
void
vnc_server_appcall(struct vnc_server_state *vs)
{

    vs->type = uip_htons(uip_conn->lport) - 5900;

    if(uip_connected()) {
        vnc_new(vs);
        vs->state = VNC_VERSION;
        vnc_server_send_data(vs);
        return;
    }
    if(uip_acked()) {
        PRINTF(("Acked\n"));
        vnc_acked(vs);
    }

    if(uip_newdata()) {
        PRINTF(("Newdata\n"));
        vs->counter = 0;
        if(vnc_read_data(vs) == 0) {
            uip_abort();
            return;
        }
    }

    if(uip_rexmit()) {
        PRINTF(("Rexmit\n"));
    }


    if(uip_newdata() ||
            uip_rexmit() ||
            uip_acked()) {
        vnc_server_send_data(vs);
    } else if(uip_poll()) {
        ++vs->counter;
        /* Abort connection after about 20 seconds of inactivity. */
        if(vs->counter >= 40) {
            uip_abort();
            return;
        }

        vnc_out_poll(vs);
    }

}
Exemple #18
0
void
httpd_main(void)
{
  if (uip_aborted() || uip_timedout())
  {
    printf("httpd: connection aborted\n");
    httpd_cleanup();
    return;
  }

  if (uip_closed())
  {
    printf("httpd: connection closed\n");
    httpd_cleanup();
    return;
  }

  if (uip_connected())
  {
    printf("httpd: new connection\n");

    /* initialize struct */
    STATE->handler = NULL;
    STATE->header_acked = 0;
    STATE->eof = 0;
    STATE->header_reparse = 0;
#ifdef HTTPD_AUTH_SUPPORT
    STATE->auth_state = PAM_UNKOWN;
#endif
  }

  if (uip_newdata() && (!STATE->handler || STATE->header_reparse))
  {
    printf("httpd: new data\n");
    httpd_handle_input();
  }

#ifdef HTTPD_AUTH_SUPPORT
  if (STATE->auth_state == PAM_DENIED && STATE->handler != httpd_handle_401)
  {
    httpd_cleanup();
    STATE->handler = httpd_handle_401;
    STATE->header_reparse = 0;
    printf("httpd: auth failed\n");
  }
  else if (STATE->auth_state == PAM_PENDING)
    return;                     /* Waiting for the PAM Layer */
#endif


  if (uip_rexmit() ||
      uip_newdata() || uip_acked() || uip_poll() || uip_connected())
  {

    /* Call associated handler, if set already. */
    if (STATE->handler && (!STATE->header_reparse))
      STATE->handler();
  }
}
Exemple #19
0
/*-----------------------------------------------------------------------------------*/
void
telnet_app(void *ts)
{
  struct telnet_state *s = (struct telnet_state *)ts;
    
  if(uip_connected()) {
    s->flags = 0;
    telnet_connected(s);
    senddata(s);
    return;
  }
  
  if(uip_closed()) {
    telnet_closed(s);
  }
  
  if(uip_aborted()) {
    telnet_aborted(s);
  }
  if(uip_timedout()) {
    telnet_timedout(s);
  }

  if(s->flags & FLAG_CLOSE) {
    uip_close();
    return;
  }
  if(s->flags & FLAG_ABORT) {
    uip_abort();
    return;
  }
  if(uip_acked()) {
    acked(s);
  }
  if(uip_newdata()) {
    telnet_newdata(s, (char *)uip_appdata, uip_datalen());
  }
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked()) {
    senddata(s);
  } else if(uip_poll()) {
    senddata(s);
  }
}
Exemple #20
0
/*---------------------------------------------------------------------*/
static
PT_THREAD(recv_tcpthread(struct pt *pt))
{
  PT_BEGIN(pt);

  /* Read the header. */
  PT_WAIT_UNTIL(pt, uip_newdata() && uip_datalen() > 0);

  if(uip_datalen() < sizeof(struct codeprop_tcphdr)) {
    PRINTF(("codeprop: header not found in first tcp segment\n"));
    uip_abort();
    goto thread_done;
  }

  s.len = uip_htons(((struct codeprop_tcphdr *)uip_appdata)->len);
  s.addr = 0;
  uip_appdata += sizeof(struct codeprop_tcphdr);
  uip_len -= sizeof(struct codeprop_tcphdr);

  xmem_erase(XMEM_ERASE_UNIT_SIZE, EEPROMFS_ADDR_CODEPROP);

  /* Read the rest of the data. */
  do {      
    if(uip_len > 0) {
      xmem_pwrite(uip_appdata, uip_len, EEPROMFS_ADDR_CODEPROP + s.addr);
      s.addr += uip_len;
    }
    if(s.addr < s.len) {
      PT_YIELD_UNTIL(pt, uip_newdata());
    }	
  } while(s.addr < s.len);

  /* Kill old program. */
  elfloader_unload();

  /* Link, load, and start new program. */
  int s;
  static char msg[30 + 10];
  s = elfloader_load(EEPROMFS_ADDR_CODEPROP);
  if (s == ELFLOADER_OK)
    sprintf(msg, "ok\n");
  else
    sprintf(msg, "err %d %s\n", s, elfloader_unknown);
    
  /* Return "ok" message. */
  do {
    s = strlen(msg);
    uip_send(msg, s);
    PT_WAIT_UNTIL(pt, uip_acked() || uip_rexmit() || uip_closed());
  } while(uip_rexmit());

  /* Close the connection. */
  uip_close();
    
 thread_done:;
  PT_END(pt);
}
/*---------------------------------------------------------------------------*/
void
telnetd_appcall(void)
{
  static unsigned int i;
  if(uip_connected()) {
    /*    tcp_markconn(uip_conn, &s);*/
    for(i = 0; i < TELNETD_CONF_NUMLINES; ++i) {
      s.lines[i] = NULL;
    }
    s.bufptr = 0;
    s.state = STATE_NORMAL;

    shell_start();
  }

  if(s.state == STATE_CLOSE) {
    s.state = STATE_NORMAL;
    uip_close();
    return;
  }
  
  if(uip_closed() ||
     uip_aborted() ||
     uip_timedout()) {
    closed();
  }
  
  if(uip_acked()) {
    acked();
  }
  
  if(uip_newdata()) {
    newdata();
  }
  
  if(uip_rexmit() ||
     uip_newdata() ||
     uip_acked() ||
     uip_connected() ||
     uip_poll()) {
    senddata();
  }
}
Exemple #22
0
static u8_t
file_stats(void)
{
  /* We use sprintf() to print the number of file accesses to a
     particular file (given as an argument to the function in the
     script). We then use uip_send() to actually send the data. */
  if(uip_acked()) {
    return 1;
  }
  uip_send(uip_appdata, sprintf((char *)uip_appdata, "%5u", httpd_fs_count(&hs->script[4])));
  return 0;
}
Exemple #23
0
/*-----------------------------------------------------------------------------------*/
static u8_t
sensors(void)
{
  if(uip_acked()) {
    return 1;
  }
  sprintf((char *)uip_appdata,
	  "<li>Microphone 0x%x<br><li>Battery 0x%x<br><li>Temp %d<br><li>Extern 0x%x<br>",
	  sensors_mic, sensors_battery, sensors_temp, sensors_extern);
  uip_send(uip_appdata, strlen((char *)uip_appdata));
  return 0;
}
/*-----------------------------------------------------------------------------------*/
void
specserver_appcall(void)
{
	static uint8_t reqs = 0; static char *data;
	if( uip_conn->lport != HTONS( SPECIAL_SERVER_PORT ) ) return; 
	specserver_stats.frames++;

	if( uip_connected() ) {
		reqs = 0;
	}
	if( uip_newdata() ) {
		specserver_stats.recv++;
		char *p;
		// Process response
		data = (char*)uip_appdata;
		p = strchr( data, '\r' ); if( p != NULL ) *p = 0;
		p = strchr( data, '\n' ); if( p != NULL ) *p = 0;
		data[50] = 0;	// Limit max size to one line or 50 char, whicever is smaller
		reqs++;
	}
	if( uip_acked() ) {
	}
	if( uip_rexmit() ||
		uip_newdata() ||
		uip_acked()) {
		// Send response
		if( reqs > 0 ) {
			reqs--;
			uip_send( specserver_resp_data, specserver_resp_data_len );
		}else{
			uip_close();
		}
	} else if(uip_poll()) {
		uip_close();
	}
}
Exemple #25
0
static void
mysql_main(void)
{
    if (uip_aborted() || uip_timedout()) {
	MYDEBUG ("connection aborted\n");
	mysql_conn = NULL;
    }

    if (uip_closed()) {
	MYDEBUG ("connection closed\n");
	mysql_conn = NULL;
    }

    if (uip_connected()) {
	MYDEBUG ("new connection\n");
	STATE->stage = MYSQL_WAIT_GREETING;
	STATE->sent = MYSQL_WAIT_GREETING;
	STATE->packetid = 0;
    }

    if (uip_newdata() && uip_len) {
#ifdef DEBUG_MYSQL
	MYDEBUG ("received data: %s\n", uip_appdata);
	for (uint16_t i = 0; i < uip_len; i ++)
	    debug_putchar (((unsigned char *) uip_appdata)[i]);
	debug_putchar (10);
#endif

	if (mysql_parse ()) {
	    uip_close ();		/* Parse error */
	    return;
	}
    }

    if (uip_rexmit()) {
	STATE->packetid --;
	mysql_send_data (STATE->sent);
    }
    else if ((STATE->stage > STATE->sent || STATE->stage == MYSQL_CONNECTED)
	     && (uip_newdata()
		 || uip_acked()
		 || uip_connected()))
	mysql_send_data (STATE->stage);
    else if (STATE->stage == MYSQL_CONNECTED
	     && uip_poll() && *STATE->u.stmtbuf)
	mysql_send_data(STATE->stage);

}
Exemple #26
0
/*---------------------------------------------------------------------------*/
static char
data_acked(register struct psock *s)
{
  if(s->state == STATE_DATA_SENT && uip_acked()) {
    if(s->sendlen > uip_mss()) {
      s->sendlen -= uip_mss();
      s->sendptr += uip_mss();
    } else {
      s->sendptr += s->sendlen;
      s->sendlen = 0;
    }
    s->state = STATE_ACKED;
    return 1;
  }
  return 0;
}
Exemple #27
0
void
httpd_handle_404 (void)
{
    if (uip_acked ()) {
	uip_close ();
	return;
    }

    PASTE_RESET ();
    PASTE_P (httpd_header_404);
    PASTE_P (httpd_header_length);
    PASTE_LEN_P (httpd_body_404);
    PASTE_P (httpd_header_end);
    PASTE_P (httpd_body_404);
    PASTE_SEND ();
}
void
httpd_handle_websocket (void)
{
    if (uip_acked ()) {
	uip_close ();
	return;
    }

    PASTE_RESET ();
    PASTE_P (httpd_header_opt);
    //PASTE_P (httpd_header_length);
    //PASTE_LEN_P (httpd_body_opt);
    PASTE_P (httpd_header_end);
    //PASTE_P (httpd_body_opt);
    PASTE_SEND ();
}
Exemple #29
0
void mqttclient_appcall(void) {
    if (uip_poll()) {
        _mqttclient_transfer_buffer();
    } else if (uip_connected()) {
        update_state(MQTTCLIENT_BROKER_CONNECTION_ESTABLISHED);
        umqtt_connect(&_mqtt, &_connection_config);
        _mqttclient_transfer_buffer();
    } else if (uip_aborted() || uip_timedout() || uip_closed()) {
        _mqttclient_handle_communication_error();
    } else  if (uip_newdata()) {
        _mqttclient_handle_new_data();
    } else if (uip_acked()) {
        _is_sending = false;
    } else if (uip_rexmit()) {
        _mqttclient_send();
    }
}
Exemple #30
0
static void
httplog_net_main(void)
{
  if (uip_aborted() || uip_timedout())
  {
    HTTPLOG_DEBUG("connection aborted\n");
    goto end;
  }

  if (uip_closed())
  {
    HTTPLOG_DEBUG("connection closed\n");
    goto end;
  }


  if (uip_connected() || uip_rexmit())
  {
    HTTPLOG_DEBUG("new connection or rexmit, sending message\n");
    char *p = uip_appdata;
    p += sprintf_P(p, get_string_head);
#ifdef CONF_HTTPLOG_INCLUDE_UUID
    p += sprintf_P(p, uuid_string);
#endif
#ifdef CONF_HTTPLOG_INCLUDE_TIMESTAMP
    p += sprintf_P(p, time_string);
    p += sprintf(p, "%lu&", clock_get_time());
#endif
    p += sprintf(p, httplog_tmp_buf);
    p += sprintf_P(p, get_string_foot);
    uip_udp_send(p - (char *) uip_appdata);
    HTTPLOG_DEBUG("send %d bytes\n", p - (char *) uip_appdata);
  }

  if (uip_acked())
  {
    uip_close();
  end:
    if (httplog_tmp_buf)
    {
      free(httplog_tmp_buf);
      httplog_tmp_buf = NULL;
    }
  }
}