Exemple #1
0
/*
 *  Entry point of the SNMP server.
 */
PROCESS_THREAD(snmpd_process, ev, data) {
	PROCESS_BEGIN();

	snmp_packets = 0;

        #ifndef CONTIKI_TARGET_AVR_RAVEN
        systemStartTime = clock_time();
        #endif

        #if CHECK_STACK_SIZE
        u16t i = 0;
        u32t pointer;
        u32t* p = &pointer;
        for (i = 0; i < 1000; i++) {
            *p = 0xAAAAAAAA;
            p--;
        }
        marker = &pointer;
        #endif

	udpconn = udp_new(NULL, UIP_HTONS(0), NULL);
	udp_bind(udpconn, UIP_HTONS(LISTEN_PORT));

        /* init MIB */
        if (mib_init() != -1) {
            
            while(1) {
                PROCESS_YIELD();
                udp_handler(ev, data);
            }
        } else {
            snmp_log("error occurs while initializing the MIB\n");
        }
	PROCESS_END();
}
Exemple #2
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(sensortag_process, ev, data)
{

  static struct etimer et;
  uip_ipaddr_t ipaddr;

  etimer_set(&et, CLOCK_CONF_SECOND*20);
  PROCESS_BEGIN();

  PROCESS_WAIT_EVENT_UNTIL(ev == PROCESS_EVENT_TIMER);
  if(uip_ds6_get_global(ADDR_PREFERRED) == NULL) {
    printf("NO IP \n\r");
  }
  else{
    printf("Good \n\r");
  }
  print_local_addresses();
  if(uiplib_ipaddrconv("2001:0db8:0002:0000:0000:0000:0000:0002", &ipaddr)){
    printf("Get server IP! \n\r");
  }
  /* new connection with remote host */
  client_conn = udp_new(&ipaddr, UIP_HTONS(10001), NULL);
  udp_bind(client_conn, UIP_HTONS(10002));
  printf("Connect! \n\r");

  init_hdc_reading(NULL);
  while(1) {
    PROCESS_YIELD();
    if(ev == sensors_event && data == &hdc_1000_sensor) {
      get_hdc_reading();
    }
  }

  PROCESS_END();
}
Exemple #3
0
/******************************************************************************
 * FunctionName : espconn_udp_server
 * Description  : Initialize the server: set up a PCB and bind it to the port
 * Parameters   : pespconn -- the espconn used to build server
 * Returns      : none
*******************************************************************************/
sint8 ICACHE_FLASH_ATTR
espconn_udp_server(struct espconn *pespconn)
{
    struct udp_pcb *upcb = NULL;
    espconn_msg *pserver = NULL;
    upcb = udp_new();

    if (upcb == NULL) {
        return ESPCONN_MEM;
    } else {
        pserver = (espconn_msg *)os_zalloc(sizeof(espconn_msg));

        if (pserver == NULL) {
            udp_remove(upcb);
            return ESPCONN_MEM;
        }

        pserver->pcommon.pcb = upcb;
        pserver->pespconn = pespconn;
        espconn_list_creat(&plink_active, pserver);
        udp_bind(upcb, IP_ADDR_ANY, pserver->pespconn->proto.udp->local_port);
        udp_recv(upcb, espconn_udp_recv, (void *)pserver);
        return ESPCONN_OK;
    }
}
Exemple #4
0
/**
 * Starts SNMP Agent.
 * Allocates UDP pcb and binds it to IP_ADDR_ANY port 161.
 */
