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

📄 wlan_config.c

📁 marvell cf wifi driver source code CF-8385-linux-x86-5.0.4.p0-132-src.rar
💻 C
📖 第 1 页 / 共 5 页
字号:
	int				CmdNum = BG_SCAN_CONFIG;
	int				Action;
	u16				Size;

	buf = (u8 *)malloc(512);
	
	memset(buf, 0, 512);

	bgscan_config = (HostCmd_DS_802_11_BG_SCAN_CONFIG *)
				(buf + sizeof(int) + sizeof(u16));

	if (argc != 4) {
		printf("Error: invalid no of arguments\n");
		printf("Syntax: ./wlanconfig eth1 bgscanconfig <filename>\n");
		exit(1);
	}
	
	strncpy(filename, argv[3], MIN(sizeof(filename)-1, strlen(argv[3])));
	if ((fp = fopen(filename, "r")) == NULL) {
		fprintf(stderr, "Cannot open file %s\n", filename);
		exit(1);
	}

	while ((pos = wlan_config_get_line(scanCfg, sizeof(scanCfg), fp, 
								&line))) {
		if (strcmp(pos, "bgscan={") == 0) {
			wlan_get_bgscan_data(fp, &line, bgscan_config);
		}
	}

	fclose(fp);

	Action = bgscan_config->Action;

	Size = sizeof(HostCmd_DS_802_11_BG_SCAN_CONFIG) +
		TLVSsidSize + TLVProbeSize + TLVChanSize;

	memcpy(buf, &CmdNum, sizeof(int));
	memcpy(buf + sizeof(int), &Size, sizeof(u16));

	strncpy(userdata.ifr_name, DevName, IFNAMSIZ);
	userdata.ifr_data = buf;

#if 0
	{
		int i;
		for(i = 0; i < Size + 6; i++)
			printf(" 0x%X",buf[i]);
		printf("\n");
	}
#endif

	if (ioctl(sockfd, WLAN_SETCONF_GETCONF, &userdata)) {
		fprintf(stderr, "wlanconfig: BG_SCAN is not supported by %s\n", 
								DevName);
			return -1;
   	}

	if (Action == HostCmd_ACT_GEN_GET) {
		int i;
		printf("BGSCAN Configuration setup:\n");
		for(i = 0; i < Size; i++) {
			if (!(i % 10)) {
				printf("\n");
			}
			printf(" 0x%x ", buf[i + 3]);
		}
		printf("\n");
	}

	free(buf);

	return 0;

}
#endif

#ifdef SUBSCRIBE_EVENT_CTRL
int sub_event_parse_action(EventSubscribe *EventData, int line, char *value)
{
	
	EventData->Action = (u16)a2hex_or_atoi(value);

	return 0;
}

int sub_event_parse_event(EventSubscribe *EventData, int line, char *value)
{
	
	EventData->Events = (u16)a2hex_or_atoi(value);

	return 0;	
}

int sub_event_parse_RSSI(EventSubscribe *EventData, int line, char *value)
{
	char		*p = value, *token;
	char		delim = ',';

	token = strtok(p, &delim);
	EventData->RSSIValue = (u8)a2hex_or_atoi(token);
	p = NULL;
	token = strtok(p, &delim);
	EventData->RSSIFreq = (u8)a2hex_or_atoi(token);

	return 0;
}

int sub_event_parse_SNR(EventSubscribe *EventData, int line, char *value)
{
	char		*p = value, *token;
	char		delim = ',';

	token = strtok(p, &delim);
	EventData->SNRValue = (u8)a2hex_or_atoi(token);
	p = NULL;
	token = strtok(p, &delim);
	EventData->SNRFreq = (u8)a2hex_or_atoi(token);

	return 0;
}

int sub_event_parse_failcnt(EventSubscribe *EventData, int line, char *value)
{
	char		*p = value, *token;
	char		delim = ',';

	token = strtok(p, &delim);
	EventData->FailValue = (u8)a2hex_or_atoi(token);
	p = NULL;
	token = strtok(p, &delim);
	EventData->FailFreq = (u8)a2hex_or_atoi(token);

	return 0;
}

