Example #1
0
int novacom_usb_transport_start(void)
{
	novacom_shutdown = 0;
	platform_create_thread(&findandattach_thread, &novacom_usb_findandattach_thread, NULL);
	platform_mutex_init(&recovery_lock);
	return 0;
}
Example #2
0
int init_mdns_socket(void)
{
	int err;
	struct sockaddr_in bindaddr;

	// Create the MDNS socket
	mdns_socket = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
	if (mdns_socket == -1)
	{
		printf("Failed to create socket (Error: %d)\n", platform_last_error());
		return -1;
	}

	// Bind to the relay port
	memset(&bindaddr, 0, sizeof(bindaddr));
	bindaddr.sin_family = AF_INET;
	bindaddr.sin_port = htons(MDNS_RELAY_PORT);
	bindaddr.sin_addr.S_un.S_addr = htonl(INADDR_ANY);

	// Bind to the MDNS port on all interfaces
	err = bind(mdns_socket, (struct sockaddr*)&bindaddr, sizeof(bindaddr));
	if (err != 0)
	{
		printf("Failed to bind socket (Error: %d)\n", platform_last_error());
		closesocket(mdns_socket);
		return -1;
	}

	// Initialize IP table mutex
	platform_mutex_init(&iface_table_mutex);

	// Load initial IP table
	err = refresh_ip_table();
	if (err != 0)
	{
		printf("Failed to load initial IP table\n");
		closesocket(mdns_socket);
		return -1;
	}

	// Join the multicast group using the IP table
	err = join_multicast_group();
	if (err != 0)
	{
		printf("Failed to join multicast group\n");
		closesocket(mdns_socket);
		return -1;
	}
	
	return 0;
}
Example #3
0
//Init
rofl_result_t physical_switch_init(){

	ROFL_PIPELINE_DEBUG("Initializing physical switch\n");

	//Allocate memory for the physical switch structure
	psw = platform_malloc_shared(sizeof(physical_switch_t));
	
	if( unlikely(psw==NULL) )
		return ROFL_FAILURE;	
	
	psw->mutex = platform_mutex_init(NULL);
	if(!psw->mutex)
		return ROFL_FAILURE;
	
	platform_memset(psw->logical_switches, 0, sizeof(psw->logical_switches));
	psw->num_of_logical_switches = 0;	

	platform_memset(psw->physical_ports, 0, sizeof(psw->physical_ports));
	platform_memset(psw->tunnel_ports, 0, sizeof(psw->tunnel_ports));
	platform_memset(psw->virtual_ports, 0, sizeof(psw->virtual_ports));
	platform_memset(psw->meta_ports, 0, sizeof(psw->meta_ports));
	
	//Generate metaports
	//Flood
	psw->meta_ports[META_PORT_FLOOD_INDEX].type = PORT_TYPE_META_FLOOD;
	strncpy(psw->meta_ports[META_PORT_FLOOD_INDEX].name, "Flood meta port", SWITCH_PORT_MAX_LEN_NAME);
	//In port
	psw->meta_ports[META_PORT_IN_PORT_INDEX].type = PORT_TYPE_META_IN_PORT;
	strncpy(psw->meta_ports[META_PORT_IN_PORT_INDEX].name, "In port meta port", SWITCH_PORT_MAX_LEN_NAME);
	//All
	psw->meta_ports[META_PORT_ALL_INDEX].type = PORT_TYPE_META_ALL;
	strncpy(psw->meta_ports[META_PORT_ALL_INDEX].name, "All meta port", SWITCH_PORT_MAX_LEN_NAME);

	//Set extern pointer
	flood_meta_port = &psw->meta_ports[META_PORT_FLOOD_INDEX];
	in_port_meta_port = &psw->meta_ports[META_PORT_IN_PORT_INDEX];
	all_meta_port = &psw->meta_ports[META_PORT_ALL_INDEX];

	//Initialize monitoring data
	if(__monitoring_init(&psw->monitoring) != ROFL_SUCCESS)
		return ROFL_FAILURE;		

	//Generate matching algorithm lists
	__physical_switch_generate_matching_algorithm_list();

	return ROFL_SUCCESS;	
}
Example #4
0
void MQTTClientInit(MQTTClient* c, Network* network, unsigned int command_timeout_ms,
		unsigned char* sendbuf, size_t sendbuf_size, unsigned char* readbuf, size_t readbuf_size)
{
    c->ipstack = network;
    
    c->command_timeout_ms = command_timeout_ms;
    c->buf = sendbuf;
    c->buf_size = sendbuf_size;
    c->readbuf = readbuf;
    c->readbuf_size = readbuf_size;
    c->isconnected = 0;
    c->ping_outstanding = 0;
    c->messageHandler = 0;
    c->messageHandlerData = 0;
	c->next_packetid = 1;

    platform_timer_init(&c->ping_timer);
    platform_timer_init(&c->pingresp_timer);
	platform_mutex_init(&c->mutex);
}
Example #5
0
/*
 * usbrecords_init
 * init records
 * @ret 0 - success, -1 error
 */