void
snmp_init(void)
{
  struct snmp_msg_pstat *msg_ps;
  u8_t i;

  snmp1_pcb = udp_new();
  if (snmp1_pcb != NULL)
  {
    udp_recv(snmp1_pcb, snmp_recv, (void *)SNMP_IN_PORT);
    udp_bind(snmp1_pcb, IP_ADDR_ANY, SNMP_IN_PORT);
  }
  msg_ps = &msg_input_list[0];
  for (i=0; i<SNMP_CONCURRENT_REQUESTS; i++)
  {
    msg_ps->state = SNMP_MSG_EMPTY;
    msg_ps->error_index = 0;
    msg_ps->error_status = SNMP_ES_NOERROR;
    msg_ps++;
  }
  trap_msg.pcb = snmp1_pcb;

#ifdef SNMP_PRIVATE_MIB_INIT
  /* If defined, this must be a function-like define to initialize the
   * private MIB after the stack has been initialized.
   * The private MIB can also be initialized in tcpip_callback (or after
   * the stack is initialized), this define is only for convenience. */
  SNMP_PRIVATE_MIB_INIT();
#endif /* SNMP_PRIVATE_MIB_INIT */

  /* The coldstart trap will only be output
     if our outgoing interface is up & configured  */
  snmp_coldstart_trap();
}
/**
  * @brief  Initialize the server application.
  * @param  None
  * @retval None
  */