int sub_event_parse_beacon_missed(EventSubscribe *EventData, int line, char *value)
{
	EventData->BcnMissed = (u8)a2hex_or_atoi(value);

	return 0;
}

int wlan_get_subscribe_event_data(FILE *fp, int *line, EventSubscribe *EventData)
{
	int	errors = 0, i, end = 0;
	char	buf[256], *pos, *pos2;


	while ((pos = wlan_config_get_line(buf, sizeof(buf), fp, line))) {
		if (strcmp(pos, "}") == 0) {
			end = 1;
			break;
		}

		pos2 = strchr(pos, '=');
		if (pos2 == NULL) {
			printf("Line %d: Invalid sub_event line '%s'.",
								*line, pos);
			errors++;
			continue;
		}

		*pos2++ = '\0';
		if (*pos2 == '"') {
			if (strchr(pos2 + 1, '"') == NULL) {
				printf("Line %d: invalid quotation '%s'.", 
								*line, pos2);
				errors++;
				continue;
			}
		}

		for (i = 0; i < NUM_SUB_EVENT_FIELDS; i++) {
			if (strcmp(pos, sub_event_fields[i].name) == 0) {
				if (sub_event_fields[i].parser(EventData,
								*line, pos2)) {
					printf("Line %d: failed to parse %s"
						"'%s'.", *line, pos, pos2);
					errors++;
					}
				break;
			}
		}
		if (i == NUM_SUB_EVENT_FIELDS) {
			printf("Line %d: unknown sub_event field '%s'.", 
								*line, pos);
			errors++;
		}
	}
	return 0;
}

int process_event_subscribe(int argc, char *argv[])
{
	u8			*buf;
	char			event_data[512];
	char			filename[48] = "";
	FILE			*fp;
	EventSubscribe		EventData;
	struct ifreq		userdata;
	u8			*pos;
	int			line = 0;
	int			CmdNum = SUBSCRIBE_EVENT; 

	memset(&EventData, 0, sizeof(EventSubscribe));
	
	if (argc != 4) {
		printf("Error: invalid no of arguments\n");
		printf("Syntax: ./wlanconfig eth1 subevent <filename>\n");
		exit(1);
	}
	
	strncpy(filename, argv[3], MIN(sizeof(filename)-1, strlen(argv[3])));

	if ((fp = fopen(filename, "r")) == NULL) {
		fprintf(stderr, "Cannot open file %s\n", argv[1]);
		exit(1);
	}

	while ((pos = wlan_config_get_line(event_data, sizeof(event_data), fp, 
							(int *)&line))) {
		if (strcmp(pos, "Events={") == 0) {
			wlan_get_subscribe_event_data(fp, &line, &EventData);
		}
	}

	fclose(fp);

	buf = (u8 *)malloc(512);

	memcpy(buf, &CmdNum, sizeof(int));
	memcpy(buf + sizeof(int), (u8 *)&EventData.Action, 
							sizeof(EventSubscribe));

	strncpy(userdata.ifr_name, DevName, IFNAMSIZ);
	userdata.ifr_data = buf;
	
	if (ioctl(sockfd, WLAN_SETCONF_GETCONF, &userdata)) {
		fprintf(stderr, "wlanconfig: SUBSCRIBE_EVENT not"
						" supported by %s\n", DevName);
			return -1;
   	}
	
#if 0	
	{
		int	i = 0;
		for(i = 3; i < sizeof(EventSubscribe); i++)
			printf("0x%X ", buf[i]);
		printf("\n");
	}
#endif
#define GET_EVENTS	0
#define BIT_0		(1 << 0) 
#define BIT_1		(1 << 1)
#define BIT_2		(1 << 2)
#define BIT_3		(1 << 3)
	if (EventData.Action == GET_EVENTS) {
		u16		Events;

		Events = *(u16 *)(buf + sizeof(int));

		printf("Events Subscribed to Firmware are\n");

		if (Events & BIT_0) {
			printf("RSSI_LOW\n");
		}

		if (Events & BIT_1) {
			printf("SNR_LOW\n");
		}

		if (Events & BIT_2) {
			printf("MAX_FAIL\n");
		}

		if (Events & BIT_3) {
			printf("LINK LOSS\n");
		}
			
	}
		
	free(buf);

	return 0;
}
#endif

