/*
 * Initialize the protocol:
 *
 * - initialise the protocol state array with 'inactive' flags
 * - 'listen' on the protocol server ports
 */
void demo_protocol_init(chanend tcp_svr) {
	for (int i = 0; i < NUM_DEMO_PROTOCOL_CONNECTIONS; i++) {
		connection_states[i].active = 0;
	}
	xtcp_listen(tcp_svr, DEMO_PROTOCOL_PORT, XTCP_PROTOCOL_TCP);
	xtcp_listen(tcp_svr, DEMO_PROTOCOL_PORT, XTCP_PROTOCOL_UDP);
}
Пример #2
0
void httpd_init(chanend tcp_svr) 
{
  int i;
  xtcp_listen(tcp_svr, HTTP_SERVER_PORT, XTCP_PROTOCOL_TCP);
  for (i=0;i<NUM_HTTPD_CONNECTIONS;i++) {
    connection_states[i].active = 0;
  }
}
Пример #3
0
// Initiate the HTTP state
void telnetd_init(chanend tcp_svr)
{
  int i;
  // Listen on the http port
  xtcp_listen(tcp_svr, TELNETD_PORT, XTCP_PROTOCOL_TCP);
  
  for ( i = 0; i < NUM_TELNETD_CONNECTIONS; i++ )
    {
      connection_states[i].active = 0;
      connection_states[i].index = i;
    }
}
Пример #4
0
// Initialize the HTTP state
void tcp_init(chanend tcp_svr)
{
  int i;
  // Listen on the http port
  xtcp_listen(tcp_svr, 80, XTCP_PROTOCOL_TCP);

  for ( i = 0; i < NUM_HTTPD_CONNECTIONS; i++ )
    {
      connection_states[i].active = 0;
      connection_states[i].dptr = NULL;
    }
}
void telnet_config_init(chanend c_xtcp) {
  for (int i=0;i<TELNET_CONFIG_NUM_CONNECTIONS;i++) {
    telnet_config_states[i].active = 0;
  }
  xtcp_listen(c_xtcp, S2E_TELNET_CONFIG_PORT, XTCP_PROTOCOL_TCP);
}
Пример #6
0
static void process_xscope_data(chanend c_xtcp, xscope_protocol xscope_data)
{
    /* Custom protocol definition
     * Start with cmd_type, send end_token as 0 as last
     * Listen:    0-dc-inport-proto-dc
     * Connect:   1-dc-out_port-proto-host_ipconfig
     * Send:      2-1-local_port-dc-remote_addr
     * Close:     2-2-local_port-dc-remote_addr
     */
#define CONTROLLER_IP	{169, 254, 196, 179}
#if !defined(CONTROLLER_IP)
#warning No define of form CONTROLLER_IP
#error Rebuild the application with this define assigned to the host controller ip
#endif

    xtcp_ipaddr_t ipaddr = CONTROLLER_IP;
    /*ipaddr[0] = atoi(xscope_data.ip_addr_1);
    ipaddr[1] = atoi(xscope_data.ip_addr_2);
    ipaddr[2] = atoi(xscope_data.ip_addr_3);
    ipaddr[3] = atoi(xscope_data.ip_addr_4);*/

    switch (xscope_data.cmd_type) {
      case XSCOPE_CMD_LISTEN: //listen; for server type conn
        xtcp_listen(c_xtcp, xscope_data.port_no, xscope_data.protocol);
        printstr("Listening on port: ");
        printintln(xscope_data.port_no);
      break;
      case XSCOPE_CMD_CONNECT: //connect; for client type conn
        xtcp_connect(c_xtcp, xscope_data.port_no, ipaddr, xscope_data.protocol);
        printstr("Connected to host on port: ");
        printintln(xscope_data.port_no);
      break;
      case XSCOPE_CMD_SEND: { //Send data
        int conn_id;
        xtcp_connection_t conn;
    	if (PROTO_TCP == xscope_data.protocol)
          conn_id = get_tcp_conn_id(ipaddr,  xscope_data.port_no);
    	else if (PROTO_UDP == xscope_data.protocol)
          conn_id = get_udp_conn_id(ipaddr,  xscope_data.port_no);

        if (conn_id) {
       	  conn.id = conn_id;
          xtcp_init_send(c_xtcp, &conn);
       	  printstr("Sending data on the connection: ");
       	  printintln(conn_id);
        }
      }
      break;
      case XSCOPE_CMD_CLOSE: { //Close command
        int conn_id;
        xtcp_connection_t conn;
        if (PROTO_TCP == xscope_data.protocol)
          conn_id = get_tcp_conn_id(ipaddr,  xscope_data.port_no);
        else if (PROTO_UDP == xscope_data.protocol)
          conn_id = get_udp_conn_id(ipaddr,  xscope_data.port_no);

    	if (conn_id) {
       	  conn.id = conn_id;
       	  xtcp_close(c_xtcp, &conn);
       	  printstr("Closing the connection: ");
       	  printintln(conn_id);
        }
      }
      break;
      case XSCOPE_CMD_CTRLR_SEND: //this is a controller send command; do nothing
      break;
      default:
        printstrln("unknown command received");
      break;
    }
}
Пример #7
0
// Initialize the connection states
void tcpd_xscope_init(chanend c_xtcp)
{
  // Listen on the app port
  xtcp_listen(c_xtcp, TCP_XSCOPE_PORT, XTCP_PROTOCOL_TCP);
}