void udp_echoserver_init(void)
{
   struct udp_pcb *upcb;
   err_t err;
   
   /* Create a new UDP control block  */
   upcb = udp_new();
   
   if (upcb)
   {
     /* Bind the upcb to the UDP_PORT port */
     /* Using IP_ADDR_ANY allow the upcb to be used by any local interface */
      err = udp_bind(upcb, IP_ADDR_ANY, UDP_SERVER_PORT);
      
      if(err == ERR_OK)
      {
        /* Set a receive callback for the upcb */
        udp_recv(upcb, udp_echoserver_receive_callback, NULL);
      }
      else
      {
        udp_remove(upcb);
      }
   }
}
Exemple #6
0
int main (void)
{
    zctx_t *ctx = zctx_new ();
    udp_t *udp = udp_new (PING_PORT_NUMBER);
    
    byte buffer [PING_MSG_SIZE];
    zmq_pollitem_t pollitems [] = {{ NULL, udp_handle (udp), ZMQ_POLLIN, 0 }};
    
    //  Send first ping right away
    uint64_t ping_at = zclock_time ();
    
    while (!zctx_interrupted) {
        long timeout = (long) (ping_at - zclock_time ());
        if (timeout < 0)
            timeout = 0;
        if (zmq_poll (pollitems, 1, timeout * ZMQ_POLL_MSEC) == -1)
            break;              //  Interrupted

        //  Someone answered our ping
        if (pollitems [0].revents & ZMQ_POLLIN)
            udp_recv (udp, buffer, PING_MSG_SIZE);
        
        if (zclock_time () >= ping_at) {
            puts ("Pinging peers...");
            buffer [0] = '!';
            udp_send (udp, buffer, PING_MSG_SIZE);
            ping_at = zclock_time () + PING_INTERVAL;
        }
    }
    udp_destroy (&udp);
    zctx_destroy (&ctx);
    return 0;
}
Exemple #7
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{

  PROCESS_BEGIN();
  PRINTF("UDP server started\n");

#if UIP_CONF_ROUTER
  uip_ip6addr(&ipaddr, 0xaaaa, 0, 0, 0, 0, 0, 0, 0);
  uip_netif_addr_add(&ipaddr, 64, 0, AUTOCONF);
#endif /* UIP_CONF_ROUTER */

  print_local_addresses();

  server_conn = udp_new(NULL, HTONS(61617), NULL);
  udp_bind(server_conn, HTONS(61616));

  PRINTF("Created a server connection with remote address ");
  PRINT6ADDR(&server_conn->ripaddr);
  PRINTF("local/remote port %u/%u\n", HTONS(server_conn->lport),
         HTONS(server_conn->rport));

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
Exemple #8
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(servreg_hack_process, ev, data)
{
  static struct etimer periodic;
  static struct uip_udp_conn *outconn, *inconn;
  PROCESS_BEGIN();

  /* Create outbound UDP connection. */
  outconn = udp_broadcast_new(UIP_HTONS(UDP_PORT), NULL);
  udp_bind(outconn, UIP_HTONS(UDP_PORT));

  /* Create inbound UDP connection. */
  inconn = udp_new(NULL, UIP_HTONS(UDP_PORT), NULL);
  udp_bind(inconn, UIP_HTONS(UDP_PORT));

  etimer_set(&periodic, PERIOD_TIME);
  etimer_set(&sendtimer, random_rand() % (PERIOD_TIME));
  while(1) {
    PROCESS_WAIT_EVENT();
    if(ev == PROCESS_EVENT_TIMER && data == &periodic) {
      etimer_reset(&periodic);
      etimer_set(&sendtimer, random_rand() % (PERIOD_TIME));
    } else if(ev == PROCESS_EVENT_TIMER && data == &sendtimer) {
      send_udp_packet(outconn);
    } else if(ev == tcpip_event) {
      parse_incoming_packet(uip_appdata, uip_datalen());
    }
  }
  PROCESS_END();
}
Exemple #9
0
PROCESS_THREAD(receive_process, ev, data)
{
    PROCESS_BEGIN();
    
    static struct uip_udp_conn* server_conn;
    server_conn = udp_new(NULL, UIP_HTONS(UDP_CLIENT_PORT), NULL);
    udp_bind(server_conn, UIP_HTONS(UDP_SERVER_PORT));

    while(1) {
        PROCESS_YIELD();
        if(ev == tcpip_event) {
            uint8_t* appdata = uip_appdata;
            ASSERT((uip_datalen() % sizeof(uint32_t)) == 0);
            size_t numberof_values = uip_datalen() / sizeof(uint32_t);


            printf("trace: received values: ");
            uint32_t value;
            size_t i;
            for (i=0; i<numberof_values; i++) {
                ASSERT(offset < MAX_NUMBEROF_VALUES);
                memcpy(&value, &appdata[i * sizeof(uint32_t)], sizeof(uint32_t));
                printf("%lu ", value);
                values[offset++] = value;
            }
            printf("\n");
        }
    }

    PROCESS_END();
}
Exemple #10
0
/* Glowny program */
PROCESS_THREAD(program_UDP, ev, data) {
    static struct etimer et;

    PROCESS_BEGIN();

#if UIP_CONF_IPV6 > 0
    uip_ip6addr(&ipaddr, addr[0], addr[1], addr[2], addr[3], addr[4], addr[5], addr[6], addr[7]);
#else
    uip_ipaddr(&ipaddr, addr[0], addr[1], addr[2], addr[3]);
#endif

    conn = udp_new(&ipaddr, UIP_HTONS(port), &state);
    udp_bind(conn, UIP_HTONS(port + 1));
    printf("Binded\n");

    etimer_set(&et, CLOCK_CONF_SECOND * 3);

    while (1) {
        PROCESS_WAIT_EVENT();
        if (uip_newdata()) {
            str = uip_appdata;
            str[uip_datalen()] = '\0';
            printf("Received: '%s'\n", str);
        }
        etimer_reset(&et);
    }

    PROCESS_END();
}
Exemple #11
0
PROCESS_THREAD(udp_plug_process, ev, data)
{
	static struct etimer et;
	PROCESS_BEGIN();

	
  
	PRINTF("UDP server started\r\n");
	
#if DEV_BOARD  
	leds_on(LEDS_RED | LEDS_GREEN);
	SENSORS_ACTIVATE(button_sensor);
#else
	leds_on(LEDS_GREEN);
	#ifdef HAS_PIR_SENSOR
		pir_state = PIR_DISPATCH;
		etimer_set(&pir_timer, PIR_INIT_TIME);
	#endif
#endif

#if HAS_TEMP_SENSOR
	start_temp_conv();
#endif

#if HAS_LIGHT_SENSOR
	light_sensor_init();
#endif

	udp_conn = udp_new(NULL, UIP_HTONS(0), NULL);
	udp_bind(udp_conn, UIP_HTONS(PLUG_PORT));
	PRINTF("listening on udp port %u\r\n",UIP_HTONS(udp_conn->lport));
	etimer_set(&et, SEND_INTERVAL);
	while(1) {
		PROCESS_YIELD();
		if(etimer_expired(&et)) {
			timeout_handler();
			etimer_restart(&et);

		}
#ifdef HAS_PIR_SENSOR		
		if((pir_state == PIR_DISPATCH)&&(etimer_expired(&pir_timer))) {
			SENSORS_ACTIVATE(button_sensor);
			pir_state = PIR_READY;
		}
#endif		
		if(ev == tcpip_event) {
			PRINTF("Calling tcpip_Handler\r\n");
			tcpip_handler();
		}
		
		if (ev == sensors_event && data == &button_sensor) {
#ifndef DEV_BOARD  
			handle_pir_event();
#endif
			PRINTF("Button Pressed\r\n");
		}
	}

  PROCESS_END();
}
/*-----------------------------------------------------------------------*/
PROCESS_THREAD(udp_sender_process, ev, data)
{
	static struct etimer period_timer, wait_timer;
	PROCESS_BEGIN();
	
	set_global_address();
	PRINTF("UDP sender process started\n");
	print_local_address();

	/* new connection with remote host */
	sender_conn = udp_new(NULL, UIP_HTONS(UDP_SINK_PORT), NULL);
	udp_bind(sender_conn, UIP_HTONS(UDP_SENDER_PORT));

	PRINTF("Created a connection with the sink ");
	PRINT6ADDR(&sender_conn->ripaddr);
	PRINTF(" local/remote port %u/%u\n",
			UIP_HTONS(sender_conn->lport), UIP_HTONS(sender_conn->rport));
	
	etimer_set(&period_timer, CLOCK_SECOND * PERIOD);
	while(1) {
		PROCESS_WAIT_EVENT();
		if(ev == PROCESS_EVENT_TIMER) {
			if(data == &period_timer) {
				etimer_reset(&period_timer);
				etimer_set(&wait_timer,
							random_rand() % (CLOCK_SECOND * RANDWAIT));
			} else if(data ==&wait_timer) {
				/* Time to send a data. */
				collect_common_send();
			}
		}
	}
	PROCESS_END();
}
Exemple #13
0
PROCESS_THREAD(sync_master, ev, data)
{
  static int i=0;
  static struct uip_udp_conn *udp;

  PROCESS_BEGIN();
    
  udp = udp_new(NULL, UIP_HTONS(10000), NULL);
  uip_udp_bind(udp, UIP_HTONS(10000));
  uart0_init(1000000);

  while(1)
  {
    PROCESS_YIELD_UNTIL(ev == tcpip_event);
    int i;
    for (i = 0; i < 16; i++)
      uart0_writeb(UDP_HDR->srcipaddr.u8[i]);
    for (i = 0; i < uip_datalen(); i++)
    {
      uart0_writeb(((uint8_t*)uip_appdata)[i]);
    }
  }

  PROCESS_END();
}
Exemple #14
0
/*---------------------------------------------------------------------------*/
void
init_dtls() {
  static dtls_handler_t cb = {
    .write = send_to_peer,
    .read  = read_from_peer,
    .event = NULL,
#ifdef DTLS_PSK
    .get_psk_info = get_psk_info,
#endif
#ifdef DTLS_ECC
    .get_ecdsa_key = NULL,
    .verify_ecdsa_key = NULL,
#endif
  };

  server_conn = udp_new(NULL, 0, NULL);
  udp_bind(server_conn, UIP_HTONS(DTLS_ECHO_PORT));

  dtls_set_log_level(DTLS_LOG_DEBUG);

  dtls_context = dtls_new_context(server_conn);
  if (dtls_context)
    dtls_set_handler(dtls_context, &cb);

  printf("DTLS server started\n");
}
Exemple #15
0
/**
 * \brief      Register a UDP connection
 * \param c    A pointer to a struct simple_udp_connection
 * \param local_port The local UDP port in host byte order
 * \param remote_addr The remote IP address
 * \param remote_port The remote UDP port in host byte order
 * \param receive_callback A pointer to a function to be called for incoming packets
 * \retval 0   If no UDP connection could be allocated
 * \retval 1   If the connection was successfully allocated
 *
 *             This function registers a UDP connection and attaches a
 *             callback function to it. The callback function will be
 *             called for incoming packets. The local UDP port can be
 *             set to 0 to indicate that an ephemeral UDP port should
 *             be allocated. The remote IP address can be NULL, to
 *             indicate that packets from any IP address should be
 *             accepted.
 *
 */
int
simple_udp_register(struct simple_udp_connection *c,
                    uint16_t local_port,
                    uip_ipaddr_t *remote_addr,
                    uint16_t remote_port,
                    simple_udp_callback receive_callback)
{

  init_simple_udp();

  c->local_port = local_port;
  c->remote_port = remote_port;
  if(remote_addr != NULL) {
    uip_ipaddr_copy(&c->remote_addr, remote_addr);
  }
  c->receive_callback = receive_callback;

  PROCESS_CONTEXT_BEGIN(&simple_udp_process);
  c->udp_conn = udp_new(remote_addr, UIP_HTONS(remote_port), c);
  if(c->udp_conn != NULL) {
    udp_bind(c->udp_conn, UIP_HTONS(local_port));
  }
  PROCESS_CONTEXT_END();

  if(c->udp_conn == NULL) {
    return 0;
  }
  return 1;
}
Exemple #16
0
void UdpConnection::initialize(udp_pcb* pcb /* = NULL*/)
{
	if (pcb == NULL)
		pcb = udp_new();
	udp = pcb;
	udp_recv(udp, staticOnReceive, (void*)this);
}
Exemple #17
0
TC_RUN_THREAD void server_thread()
{
    int i=0;
    for (i=0; i<sizeof(workers)/sizeof(worker_t); i++) {
        workers[i].busy = false;
    }

    ipconfig(false);

    struct uip_udp_conn* conn = udp_new(NULL, 0, NULL);
    udp_bind(conn, UDP_SERVER_PORT);

    while(1) {
        if (! tc_receive(&cond_server)) {
            for (i=0; i<sizeof(workers)/sizeof(worker_t); i++) {
                worker_t* worker = workers + i;
                if (worker->busy == false) {
                    worker->busy = true;
                    bool success = rpc_unmarshall_call(CALL, MAX_TELL_DEPTH, uip_appdata, uip_datalen());
                    ASSERT(success == true);
                    worker->peer = UIP_IP_BUF->srcipaddr;
                    tc_condition_signal(&worker->cond, NULL);
                    break;
                }
            }
            ASSERT(i != sizeof(workers)/sizeof(worker_t));
        } else {
            worker_t* worker = cond_server.data;
            worker->busy = false;
            int16_t size = rpc_marshall_response(RESPONSE, uip_appdata, UIP_BUFSIZE);
            ASSERT(size != -1);
            uip_udp_packet_sendto(conn, uip_appdata, size, &worker->peer, UDP_CLIENT_PORT);
        }
    }
}
int lwip_bind(int s, struct sockaddr *name, socklen_t namelen) {
	sockfd_t	* fd;
	struct ip_addr	ip;
	int		port, rv = 0;

	s = sock_for_fd(s);
	if (s < 0) {
		errno = EBADF;
		return -1;
	}
	fd = fds + s;

	// Make sure it's an internet address we understand.
	if (namelen != sizeof(struct sockaddr_in)) {
		errno = ENAMETOOLONG;
		return -1;
	}

	// Get access
	mutex_lock(fd->mutex);

	// Copy it over
	memcpy(&fd->name, name, namelen);

	// Convert this to an lwIP-happy format
	ip.addr = ((struct sockaddr_in *)name)->sin_addr.s_addr;
	port = ((struct sockaddr_in *)name)->sin_port;

	// Are we TCP or UDP?
	switch (fd->type) {
	case SOCK_STREAM:
		fd->tcppcb = tcp_new();
		tcp_arg(fd->tcppcb, (void *)s);
		tcp_recv(fd->tcppcb, recv_tcp);
		tcp_sent(fd->tcppcb, sent_tcp);
		tcp_poll(fd->tcppcb, poll_tcp, 4);	// 4 == 4 TCP timer intervals
		tcp_err(fd->tcppcb, err_tcp);
		if (tcp_bind(fd->tcppcb, &ip, ntohs(port)) != ERR_OK) {
			if (tcp_close(fd->tcppcb) != ERR_OK)
				tcp_abort(fd->tcppcb);
			fd->tcppcb = NULL;
			errno = EINVAL;
			rv = -1; goto out;
		}
		break;
	case SOCK_DGRAM:
		fd->udppcb = udp_new();
		udp_recv(fd->udppcb, recv_udp, (void *)s);
		udp_bind(fd->udppcb, &ip, ntohs(port));
		break;
	default:
		assert( 0 );
		errno = EINVAL;
		rv = -1; goto out;
	}

out:
	mutex_unlock(fd->mutex);
	return rv;
}
PROCESS_THREAD(rs232udp_process, ev, data) {
  PROCESS_BEGIN();

  _network_rs232udp_server_conn = udp_new(NULL, UIP_HTONS(0), NULL);
  udp_bind(_network_rs232udp_server_conn, UIP_HTONS(UDP_PORT));
  
  while (1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
    if(uip_newdata()) {
      uip_ipaddr_copy(&_network_rs232udp_last_ip, &UDP_HDR->srcipaddr);
      _network_rs232udp_last_port = UIP_HTONS(UDP_HDR->srcport);
      
      ((char *)uip_appdata)[uip_datalen()] = 0;
      printf("rs232udp %d.%d.%d.%d:%d rx: '%s'\n",
	     _network_rs232udp_last_ip.u8[0],
	     _network_rs232udp_last_ip.u8[1],
	     _network_rs232udp_last_ip.u8[2],
	     _network_rs232udp_last_ip.u8[3],
	     _network_rs232udp_last_port,
	     (char *)uip_appdata);
      rs232_tx((char *)uip_appdata);
    }
  }

  PROCESS_END();
}
Exemple #20
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_server_process, ev, data)
{

  PROCESS_BEGIN();
  putstring("Starting UDP server\n");

#if BUTTON_SENSOR_ON
  putstring("Button 1: Print RIME stats\n");
#endif

#if SERVER_RPL_ROOT
  create_dag();
#endif

  server_conn = udp_new(NULL, UIP_HTONS(0), NULL);
  udp_bind(server_conn, UIP_HTONS(3000));

  PRINTF("Listen port: 3000, TTL=%u\n", server_conn->ttl);

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
#if (BUTTON_SENSOR_ON && (DEBUG==DEBUG_PRINT))
    } else if(ev == sensors_event && data == &button_sensor) {
        print_stats();
#endif /* BUTTON_SENSOR_ON */
    }
  }

  PROCESS_END();
}
Exemple #21
0
PROCESS_THREAD(rime_udp_process, ev, data)
{
  static uip_ipaddr_t ipaddr;

  PROCESS_BEGIN();

  broadcast_conn = udp_broadcast_new(HTONS(RIME_UDP_PORT), NULL);
  if(broadcast_conn == NULL) {
    PRINTF("rime-udp: Failed to allocate a broadcast connection!\n");
  }

  uip_create_unspecified(&ipaddr);
  unicast_conn = udp_new(&ipaddr, HTONS(RIME_UDP_PORT), NULL);
  if(unicast_conn == NULL) {
    PRINTF("rime-udp: Failed to allocate a unicast connection!\n");
  }

  udp_bind(unicast_conn, HTONS(RIME_UDP_PORT));

  while(1) {
    PROCESS_WAIT_EVENT_UNTIL(ev == tcpip_event);
    if(uip_newdata()) {
      packetbuf_clear();
      memmove(packetbuf_hdrptr(), uip_appdata, uip_datalen());
      PRINTF("rime-udp: received %d bytes\n", uip_datalen());
      receiver_callback(&rime_udp_driver);
    }
  }

  PROCESS_END();
}
Exemple #22
0
/**
  * @brief  Initialize the server application.
  * @param  None
  * @retval None
  */
