⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 Linux Wireless LAN Project 的目标是开发一个完整的
💻 C
📖 第 1 页 / 共 2 页
字号:
		if (strcmp(argv[7], "both") == 0 )		{			cmd.bsstype = BSSTYPE_IND | BSSTYPE_INFRA;		}		else if ( strcmp(argv[7], "independent") == 0 )		{			cmd.bsstype = BSSTYPE_IND;		}		else		{			cmd.bsstype = BSSTYPE_INFRA;		}		if ( strcmp( argv[8], "active") == 0 )		{			cmd.scantype = 0;		}		else		{			cmd.scantype = 1;		}		cmd.ssid[0] = WLAN_EID_SSID;		if ( (cmd.ssid[1] = strlen(argv[9])) <= 32 )		{			memcpy( &(cmd.ssid[2]), argv[9], cmd.ssid[1]);		}		else		{			fprintf(stderr, "warning: ssid longer than 32 chars, using wildcard.");			cmd.ssid[1] = 0;			cmd.ssid[2] = 0;		}		result = ioctl( fd, WLAN_SCAN, &req);		switch( req.result)		{			case 0: 				process_netlist( fd, argc, argv );				break;			case 1: 				fprintf(stderr, "%s: command discarded, driver is already scanning\n", appname);				break;			case 2: 				fprintf(stderr, "%s: h/w scan command failed!\n", appname);				break;			default:				fprintf(stderr, "%s: unknown error.\n", appname);				break;		}	}	    return result;}/*----------------------------------------------------------------*	process_getmib**	Called when the user has requested the 'getmib' command at the*	command line.**	This function calls getmib to read the contents of one or more*   Managment Information Block (MIB) structures from the specified*   wireless network device and display the values.  Issuing just the*   getmib command to wlanctl displays ALL MIB's.  Otherwise, a*   particular MIB(s) is specified following the getmib command.*   *   Valid MIB values are:*		0x00 for local mib*		0x02 for address mib*		0x03 for mac (media access control) mib*		0x04 for statistics mib*		0x05 for managment mib*		0x07 for physical mib*	Arguments:*		fd 		- socket file descriptor*		argc  	- the argument count passed to main *		argv	- the argument list passed to main **	returns: 0 if successful, not 0 otherwise*----------------------------------------------------------------*/int process_getmib( int fd, int argc, char **argv ){	int			result;	result = 0;	/* ok, which mib's? */	if ( argc >= 4 )	{		int		i;		UINT32	mibcode;		for ( i = 3; i < argc; i++ )		{		   mibcode = atoi(argv[i]);		   result = getmib( fd, argv[1], mibcode );		}	}	else	{		/* OK, print them all */		result = getmib( fd, argv[1], SUMIB_LOCAL);		result = getmib( fd, argv[1], SUMIB_ADDR);		result = getmib( fd, argv[1], SUMIB_MAC);		result = getmib( fd, argv[1], SUMIB_STAT);		result = getmib( fd, argv[1], SUMIB_MGMT);		result = getmib( fd, argv[1], SUMIB_PHY);	}	return result;}/*----------------------------------------------------------------*	process_netlist**	Called when the user has requested the 'netlist' command at the*	command line.**	This function prints all the BSS's in the current list of BSS's*	generated from the last scan.*   *	Arguments:*		fd 		- socket file descriptor*		argc  	- the argument count passed to main *		argv	- the argument list passed to main **	returns: 0 if successful, not 0 otherwise*----------------------------------------------------------------*/int process_netlist( int fd, int argc, char **argv ){	int					result;	wlan_req_t			req;	wlan_netlist_len_t	cmd1;	wlan_netlist_t		*cmd2;	result = 0;	strcpy( req.name, argv[1]);	req.result = 0;	req.data = &cmd1;	req.len = sizeof(cmd1);	result = ioctl( fd, WLAN_NETLIST_LEN, &req);	if ( result || req.result )	{		fprintf(stderr,"%s: ioctl failed in netlist_len command.\n", appname);	}	else	{		cmd2 = malloc( sizeof(wlan_netlist_t) + (cmd1.nitems * sizeof(netitem_t)));		cmd2->nitems = cmd1.nitems;		req.result = 0;		req.data = cmd2;		req.len = sizeof(wlan_netlist_t) + (cmd1.nitems * sizeof(netitem_t));		result = ioctl( fd, WLAN_NETLIST, &req);		if ( result || req.result )		{			fprintf(stderr,"%s: ioctl failed in netlist command\n", appname);		}		else		{			pr_netlist( cmd2 );		}	}	return result;}/*----------------------------------------------------------------*	process_bsscreate**	Called when the user has requested the 'bsscreate' command at the*	command line.**	This function creates a BSS based on the arguments passed to the*   command.  The arguments are in the order that follows:*		channel - the channel number to establish the bss on.*		beacon interval - time (in microseconds) between the*			transmission of beacon frames in the new BSS.*		atim window - "Announcement Traffic Indication Message"*			The atim window is the period of time following a target*			beacon transmission time (TBTT) that power saving MAC*			entities should remain awake listening for atim frames.*			Units for the atim window are 1024 microseconds.*		ssid - "Service Set Identifier": a string (with a maximum*			length of 15 characters) that identifies the new BSS.*			This is not to be confused with the BSSID, namely the*			IEEE 802 48 bit address.*   *	Arguments:*		fd 		- socket file descriptor*		argc  	- the argument count passed to main *		argv	- the argument list passed to main **	returns: 0 if successful, not 0 otherwise*----------------------------------------------------------------*/int process_bsscreate( int fd, int argc, char **argv ){	int					result;	result = 0;	if (argc < 7)	{		fprintf(stderr,"%s: not enough arguments for bsscreate command; ",				appname);		fprintf(stderr, "see wlanctl man page.\n");		usage();	}	else	{		wlan_req_t	req;		wlan_bsscreate_t cmd;		strcpy( req.name, argv[1]);		req.result = 0;		req.data = &cmd;		req.len = sizeof(cmd);		cmd.channel = atoi(argv[3]);		cmd.beacon_int = atoi(argv[4]);		cmd.atim_win = atoi(argv[5]);		cmd.ssid[0] = WLAN_EID_SSID;		cmd.ssid[1] = strlen(argv[6]);		strcpy( &(cmd.ssid[2]), argv[6]);		result = ioctl( fd, WLAN_BSSCREATE, &req);		if ( result )		{			fprintf(stderr,"%s: ioctl failed for bsscreate command.\n",					appname);		}	}	return result;}/*----------------------------------------------------------------*	process_bssjoin**	Called when the user has requested the 'bssjoin' command at the*	command line.**	This function forces the wireless network device to join*	(syncronize) with the named BSS.  The named BSS provided as an*	argument to the bssjoin command must be a valid BSS in the*	network list.*   *	Arguments:*		fd 		- socket file descriptor*		argc  	- the argument count passed to main *		argv	- the argument list passed to main **	returns: 0 if successful, not 0 otherwise*----------------------------------------------------------------*/int process_bssjoin( int fd, int argc, char **argv ){	int					result;	wlan_req_t			req;	wlan_bssjoin_t		cmd;	result = 0;	if ( argc < 4 )	{		fprintf(stderr, 			"%s: not enough arguments for the bssjoin command; ", appname);		fprintf(stderr, "see wlanctl man page.\n");		usage();		result = 1;	}	else	{		strcpy( req.name, argv[1]);		req.result = 0;		req.data = &cmd;		req.len = sizeof(cmd);		strtoUINT48( cmd.bssid, argv[3] );		result = ioctl( fd, WLAN_BSSJOIN, &req);		if ( req.result )		{			fprintf(stderr,			"%s: Either the bssid was invalid or the sync command failed.\n",				appname);			result = 1;		}	}	return result;}/*----------------------------------------------------------------*	process_privacy**	Called when the user has requested the 'privacy' command at the*	command line.**	This function collects the privacy settings and sends them down*	to the driver.*   *	Arguments:*		fd 		- socket file descriptor*		argc  	- the argument count passed to main *		argv	- the argument list passed to main **	returns: 0 if successful, not 0 otherwise*----------------------------------------------------------------*/int process_privacy( int fd, int argc, char **argv ){	int					result;	wlan_req_t			req;	wlan_privacy_t		cmd;	int					i;	result = 0;	if ( argc < 4 )	{		fprintf(stderr, 			"%s: not enough arguments for the bssjoin command; ", appname);		fprintf(stderr, "see wlanctl man page.\n");		usage();		result = 1;	}	else	{		strcpy( req.name, argv[1]);		req.result = 0;		req.data = &cmd;		req.len = sizeof(cmd);		cmd.defkey = atoi(argv[3]);		cmd.exclude_unencrypted = (strcmp(argv[4], "exclude_unenecrypted")==0);		for ( i = 0; i < 4; i++)		{			strtoUINT40( cmd.keys[i], argv[i + 5] );		}		result = ioctl( fd, WLAN_PRIVACY, &req);		if ( req.result )		{			fprintf(stderr,			"%s: There's a bad arg or the device isn't present.\n",				appname);			result = 1;		}	}	return result;}/*----------------------------------------------------------------*	process_ethconv**	Called when the user wants to change the default ethernet *	conversion.**	Arguments:*		fd 		- socket file descriptor*		argc  	- the argument count passed to main *		argv	- the argument list passed to main **	returns: 0 if successful, not 0 otherwise*----------------------------------------------------------------*/int process_ethconv( int fd, int argc, char **argv ){	int					result;	wlan_req_t			req;	wlan_ethconv_t		cmd;	result = 0;	if ( argc < 4 )	{		fprintf(stderr, 			"%s: not enough arguments for the bssjoin command; ", appname);		fprintf(stderr, "see wlanctl man page.\n");		usage();		result = 1;	}	else	{		strcpy( req.name, argv[1]);		req.result = 0;		req.data = &cmd;		req.len = sizeof(cmd);		cmd.ethconv_type = WLAN_ETHCONV_ENCAP;		if ( strcmp(argv[3], "encapsulation")==0 )		{			cmd.ethconv_type = WLAN_ETHCONV_ENCAP;		}		if ( strcmp(argv[3], "rfc1042")==0 )		{			cmd.ethconv_type = WLAN_ETHCONV_RFC1042;		}		if ( strcmp(argv[3], "802.1h")==0 )		{			cmd.ethconv_type = WLAN_ETHCONV_8021h;		}		result = ioctl( fd, WLAN_ETHCONV, &req);		if ( req.result )		{			fprintf(stderr,			"%s: There's a bad arg or the device isn't present.\n",				appname);			result = 1;		}	}	return result;}/*----------------------------------------------------------------*	process_authen**	Called when the user wants to establish the authentication*	relationship with the AP at the joined BSSID.**	Arguments:*		fd 		- socket file descriptor*		argc  	- the argument count passed to main *		argv	- the argument list passed to main **	returns: 0 if successful, not 0 otherwise*----------------------------------------------------------------*/int process_authen( int fd, int argc, char **argv ){	int					result;	wlan_req_t			req;	result = 0;	strcpy( req.name, argv[1]);	req.result = 0;	req.data = NULL;	req.len = 0;	result = ioctl( fd, WLAN_AUTHENTICATE, &req);	/* TODO: error handling needs alot of work */	if ( req.result )	{		fprintf(stderr,		"%s: There's a bad arg or the device isn't present.\n",			appname);		result = 1;	}	return result;}/*----------------------------------------------------------------*	process_assoc**	Called when the user wants to establish the association*	relationship with the AP at the joined ESSID.**	Arguments:*		fd 		- socket file descriptor*		argc  	- the argument count passed to main *		argv	- the argument list passed to main **	returns: 0 if successful, not 0 otherwise*----------------------------------------------------------------*/int process_assoc( int fd, int argc, char **argv ){	int					result;	wlan_req_t			req;	result = 0;	strcpy( req.name, argv[1]);	req.result = 0;	req.data = NULL;	req.len = 0;	result = ioctl( fd, WLAN_ASSOCIATE, &req);	/* TODO: error handling needs alot of work */	if ( req.result )	{		fprintf(stderr,		"%s: There's a bad arg or the device isn't present.\n",			appname);		result = 1;	}	return result;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -