Exemple #1
0
static void cc1101_task(void* param) {
	// Initialize the radio
	cc1101_driver_init();

	// Make sure the semaphore is taken
	xSemaphoreTake(rx_sem, 0);

	// Infinite loop for handling received frames
	while (1) {
		if (xSemaphoreTake(rx_sem, portMAX_DELAY) == pdTRUE) {
			handle_received_frame();
		}
	}
}
Exemple #2
0
static void
handle_frame_received_on_switch_port( buffer *frame, void *user_data ) {
  assert( frame != NULL );
  assert( user_data != NULL );

  switch_port *port = user_data;

  if ( !lock_mutex( &mutex ) ) {
    return;
  }

  if ( ( port->config & ( OFPPC_PORT_DOWN | OFPPC_NO_RECV ) ) != 0 ) {
    unlock_mutex( &mutex );
    return;
  }

  if ( frame->length + ETH_FCS_LENGTH < ETH_MINIMUM_LENGTH ) {
    fill_ether_padding( frame );
  }

  handle_received_frame( port, frame );

  unlock_mutex( &mutex );
}
Exemple #3
0
OFDPE
send_frame_from_switch_port( const uint32_t port_no, buffer *frame ) {
  assert( port_no > 0 );
  assert( frame != NULL );
 
  if ( port_no == OFPP_NORMAL || port_no == OFPP_CONTROLLER || port_no == OFPP_LOCAL || port_no == OFPP_ANY ) {
    error( "Invalid output port number ( port_no = %u, frame = %p ).", port_no, frame );
    return OFDPE_FAILED;
  }

  if ( frame->length + ETH_FCS_LENGTH < ETH_MINIMUM_LENGTH ) {
    fill_ether_padding( frame );
  }

  uint32_t in_port = 0;
  if ( port_no == OFPP_ALL || port_no == OFPP_FLOOD || port_no == OFPP_IN_PORT || port_no == OFPP_TABLE ) {
    if ( frame->user_data == NULL ) {
      warn( "Ethernet frame is not parsed yet. OFPP_ALL, OFPP_FLOOD, OFPP_IN_PORT, and OFPP_TABLE "
            "require eth_in_port to find actual output ports ( port_no = %u, frame = %p ).", port_no, frame );
      return OFDPE_FAILED;
    }
    in_port = ( ( packet_info * ) frame->user_data )->eth_in_port;
    if ( in_port == 0 || ( in_port > OFPP_MAX && in_port != OFPP_CONTROLLER ) ) {
      warn( "Invalid eth_in_port found in a parsed frame ( frame = %p, eth_in_port = %u ).", frame, in_port );
      return OFDPE_FAILED;
    }
  }

  if ( !lock_mutex( &mutex ) ) {
    return ERROR_LOCK;
  }

  OFDPE ret = OFDPE_SUCCESS;
  if ( port_no != OFPP_TABLE ) {
    list_element *ports = get_switch_ports_to_output( port_no, in_port );
    for ( list_element *e = ports; e != NULL;  e = e->next ) {
      assert( e->data != NULL );
      switch_port *port = e->data;
      if ( ( port->config & ( OFPPC_PORT_DOWN | OFPPC_NO_FWD ) ) != 0 ) {
        continue;
      }
      assert( port->device != NULL );
      send_frame( port->device, frame );
    }

    if ( ports != NULL ) {
      delete_list( ports );
    }
  }
  else {
    if ( in_port != OFPP_CONTROLLER ) {
      switch_port *port = lookup_switch_port( in_port );
      if ( port != NULL ) {
        handle_received_frame( port, frame );
      }
      else {
        ret = OFDPE_FAILED;
      }
    }
    else {
      warn( "Packet-out with in_port = OFPP_CONTROLLER is not supported." );
      ret = OFDPE_FAILED;
    }
  }

  if ( !unlock_mutex( &mutex ) ) {
    return ERROR_UNLOCK;
  }

  return ret;
}