void server_init(void)
{
  struct tcp_pcb *tpcb;    
	struct udp_pcb *upcb;  	 
 
	/* Create a new TCP control block  */
	tpcb = tcp_new();
	
	/* Assign to the new pcb a local IP address and a port number */
	/* Using IP_ADDR_ANY allow the pcb to be used by any local interface */
	tcp_bind(tpcb, IP_ADDR_ANY, TCP_SERVER_PORT);
	
	/* Set the connection to the LISTEN state */
	tpcb = tcp_listen(tpcb);

	/* Specify the function to be called when a connection is established */	
	tcp_accept(tpcb, tcp_server_accept);	
	
  /* Create a new UDP control block  */
  upcb = udp_new();
  
  /* Bind the upcb to the UDP_PORT port */
  /* Using IP_ADDR_ANY allow the upcb to be used by any local interface */
  udp_bind(upcb, IP_ADDR_ANY, UDP_SERVER_PORT);
  
  /* Set a receive callback for the upcb */
  udp_recv(upcb, udp_server_callback, NULL);  
}
int
start_urxperf_application()
{
	struct udp_pcb *pcb;
	err_t err;
	unsigned port = rxperf_port;	/* iperf default port */

	/* create new TCP PCB structure */
	pcb = udp_new();
	if (!pcb) {
		xil_printf("Error creating PCB. Out of Memory\r\n");
		return -1;
	}

	/* bind to iperf @port */
	err = udp_bind(pcb, IP_ADDR_ANY, port);
	if (err != ERR_OK) {
		xil_printf("Unable to bind to port %d: err = %d\r\n", port, err);
		return -2;
	}

	udp_recv(pcb, urxperf_recv_callback, NULL);

        rxperf_server_running = 1;

	return 0;
}
Exemple #24
0
/**
 * Starts SNMP Agent.
 * Allocates UDP pcb and binds it to IP_ADDR_ANY port 161.
 */