#ifdef CAL_DATA
/* To Change the calibration */
int process_cal_data(int argc, char *argv[])
{
	int			i, count;
	u8			*buf;
	char			filename[48] = "";
	FILE			*fp;
	wlan_ioctl_cal_data	cal_data;
	struct ifreq		userdata;

	memset(&cal_data, 0, sizeof(cal_data));

	buf = (u8 *) &cal_data.Type;
	
	if (argc != 4) {
		printf("Error: invalid no of arguments\n");
		printf("Syntax: ./wlanconfig eth1 caldata <filename>\n");
		exit(1);
	}
	
	strncpy(filename, argv[3], MIN(sizeof(filename)-1, strlen(argv[3])));
	if ((fp = fopen(filename, "r")) == NULL) {
		fprintf(stderr, "Cannot open file %s\n", argv[1]);
		exit(1);
	}

	count = fparse_for_hex(fp, buf + 1);
	fclose(fp);

#ifdef  DEBUG	
	printf("\n");
	printf("HEXDUMP of the configuration file:");
	for (i = 0; i < count; i++) {
		if (!(i % 16))
			printf("\n");
		printf("%02x ", buf[i]);
	}
	printf("\n\n");
#endif

	display_calibration(&cal_data, 0);

	strncpy(userdata.ifr_name, DevName, IFNAMSIZ);
	userdata.ifr_data = (char *) &cal_data;

	if (ioctl(sockfd, WLAN_SETCONF_GETCONF, &userdata)) {
		fprintf(stderr, "wlanconfig: CAL DATA not supported by %s\n", 
								DevName);
			return -1;
   	}
	
	display_calibration(&cal_data, 1);

	return 0;
}

int process_cal_data_ext(int argc, char *argv[])
{
	int				i, count;
	u8				*buf, *CmdBuf;
	FILE				*fp;
	char				filename[48] = "";
	HostCmd_DS_802_11_CAL_DATA_EXT	cal_data; 
	struct ifreq			userdata;
	int				CmdNum = CAL_DATA_EXT_CONFIG;

	printf("Enter process_cal_data_ext()\n");
	memset(&cal_data, 0, sizeof(cal_data));

	buf = (u8 *) &cal_data.Action;
	
	if (argc != 4) {
		printf("Error: invalid no of arguments\n");
		printf("Syntax: ./wlanconfig eth1 caldataext <filename>\n");
		exit(1);
	}
	
	strncpy(filename, argv[3], MIN(sizeof(filename)-1, strlen(argv[3])));
	if ((fp = fopen(filename, "r")) == NULL) {
		fprintf(stderr, "Cannot open file %s\n", argv[1]);
		exit(1);
	}
	
	count = fparse_for_hex(fp, buf); //copyfile data to buf+1
	fclose(fp);

	CmdBuf = malloc(sizeof(HostCmd_DS_802_11_CAL_DATA_EXT) + sizeof(int));
	memcpy(CmdBuf, &CmdNum, sizeof(int));
	memcpy(CmdBuf + sizeof(int), &cal_data, 
					sizeof(HostCmd_DS_802_11_CAL_DATA_EXT));
	strncpy(userdata.ifr_name, DevName, IFNAMSIZ);
	userdata.ifr_data = CmdBuf;

#ifdef  DEBUG	
	printf("\n");
	printf("HEXDUMP of the configuration file:");
	for (i = 0; i < count; i++) {
		if (!(i % 16))
			printf("\n");
		printf("%02x ", buf[i]);
	}
	printf("\n\n");
#endif
	if (ioctl(sockfd, WLAN_SETCONF_GETCONF, &userdata)) { 
		fprintf(stderr, "wlanconfig: CAL DATA not supported by %s\n", 
								DevName);
			return -1;
   	}

	free(CmdBuf); //free CmdBuf
	printf("Exit process_cal_data_ext()\n"); 
	return 0;
}
#endif