int usbrecords_init( void )
{
	TAILQ_INIT(&t_recovery_queue);	/* initialize records queue */
	platform_mutex_init(&recovery_lock); /* initialize mutex */
	return 0;
}
Example #6
0
/* Initalizer. Table struct has been allocated by pipeline initializer. */
rofl_result_t __of1x_init_table(struct of1x_pipeline* pipeline, of1x_flow_table_t* table, const unsigned int table_index, const enum of1x_matching_algorithm_available algorithm){

	//Safety checks
	if( unlikely(pipeline==NULL) || unlikely(table==NULL) )
		return ROFL_FAILURE;	

	//Initializing mutexes
	table->mutex = platform_mutex_init(NULL);
	if( unlikely(NULL==table->mutex) )
		return ROFL_FAILURE;
	table->rwlock = platform_rwlock_init(NULL);
	if( unlikely(NULL==table->rwlock) )
		return ROFL_FAILURE;
	
	table->pipeline = pipeline;
	table->number = table_index;
	table->entries = NULL;
	table->num_of_entries = 0;
	table->max_entries = OF1X_MAX_NUMBER_OF_TABLE_ENTRIES;

	//Set name
	snprintf(table->name, OF1X_MAX_TABLE_NAME_LEN, "table%u", table_index);
	
	//Setting up the matching algorithm	
	if(! (algorithm < of1x_matching_algorithm_count)){
		platform_mutex_destroy(table->mutex);
		platform_rwlock_destroy(table->rwlock);
		return ROFL_FAILURE;
	}

	//Set algorithm
	table->matching_algorithm = algorithm;

	//Auxiliary matching algorithm structs 
	table->matching_aux[0] = NULL; 
	table->matching_aux[1] = NULL;

	//Initializing timers. NOTE does that need to be done here or somewhere else?
#if OF1X_TIMER_STATIC_ALLOCATION_SLOTS
	__of1x_timer_group_static_init(table);
#else
	table->timers = NULL;
#endif

	switch(pipeline->sw->of_ver){
		case OF_VERSION_10:
			__of10_set_table_defaults(table);
			break; 
		case OF_VERSION_12:
			__of12_set_table_defaults(table);
			break; 
		case OF_VERSION_13:
			__of13_set_table_defaults(table);
			break; 
		default:
			platform_mutex_destroy(table->mutex);
			platform_rwlock_destroy(table->rwlock);
			return ROFL_FAILURE;
	}

	//Init stats
	__of1x_stats_table_init(table);

	//Allow matching algorithms to do stuff	
	if(of1x_matching_algorithms[table->matching_algorithm].init_hook)
		return of1x_matching_algorithms[table->matching_algorithm].init_hook(table);
	
	return ROFL_SUCCESS;
}