void
snmp_init(void)
{
  struct snmp_msg_pstat *msg_ps;
  u8_t i;

  snmp1_pcb = udp_new();
  if (snmp1_pcb != NULL)
  {
    udp_recv(snmp1_pcb, snmp_recv, (void *)SNMP_IN_PORT);
    udp_bind(snmp1_pcb, IP_ADDR_ANY, SNMP_IN_PORT);
  }
  msg_ps = &msg_input_list[0];
  for (i=0; i<SNMP_CONCURRENT_REQUESTS; i++)
  {
    msg_ps->state = SNMP_MSG_EMPTY;
    msg_ps->error_index = 0;
    msg_ps->error_status = SNMP_ES_NOERROR;
    msg_ps++;
  }
  trap_msg.pcb = snmp1_pcb;
  /* The coldstart trap will only be output
     if our outgoing interface is up & configured  */
  snmp_coldstart_trap();
}
Exemple #25
0
/**
  * @brief  Creates and initializes a UDP PCB for TFTP receive operation  
  * @param  None  
  * @retval None
  */
void IAP_tftpd_init(void)
{
  err_t err;
  unsigned port = 69; /* 69 is the port used for TFTP protocol initial transaction */

  /* create a new UDP PCB structure  */
  UDPpcb = udp_new();
  if (!UDPpcb)
  {
    /* Error creating PCB. Out of Memory  */
#ifdef USE_LCD
    LCD_ErrLog("Can not create pcb \n");
#endif
    return;
  }

  /* Bind this PCB to port 69  */
  err = udp_bind(UDPpcb, IP_ADDR_ANY, port);
  if (err == ERR_OK)
  {
    /* Initialize receive callback function  */
    udp_recv(UDPpcb, IAP_tftp_recv_callback, NULL);
  } 
  else
  {
#ifdef USE_LCD
    LCD_ErrLog("Can not create pcb \n");
#endif
  }
}
/**
  * @brief  Initializes the udp pcb for TFTP 
  * @param  None
  * @retval None
  */
