コード例 #1
0
ファイル: lapbether.c プロジェクト: dmgerman/original
/*
 * open/close a device
 */
static int lapbeth_open(struct net_device *dev)
{
	struct lapb_register_struct lapbeth_callbacks;
	struct lapbethdev *lapbeth;
	int err;

	if (lapbeth_check_devices(dev))
		return -ENODEV;		/* oops, it's gone */
	
	lapbeth = (struct lapbethdev *)dev->priv;

	lapbeth_callbacks.connect_confirmation    = lapbeth_connected;
	lapbeth_callbacks.connect_indication      = lapbeth_connected;
	lapbeth_callbacks.disconnect_confirmation = lapbeth_disconnected;
	lapbeth_callbacks.disconnect_indication   = lapbeth_disconnected;
	lapbeth_callbacks.data_indication         = lapbeth_data_indication;
	lapbeth_callbacks.data_transmit           = lapbeth_data_transmit;

	if ((err = lapb_register(lapbeth, &lapbeth_callbacks)) != LAPB_OK) {
		printk(KERN_ERR "lapbeth: lapb_register error - %d\n", err);
		return -ENODEV;
	}

	MOD_INC_USE_COUNT;
	netif_start_queue(dev);

	return 0;
}
コード例 #2
0
static int x25_asy_open(struct net_device *dev)
{
	struct lapb_register_struct x25_asy_callbacks;
	struct x25_asy *sl = (struct x25_asy*)(dev->priv);
	unsigned long len;
	int err;

	if (sl->tty == NULL)
		return -ENODEV;

	/*
	 * Allocate the X.25 frame buffers:
	 *
	 * rbuff	Receive buffer.
	 * xbuff	Transmit buffer.
	 */

	len = dev->mtu * 2;

	sl->rbuff = (unsigned char *) kmalloc(len + 4, GFP_KERNEL);
	if (sl->rbuff == NULL)   {
		goto norbuff;
	}
	sl->xbuff = (unsigned char *) kmalloc(len + 4, GFP_KERNEL);
	if (sl->xbuff == NULL)   {
		goto noxbuff;
	}
	sl->mtu	     = dev->mtu;
	sl->buffsize = len;
	sl->rcount   = 0;
	sl->xleft    = 0;
	sl->flags   &= (1 << SLF_INUSE);      /* Clear ESCAPE & ERROR flags */

	netif_start_queue(dev);
			
	/*
	 *	Now attach LAPB
	 */
	 
	x25_asy_callbacks.connect_confirmation=x25_asy_connected;
	x25_asy_callbacks.connect_indication=x25_asy_connected;
	x25_asy_callbacks.disconnect_confirmation=x25_asy_disconnected;
	x25_asy_callbacks.disconnect_indication=x25_asy_disconnected;
	x25_asy_callbacks.data_indication=x25_asy_data_indication;
	x25_asy_callbacks.data_transmit=x25_asy_data_transmit;

	if((err=lapb_register(sl, &x25_asy_callbacks))==LAPB_OK)
		return 0;

	/* Cleanup */
	kfree(sl->xbuff);
noxbuff:
	kfree(sl->rbuff);
norbuff:
	return -ENOMEM;
}
コード例 #3
0
static int comxlapb_init(struct net_device *dev)
{
	struct comx_channel *ch = dev->priv;
	struct lapb_register_struct lapbreg;

	dev->mtu		= 1500;
	dev->hard_header_len    = 4;
	dev->addr_len		= 0;

	ch->LINE_rx	= comxlapb_rx;
	ch->LINE_tx	= comxlapb_tx;
	ch->LINE_status = comxlapb_status;
	ch->LINE_open	= comxlapb_open;
	ch->LINE_close	= comxlapb_close;
	ch->LINE_xmit	= comxlapb_xmit;
	ch->LINE_header	= comxlapb_header;
	ch->LINE_statistics = comxlapb_statistics;

	lapbreg.connect_confirmation = comxlapb_connected;
	lapbreg.connect_indication = comxlapb_connected;
	lapbreg.disconnect_confirmation = comxlapb_disconnected;
	lapbreg.disconnect_indication = comxlapb_disconnected;
	lapbreg.data_indication = comxlapb_data_indication;
	lapbreg.data_transmit = comxlapb_data_transmit;
	if (lapb_register(dev->priv, &lapbreg)) {
		return -ENOMEM;
	}
	if (ch->debug_flags & DEBUG_COMX_LAPB) {
		comx_debug(dev, "%s: lapb registered\n", dev->name);
	}

	if (!create_comxlapb_proc_entry(FILENAME_T1, 0644, 8, ch->procdir)) {
		return -ENOMEM;
	}
	if (!create_comxlapb_proc_entry(FILENAME_T2, 0644, 8, ch->procdir)) {
		return -ENOMEM;
	}
	if (!create_comxlapb_proc_entry(FILENAME_N2, 0644, 8, ch->procdir)) {
		return -ENOMEM;
	}
	if (!create_comxlapb_proc_entry(FILENAME_MODE, 0644, 14, ch->procdir)) {
		return -ENOMEM;
	}
	if (!create_comxlapb_proc_entry(FILENAME_WINDOW, 0644, 0, ch->procdir)) {
		return -ENOMEM;
	}

	MOD_INC_USE_COUNT;
	return 0;
}
コード例 #4
0
ファイル: hdlc_x25.c プロジェクト: 119-org/hi3518-osdrv
static int x25_open(struct net_device *dev)
{
	struct lapb_register_struct cb;
	int result;

	cb.connect_confirmation = x25_connected;
	cb.connect_indication = x25_connected;
	cb.disconnect_confirmation = x25_disconnected;
	cb.disconnect_indication = x25_disconnected;
	cb.data_indication = x25_data_indication;
	cb.data_transmit = x25_data_transmit;

	result = lapb_register(dev, &cb);
	if (result != LAPB_OK)
		return result;
	return 0;
}
コード例 #5
0
ファイル: x25_asy.c プロジェクト: Lyude/linux
/* Open the low-level part of the X.25 channel. Easy! */
static int x25_asy_open(struct net_device *dev)
{
	struct x25_asy *sl = netdev_priv(dev);
	unsigned long len;
	int err;

	if (sl->tty == NULL)
		return -ENODEV;

	/*
	 * Allocate the X.25 frame buffers:
	 *
	 * rbuff	Receive buffer.
	 * xbuff	Transmit buffer.
	 */

	len = dev->mtu * 2;

	sl->rbuff = kmalloc(len + 4, GFP_KERNEL);
	if (sl->rbuff == NULL)
		goto norbuff;
	sl->xbuff = kmalloc(len + 4, GFP_KERNEL);
	if (sl->xbuff == NULL)
		goto noxbuff;

	sl->buffsize = len;
	sl->rcount   = 0;
	sl->xleft    = 0;
	sl->flags   &= (1 << SLF_INUSE);      /* Clear ESCAPE & ERROR flags */

	netif_start_queue(dev);

	/*
	 *	Now attach LAPB
	 */
	err = lapb_register(dev, &x25_asy_callbacks);
	if (err == LAPB_OK)
		return 0;

	/* Cleanup */
	kfree(sl->xbuff);
noxbuff:
	kfree(sl->rbuff);
norbuff:
	return -ENOMEM;
}
コード例 #6
0
static int x25_asy_open(struct net_device *dev)
{
	struct x25_asy *sl = netdev_priv(dev);
	unsigned long len;
	int err;

	if (sl->tty == NULL)
		return -ENODEV;

	/*
                                    
   
                         
                          
  */

	len = dev->mtu * 2;

	sl->rbuff = kmalloc(len + 4, GFP_KERNEL);
	if (sl->rbuff == NULL)
		goto norbuff;
	sl->xbuff = kmalloc(len + 4, GFP_KERNEL);
	if (sl->xbuff == NULL)
		goto noxbuff;

	sl->buffsize = len;
	sl->rcount   = 0;
	sl->xleft    = 0;
	sl->flags   &= (1 << SLF_INUSE);      /*                            */

	netif_start_queue(dev);

	/*
                   
  */
	err = lapb_register(dev, &x25_asy_callbacks);
	if (err == LAPB_OK)
		return 0;

	/*         */
	kfree(sl->xbuff);
noxbuff:
	kfree(sl->rbuff);
norbuff:
	return -ENOMEM;
}
コード例 #7
0
ファイル: server_main.c プロジェクト: SergeAvdeyev/my_project
int manual_process() {
	struct lapb_callbacks callbacks;
	int lapb_res;

	fd_set			read_set;
	struct timeval	timeout;
	int sr = 0;

	char buffer[4];

	/* LAPB init */
	bzero(&callbacks, sizeof(struct lapb_callbacks));
	callbacks.transmit_data = transmit_data;
	callbacks.debug = lapb_debug;
	lapb_res = lapb_register(&callbacks, NULL, &lapb_server);
	if (lapb_res != LAPB_OK) {
		printf("lapb_register return %d\n", lapb_res);
		exit(EXIT_FAILURE);
	};
	//lapb_server->mode = LAPB_DCE;

	print_man_commands();

	while (!exit_flag) {
		FD_ZERO(&read_set);
		FD_SET(fileno(stdin), &read_set);
		timeout.tv_sec  = 0;
		timeout.tv_usec = 100000;
		sr = select(fileno(stdin) + 1, &read_set, NULL, NULL, &timeout);
		if (sr > 0) {
			bzero(buffer, sizeof(buffer));
			while (read(0, buffer, sizeof(buffer)) <= 1)
				write(0, ">", 1);
			//printf("\n");
			int action = atoi(buffer);
			switch (action) {
				case 1: /* SABM */
					//lapb_send_control(lapb_server, LAPB_SABM, LAPB_POLLON, LAPB_COMMAND);
					//
					break;
				case 2: /* SABME */
					//lapb_send_control(lapb_server, LAPB_SABME, LAPB_POLLON, LAPB_COMMAND);
					//
					break;
				case 3: /* DISC */
					//lapb_send_control(lapb_server, LAPB_DISC, LAPB_POLLON, LAPB_COMMAND);
					//
					break;
				case 4: /* UA */
					//lapb_send_control(lapb_server, LAPB_UA, LAPB_POLLON, LAPB_RESPONSE);
					//
					break;
				case 5: /* DM */
					//lapb_send_control(lapb_server, LAPB_DM, LAPB_POLLON, LAPB_RESPONSE);
					//
					break;
				case 6: /* RR good*/
					//lapb_send_control(lapb_server, LAPB_RR, LAPB_POLLON, LAPB_RESPONSE);
					//
					break;
				case 7: /* RR bad*/
					//lapb_server->vr++;
					//lapb_send_control(lapb_server, LAPB_RR, LAPB_POLLON, LAPB_RESPONSE);
					//
					break;
				case 0:
					exit_flag = TRUE;
					break;
				default:
					printf("Command is not supported\n\n");
					break;
			};
		};

	};


	lapb_unregister(lapb_server);

	return EXIT_SUCCESS;
}
コード例 #8
0
ファイル: server_main.c プロジェクト: SergeAvdeyev/my_project
int main (int argc, char *argv[]) {
	(void)argc;
	(void)argv;
	int ret;
	int dbg = TRUE;

	struct lapb_callbacks callbacks;
	int lapb_res;

	char buffer[2048];

	unsigned char lapb_equipment_type = LAPB_DCE;
	unsigned char lapb_modulo = LAPB_STANDARD;

	pthread_t server_thread;
	struct tcp_server_struct * server_struct = NULL;

	pthread_t timer_thread;
	struct timer_thread_struct * timer_struct = NULL;

	pthread_t logger_thread;

	printf("*******************************************\n");
	printf("******                               ******\n");
	printf("******  LAPB EMULATOR (server side)  ******\n");
	printf("******                               ******\n");
	printf("*******************************************\n");

	/* Initialize syslog */
	setlogmask (LOG_UPTO (LOG_DEBUG));
	openlog ("server_app", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);

	ret = pthread_create(&logger_thread, NULL, logger_function, NULL);
	if (ret) {
		perror("Error - pthread_create()");
		closelog();
		exit(EXIT_FAILURE);
	};
	printf("Logger thread created(code %d)\n", ret);
	while (!is_logger_started())
		sleep_ms(200);
	printf("Logger started\n\n");

	lapb_debug(0, "Program started by User %d", getuid ());

	/* Setup signal handler */
	setup_signals_handler();

	if (dbg)
		goto label_1;

	/* Select program mode */
	printf("\nSelect program mode:\n1. Automatic\n2. Manual\n");
	write(0, ">", 1);
	while (read(0, buffer, sizeof(buffer)) <= 1)
		write(0, ">", 1);
	if (atoi(buffer) == 2)
		AutomaticMode = FALSE;
	else {
		/* Set up equipment mode: DTE or DCE */
		printf("\nSelect equipment type:\n1. DTE\n2. DCE\n");
		write(0, ">", 1);
		while (read(0, buffer, sizeof(buffer)) <= 1)
			write(0, ">", 1);
		if (atoi(buffer) == 1)
			lapb_equipment_type = LAPB_DTE;

		/* Set up lapb modulo: STANDARD or EXTENDED */
		printf("\nSelect modulo value:\n1. STANDARD(8)\n2. EXTENDED(128)\n");
		write(0, ">", 1);
		while (read(0, buffer, sizeof(buffer)) <= 1)
			write(0, ">", 1);
		if (atoi(buffer) == 2)
			lapb_modulo = LAPB_EXTENDED;
	};

label_1:

	/* Create TCP server */
	server_struct = malloc(sizeof(struct tcp_server_struct));

	if (dbg) {
		server_struct->port = 1234;
		goto label_2;
	};

	printf("\nEnter server port[1234]: ");
	fgets(buffer, sizeof(buffer) - 1, stdin);
	int tmp_len = strlen(buffer);
	if (tmp_len == 1)
		server_struct->port = 1234;
	else {
		buffer[strlen(buffer) - 1] = 0;
		server_struct->port = atoi(buffer);
	};

label_2:

	/* TCP server callbacks */
	server_struct->new_data_received = new_data_received;
	server_struct->no_active_connection = no_active_connection;

	ret = pthread_create(&server_thread, NULL, server_function, (void*)server_struct);
	if (ret) {
		fprintf(stderr, "Error - pthread_create() return code: %d\n", ret);
		exit(EXIT_FAILURE);
	};
	printf("TCP server thread created(code %d)\n", ret);
	while (!is_server_started())
		sleep_ms(200);
	printf("TCP server started\n\n");

	if (!AutomaticMode)
		return manual_process();

	/* Create timer */
	timer_struct = malloc(sizeof(struct timer_thread_struct));
	timer_struct->interval = 10; /* milliseconds */
	//bzero(timer_struct->timers_list, sizeof(timer_struct->timers_list));
	ret = pthread_create(&timer_thread, NULL, timer_thread_function, (void*)timer_struct);
	if (ret) {
		lapb_debug(0, "Error - pthread_create() return code: %d\n", ret);
		closelog();
		exit(EXIT_FAILURE);
	};
	printf("Timer thread created(code %d)\n", ret);
	while (!is_timer_thread_started())
		sleep_ms(200);
	printf("Timer started\n\n");


	/* LAPB init */
	bzero(&callbacks, sizeof(struct lapb_callbacks));
	callbacks.connect_confirmation = connect_confirmation;
	callbacks.connect_indication = connect_indication;
	callbacks.disconnect_confirmation = disconnect_confirmation;
	callbacks.disconnect_indication = disconnect_indication;
	callbacks.data_indication = data_indication;
	callbacks.transmit_data = transmit_data;

	callbacks.add_timer = timer_add;
	callbacks.del_timer = timer_del;
	callbacks.start_timer = timer_start;
	callbacks.stop_timer = timer_stop;

	callbacks.debug = lapb_debug;

	/* Define LAPB values */
	struct lapb_params params;
	params.mode = lapb_modulo | LAPB_SLP | lapb_equipment_type;
	params.window = LAPB_DEFAULT_SWINDOW;
	params.N1 = LAPB_DEFAULT_N1;	/* I frame size is 135 bytes */
	params.T201_interval = 1000;	/* 1s */
	params.T202_interval = 100;		/* 0.1s */
	params.N201 = 10;					/* T201 timer will repeat for 10 times */
	params.low_order_bits = FALSE;
	params.auto_connecting = TRUE;

	lapb_res = lapb_register(&callbacks, &params, &lapb_server);
	if (lapb_res != LAPB_OK) {
		printf("lapb_register return %d\n", lapb_res);
		exit(EXIT_FAILURE);
	};
	//lapb_server->mode = lapb_modulo | LAPB_SLP | lapb_equipment_type;

	/* Redefine some default values */
	lapb_server->T201_interval = 1000; /* 1s */
	lapb_server->T202_interval = 100;  /* 0.5s */
	lapb_server->N201 = 10;	/* Try 10 times */
	//lapb_server->low_order_bits = TRUE;

	/* Start endless loop */
	printf("Run Main loop\n\n");
	main_loop(lapb_server);

	printf("Main loop ended\n");

	terminate_tcp_server();
	while (is_server_started())
		sleep_ms(200);
	printf("TCP server stopped\n");
	int * thread_result;
	pthread_join(server_thread, (void **)&thread_result);
	printf("TCP server thread exit(code %d)\n", *thread_result);
	free(thread_result);
	if (server_struct != NULL)
		free(server_struct);

	terminate_timer_thread();
	while (is_timer_thread_started())
		sleep_ms(200);
	printf("Timer stopped\n");
	pthread_join(timer_thread, (void **)&thread_result);
	printf("Timer thread exit(code %d)\n", *thread_result);
	free(thread_result);
	if (timer_struct != NULL)
		free(timer_struct);

	lapb_unregister(lapb_server);

	terminate_logger();
	while (is_logger_started())
		sleep_ms(200);
	printf("Logger stopped\n");
	pthread_join(logger_thread, (void **)&thread_result);
	printf("Logger thread exit(code %d)\n", *thread_result);
	free(thread_result);


	/* Close syslog */
	closelog();
	printf("Exit application\n\n");
	return EXIT_SUCCESS;
}
コード例 #9
0
ファイル: server_main.c プロジェクト: SergeAvdeyev/my_project
int main (int argc, char *argv[]) {
	(void)argc;
	(void)argv;
	int ret;
	int dbg = TRUE;

	struct lapb_callbacks lapb_callbacks;
	int res;

	char buffer[2048];

	_uchar lapb_equipment_type = LAPB_DCE;
	_uchar lapb_modulo = LAPB_STANDARD;

	pthread_t server_thread;
	struct tcp_server_struct * server_thread_struct = NULL;

	pthread_t timer_thread;
	struct timer_thread_struct * timer_thread_struct = NULL;

	pthread_t logger_thread;

	printf("*******************************************\n");
	printf("******                               ******\n");
	printf("******  X25 EMULATOR (server side)  ******\n");
	printf("******                               ******\n");
	printf("*******************************************\n");

	/* Initialize syslog */
	setlogmask (LOG_UPTO (LOG_DEBUG));
	openlog ("server_app", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_LOCAL1);

	ret = pthread_create(&logger_thread, NULL, logger_function, NULL);
	if (ret) {
		perror("Error - pthread_create()");
		closelog();
		exit(EXIT_FAILURE);
	};
	printf("Logger thread created(code %d)\n", ret);
	while (!is_logger_started())
		sleep_ms(200);
	printf("Logger started\n\n");

	lapb_debug(0, "Program started by User %d", getuid ());

	/* Setup signal handler */
	setup_signals_handler();

	if (dbg)
		goto label_1;

	/* Select program mode */
	printf("\nSelect program mode:\n1. Automatic\n2. Manual\n");
	write(0, ">", 1);
	while (read(0, buffer, sizeof(buffer)) <= 1)
		write(0, ">", 1);
	if (atoi(buffer) == 2)
		AutomaticMode = FALSE;
	else {
		/* Set up equipment mode: DTE or DCE */
		printf("\nSelect equipment type:\n1. DTE\n2. DCE\n");
		write(0, ">", 1);
		while (read(0, buffer, sizeof(buffer)) <= 1)
			write(0, ">", 1);
		if (atoi(buffer) == 1)
			lapb_equipment_type = LAPB_DTE;

		/* Set up lapb modulo: STANDARD or EXTENDED */
		printf("\nSelect modulo value:\n1. STANDARD(8)\n2. EXTENDED(128)\n");
		write(0, ">", 1);
		while (read(0, buffer, sizeof(buffer)) <= 1)
			write(0, ">", 1);
		if (atoi(buffer) == 2)
			lapb_modulo = LAPB_EXTENDED;
	};

label_1:

	/* Create TCP server */
	server_thread_struct = malloc(sizeof(struct tcp_server_struct));

	if (dbg) {
		server_thread_struct->port = 1234;
		goto label_2;
	};

	printf("\nEnter server port[1234]: ");
	fgets(buffer, sizeof(buffer) - 1, stdin);
	int tmp_len = strlen(buffer);
	if (tmp_len == 1)
		server_thread_struct->port = 1234;
	else {
		buffer[strlen(buffer) - 1] = 0;
		server_thread_struct->port = atoi(buffer);
	};

label_2:

	/* TCP server callbacks */
	server_thread_struct->new_data_received = new_data_received;
	server_thread_struct->no_active_connection = no_active_connection;

	ret = pthread_create(&server_thread, NULL, server_function, (void*)server_thread_struct);
	if (ret) {
		fprintf(stderr, "Error - pthread_create() return code: %d\n", ret);
		exit(EXIT_FAILURE);
	};
	printf("TCP server thread created(code %d)\n", ret);
	while (!is_server_started())
		sleep_ms(200);
	printf("TCP server started\n\n");

//	if (!AutomaticMode)
//		return manual_process();

	/* Create timer */
	timer_thread_struct = malloc(sizeof(struct timer_thread_struct));
	timer_thread_struct->interval = 10; /* milliseconds */
	timer_thread_struct->main_lock = main_lock;
	timer_thread_struct->main_unlock = main_unlock;
	ret = pthread_create(&timer_thread, NULL, timer_thread_function, (void*)timer_thread_struct);
	if (ret) {
		lapb_debug(0, "Error - pthread_create() return code: %d\n", ret);
		closelog();
		exit(EXIT_FAILURE);
	};
	printf("Timer thread created(code %d)\n", ret);
	while (!is_timer_thread_started())
		sleep_ms(200);
	printf("Timer started\n\n");


	/* LAPB init */
	bzero(&lapb_callbacks, sizeof(struct lapb_callbacks));
	lapb_callbacks.connect_confirmation = lapb_connect_confirmation_cb;
	lapb_callbacks.connect_indication = lapb_connect_indication_cb;
	lapb_callbacks.disconnect_confirmation = lapb_disconnect_confirmation_cb;
	lapb_callbacks.disconnect_indication = lapb_disconnect_indication_cb;
	lapb_callbacks.data_indication = lapb_data_indication_cb;
	lapb_callbacks.transmit_data = lapb_transmit_data;

	lapb_callbacks.add_timer = timer_add;
	lapb_callbacks.del_timer = timer_del;
	lapb_callbacks.start_timer = timer_start;
	lapb_callbacks.stop_timer = timer_stop;

	lapb_callbacks.debug = lapb_debug;

	/* Define LAPB values */
	struct lapb_params lapb_params;
	lapb_params.mode = lapb_modulo | LAPB_SLP | lapb_equipment_type;
	lapb_params.window = LAPB_DEFAULT_SWINDOW;
	lapb_params.N1 = LAPB_DEFAULT_N1;		/* I frame size is 135 bytes */
	lapb_params.T201_interval = 1000;		/* 1s */
	lapb_params.T202_interval = 100;		/* 0.1s */
	lapb_params.N201 = 10;					/* T201 timer will repeat for 10 times */
	lapb_params.low_order_bits = FALSE;
	lapb_params.auto_connecting = TRUE;

	res = lapb_register(&lapb_callbacks, &lapb_params, &lapb_server);
	if (res != LAPB_OK) {
		printf("lapb_register return %d\n", res);
		exit(EXIT_FAILURE);
	};




	/* X25 init */
	struct x25_callbacks x25_callbacks;
	bzero(&x25_callbacks, sizeof(struct x25_callbacks));
	x25_callbacks.link_connect_request = lapb_connect_request;
	x25_callbacks.link_disconnect_request = lapb_disconnect_request;
	x25_callbacks.link_send_frame = lapb_data_request;

	x25_callbacks.call_indication = x25_call_indication_cb;
	x25_callbacks.call_accepted = x25_call_accepted_cb;
	x25_callbacks.data_indication = x25_data_indication_cb;

	x25_callbacks.add_timer = timer_add;
	x25_callbacks.del_timer = timer_del;
	x25_callbacks.start_timer = timer_start;
	x25_callbacks.stop_timer = timer_stop;

	x25_callbacks.debug = x25_debug;

	/* Define X25 values */
	//struct x25_params x25_params;

	//res = x25_register(&x25_callbacks, &x25_params, &x25_server);
	res = x25_register(&x25_callbacks, NULL, &x25_server);
	if (res != X25_OK) {
		printf("x25_register return %d\n", res);
		goto exit;
	};
	x25_server->mode = (lapb_equipment_type & LAPB_DCE ? X25_DCE : X25_DTE) | (lapb_modulo & LAPB_EXTENDED ? X25_EXTENDED : X25_STANDARD);
	x25_add_link(x25_server, lapb_server);
	lapb_server->L3_ptr = x25_server;

	printf("Enter local X25 address[7654321]: ");
	fgets(x25_server->source_addr.x25_addr, 16, stdin);
	tmp_len = strlen(x25_server->source_addr.x25_addr);
	if (tmp_len == 1)
		sprintf(x25_server->source_addr.x25_addr, "7654321");
	else
		x25_server->source_addr.x25_addr[tmp_len - 1] = 0;

	struct x25_address dest_addr;
	sprintf(dest_addr.x25_addr, "1234567");

	x25_server->lci = 128;

	x25_debug(0, "[X25]");
	x25_debug(0, "[X25]");
	x25_debug(0, "[X25]");

	/* Start endless loop */
	printf("Run Main loop\n\n");
	main_loop(x25_server, &dest_addr);

	printf("Main loop ended\n");

exit:
	terminate_tcp_server();
	while (is_server_started())
		sleep_ms(200);
	printf("TCP server stopped\n");
	int * thread_result;
	pthread_join(server_thread, (void **)&thread_result);
	printf("TCP server thread exit(code %d)\n", *thread_result);
	free(thread_result);
	if (server_thread_struct != NULL)
		free(server_thread_struct);

	terminate_timer_thread();
	while (is_timer_thread_started())
		sleep_ms(200);
	printf("Timer stopped\n");
	pthread_join(timer_thread, (void **)&thread_result);
	printf("Timer thread exit(code %d)\n", *thread_result);
	free(thread_result);
	if (timer_thread_struct != NULL)
		free(timer_thread_struct);

	lapb_unregister(lapb_server);

	terminate_logger();
	while (is_logger_started())
		sleep_ms(200);
	printf("Logger stopped\n");
	pthread_join(logger_thread, (void **)&thread_result);
	printf("Logger thread exit(code %d)\n", *thread_result);
	free(thread_result);


	/* Close syslog */
	closelog();
	printf("Exit application\n\n");
	return EXIT_SUCCESS;
}
コード例 #10
0
ファイル: hdlc.c プロジェクト: archith/camera_project
static int hdlc_open(struct net_device *dev)
{
	hdlc_device *hdlc = dev_to_hdlc(dev);
	int result;

	if (hdlc->mode == MODE_NONE)
		return -ENOSYS;

	memset(&(hdlc->stats), 0, sizeof(struct net_device_stats));

	if (mode_is(hdlc, MODE_FR | MODE_SOFT) ||
	    mode_is(hdlc, MODE_CISCO | MODE_SOFT))
		fr_cisco_open(hdlc);
#ifdef CONFIG_HDLC_PPP
	else if (mode_is(hdlc, MODE_PPP | MODE_SOFT)) {
		sppp_attach(&hdlc->pppdev);
		/* sppp_attach nukes them. We don't need syncppp's ioctl */
		dev->do_ioctl = hdlc_ioctl;
		hdlc->pppdev.sppp.pp_flags &= ~PP_CISCO;
		dev->type = ARPHRD_PPP;
		result = sppp_open(dev);
		if (result) {
			sppp_detach(dev);
			return result;
		}
	}
#endif
#ifdef CONFIG_HDLC_X25
	else if (mode_is(hdlc, MODE_X25)) {
		struct lapb_register_struct cb;

		cb.connect_confirmation = x25_connected;
		cb.connect_indication = x25_connected;
		cb.disconnect_confirmation = x25_disconnected;
		cb.disconnect_indication = x25_disconnected;
		cb.data_indication = x25_data_indication;
		cb.data_transmit = x25_data_transmit;

		result = lapb_register(hdlc, &cb);
		if (result != LAPB_OK)
			return result;
	}
#endif
	result = hdlc->open(hdlc);
	if (result) {
		if (mode_is(hdlc, MODE_FR | MODE_SOFT) ||
		    mode_is(hdlc, MODE_CISCO | MODE_SOFT))
			fr_cisco_close(hdlc);
#ifdef CONFIG_HDLC_PPP
		else if (mode_is(hdlc, MODE_PPP | MODE_SOFT)) {
			sppp_close(dev);
			sppp_detach(dev);
			dev->rebuild_header = NULL;
			dev->change_mtu = hdlc_change_mtu;
			dev->mtu = HDLC_MAX_MTU;
			dev->hard_header_len = 16;
		}
#endif
#ifdef CONFIG_HDLC_X25
		else if (mode_is(hdlc, MODE_X25))
			lapb_unregister(hdlc);
#endif
	}

	return result;
}