char *readCurCmd(char *ptr, char *curCmd)
{
	int i = 0;
#define MAX_CMD_SIZE 64

	while(*ptr != ']' && i < (MAX_CMD_SIZE - 1))
		curCmd[i++] = *(++ptr);	

	if(*ptr != ']')
		return NULL;

	curCmd[i - 1] = '\0';

	return ++ptr;
}

int fparse_for_cmd_and_hex(FILE *fp, u8 *dst, u8 *cmd)
{
	char	*ptr;
	u8	*dptr;
	char	buf[256], curCmd[64];
	int	isCurCmd = 0;

	char *convert2hex(char *ptr, u8 *chr);

	dptr = dst;
	while (fgets(buf, sizeof(buf), fp)) {
		ptr = buf;

		while (*ptr) {
			// skip leading spaces
			while (*ptr && isspace(*ptr))
				ptr++;

			// skip blank lines and lines beginning with '#'
			if (*ptr == '\0' || *ptr == '#')
				break;

			if(*ptr == '[' && *(ptr + 1) != '/') {
				if(!(ptr = readCurCmd(ptr, curCmd)))
					return -1;

				if(strcasecmp(curCmd, cmd)) /* Not equal */
					isCurCmd = 0;
				else
					isCurCmd = 1;
			}

			/* Ignore the rest if it is not correct cmd */
			if(!isCurCmd)
				break;

			if(*ptr == '[' && *(ptr + 1) == '/' )
				return (dptr - dst);

			if (isxdigit(*ptr)) {
				ptr = convert2hex(ptr, dptr++);
			} else {
				/* Invalid character on data line */
				ptr++;
			}
		}
	}

	return -1;
}

int fparse_for_hex(FILE *fp, u8 *dst)
{
	char	*ptr;
	u8	*dptr;
	char	buf[256];

	char *convert2hex(char *ptr, u8 *chr);

	dptr = dst;
	while (fgets(buf, sizeof(buf), fp)) {
		ptr = buf;

		while (*ptr) {
			// skip leading spaces
			while (*ptr && isspace(*ptr))
				ptr++;

			// skip blank lines and lines beginning with '#'
			if (*ptr == '\0' || *ptr == '#')
				break;

			if (isxdigit(*ptr)) {
				ptr = convert2hex(ptr, dptr++);
			} else {
				/* Invalid character on data line */
				ptr++;
			}
		}
	}

	return (dptr - dst);
}

char *convert2hex(char *ptr, u8 *chr)
{
	u8	val;

	int hexval(int chr);

	for (val = 0; *ptr && isxdigit(*ptr); ptr++) {
		val = (val * 16) + hexval(*ptr);
	}

	*chr = val;

	return ptr;
}

int hexval(int chr)
{
	if (chr >= '0' && chr <= '9')
		return chr - '0';
	if (chr >= 'A' && chr <= 'F')
		return chr - 'A' + 10;
	if (chr >= 'a' && chr <= 'f')
		return chr - 'a' + 10;

	return 0;
}

int process_read_register(int cmd, char *stroffset)
{
	struct ifreq    userdata;
	wlan_ioctl_regrdwr reg;
	char           *whichreg;

	switch (cmd) {
		case CMD_RDMAC:
			/*
			 * HostCmd_CMD_MAC_REG_ACCESS 
			 */
			reg.WhichReg = REG_MAC;
			whichreg = "MAC";
			break;
		case CMD_RDBBP:
			/*
			 * HostCmd_CMD_BBP_REG_ACCESS 
			 */
			reg.WhichReg = REG_BBP;
			whichreg = "BBP";
			break;
		case CMD_RDRF:
			/*
			 * 

⌨️ 快捷键说明

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