void tftpd_init(void)
{
  err_t err;
  unsigned port = 69;

  /* create a new UDP PCB structure  */
  UDPpcb = udp_new();
  if (UDPpcb)
  {  
    /* Bind this PCB to port 69  */
    err = udp_bind(UDPpcb, IP_ADDR_ANY, port);
    if (err == ERR_OK)
    {    
      /* TFTP server start  */
      udp_recv(UDPpcb, recv_callback_tftp, NULL);
    }
    else
    {
      printf("can not bind pcb");
    }
  }
  else
  {
    printf("can not create new pcb");
  }
}
Exemple #27
0
/*
  netx_udp_open()
    Open a "socket" with a given local port number
    The call returns 0 if OK, non-zero if it fails.
*/
int
netx_udp_open(struct netxsocket_s *rlpsock, localaddr_arg_t localaddr)
{
    struct udp_pcb *netx_pcb;        /* common Protocol Control Block */

    if (rlpsock->nativesock) {
        acnlog(LOG_WARNING | LOG_NETI, "netx_udp_open : already open");
        return -1;
    }

    netx_pcb = udp_new();
    if (!netx_pcb)
        return -1;

    rlpsock->nativesock = netx_pcb;

    /* BIND:sets local_ip and local_port */
    if (!udp_bind(netx_pcb, LCLAD_INADDR(LCLAD_UNARG(localaddr)), LCLAD_PORT(LCLAD_UNARG(localaddr))) == ERR_OK)
        return -1;

    if (LCLAD_PORT(LCLAD_UNARG(localaddr)) == NETI_PORT_EPHEM) {
        /* if port was 0, then the stack should have given us a port, so assign it back */
        NSK_PORT(*rlpsock) = netx_pcb->local_port;
    }  else {
        NSK_PORT(*rlpsock) = LCLAD_PORT(LCLAD_UNARG(localaddr));
    }
#if !CONFIG_LOCALIP_ANY
    NSK_INADDR(rlpsock) = LCLAD_INADDR(LCLAD_UNARG(localaddr));
#endif

    /* UDP Callback */
    udp_recv(netx_pcb, netxhandler, rlpsock);

    return 0;
}
Exemple #28
0
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  static struct etimer periodic;
  static struct ctimer backoff_timer;
#if WITH_COMPOWER
  static int print = 0;
#endif

  PROCESS_BEGIN();

  PROCESS_PAUSE();

  set_global_address();
  
  PRINTF("UDP client process started\n");

  print_local_addresses();

  /* new connection with remote host */
  client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL); 
  if(client_conn == NULL) {
    PRINTF("No UDP connection available, exiting the process!\n");
    PROCESS_EXIT();
  }
  udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT)); 

  PRINTF("Created a connection with the server ");
  PRINT6ADDR(&client_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
  UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

#if WITH_COMPOWER
  powertrace_sniff(POWERTRACE_ON);
#endif

  etimer_set(&periodic, SEND_INTERVAL);
  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
    
    if(etimer_expired(&periodic)) {
      etimer_reset(&periodic);
      ctimer_set(&backoff_timer, SEND_TIME, send_packet, NULL);

#if WITH_COMPOWER
      if (print == 0) {
  powertrace_print("#P");
      }
      if (++print == 3) {
  print = 0;
      }
#endif

    }
  }

  PROCESS_END();
}
/*---------------------------------------------------------------------------*/
PROCESS_THREAD(udp_client_process, ev, data)
{
  PROCESS_BEGIN();

  PROCESS_PAUSE();

  set_global_address();

  PRINTF("UDP client process started\n");

  print_local_addresses();

  /* new connection with remote host */
  client_conn = udp_new(NULL, UIP_HTONS(UDP_SERVER_PORT), NULL);
  udp_bind(client_conn, UIP_HTONS(UDP_CLIENT_PORT));

  PRINTF("Created a connection with the server ");
  PRINT6ADDR(&client_conn->ripaddr);
  PRINTF(" local/remote port %u/%u\n",
        UIP_HTONS(client_conn->lport), UIP_HTONS(client_conn->rport));

  while(1) {
    PROCESS_YIELD();
    if(ev == tcpip_event) {
      tcpip_handler();
    }
  }

  PROCESS_END();
}
Exemple #30
0
/* 
 * FIXME: currently we associate a connection with a thread (and an
 * upcall thread), which is restrictive.
 */
net_connection_t net_create_udp_connection(spdid_t spdid, long evt_id)
{
	struct udp_pcb *up;
	struct intern_connection *ic;
	net_connection_t ret;

	up = udp_new();	
	if (NULL == up) {
		prints("Could not allocate udp connection");
		ret = -ENOMEM;
		goto err;
	}
	ic = net_conn_alloc(UDP, cos_get_thd_id(), evt_id);
	if (NULL == ic) {
		prints("Could not allocate internal connection");
		ret = -ENOMEM;
		goto udp_err;
	}
	ic->spdid = spdid;
	ic->conn.up = up;
	udp_recv(up, cos_net_lwip_udp_recv, (void*)ic);
	return net_conn_get_opaque(ic);
udp_err:
	udp_remove(up);
err:
	return ret;
}