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

📄 wlan_config.c

📁 marvell wifi driver GSPI-8385-LINUX-OMAP1510-5.0.10.p0-144-src.rar
💻 C
📖 第 1 页 / 共 5 页
字号:
	if (a < 0)
		return -1;
	b = hex2num(*hex++);
	if (b < 0)
		return -1;
	return (a << 4) | b;
}

int hexstr2bin(const char *hex, u8 *buf, size_t len)
{
	int i, a;
	const char *ipos = hex;
	char *opos = buf;

	for (i = 0; i < len; i++) {
		a = hex2byte(ipos);
		if (a < 0)
			return -1;
		*opos++ = a;
		ipos += 2;
	}
	return 0;
}

unsigned int a2hex_or_atoi(char *value)
{
	if (value[0] == '0' && (value[1] == 'X' || value[1] == 'x'))
		return a2hex(value + 2);
	else
		return atoi(value);
}

static char * wlan_config_get_line(char *s, int size, FILE *stream, int *line)
{
	char *pos, *end, *sstart;

	while (fgets(s, size, stream)) {
		(*line)++;
		s[size - 1] = '\0';
		pos = s;

		while (*pos == ' ' || *pos == '\t')
			pos++;
		if (*pos == '#' || (*pos == '\r' && *(pos+1) == '\n') || 
						*pos == '\n' || *pos == '\0')
			continue;

		/* Remove # comments unless they are within a double quoted
		* string. Remove trailing white space. */
		sstart = strchr(pos, '"');
		if (sstart)
			sstart = strchr(sstart + 1, '"');
		if (!sstart)
			sstart = pos;
		end = strchr(sstart, '#');
		if (end)
			*end-- = '\0';
		else
			end = pos + strlen(pos) - 1;
		while (end > pos && (*end == '\r' || *end == '\n' || 
						*end == ' ' || *end == '\t')) {
			*end-- = '\0';
		}
		if (*pos == '\0')
			continue;
		return pos;
	}

	return NULL;
}

#ifdef BG_SCAN
static int wlan_config_parse_string(const char *value, char *str, size_t *len)
{
	if (*value == '"') {
		char *pos;
		value++;
		pos = strchr(value, '"');
		
		if (pos == NULL || pos[1] != '\0') {
			value--;
			return -1;
		}
		*pos = '\0';
		*len = strlen(value);
		strcpy(str, value);
		return 0;
	} else {
		int hlen = strlen(value);

		if (hlen % 1)
			return -1;
		*len = hlen / 2;
		if (str == NULL)
			return -1;
		if (hexstr2bin(value, str, *len)) {
			return -1;
   		 }
		
	    return 0;
 	 }
}

int bgscan_parse_action(u8 *CmdBuf, int line, char *value)
{
	HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config = 
				(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;
	
	bgscan_config->Action = (u16)a2hex_or_atoi(value);
	return 0;
}

int bgscan_parse_enable(u8 *CmdBuf, int line, char *value)
{
	HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config = 
				(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;

	bgscan_config->Enable = (u8)a2hex_or_atoi(value);
	
	return 0;
}

int bgscan_parse_bsstype(u8 *CmdBuf, int line, char *value)
{
	HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config = 
				(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;

	bgscan_config->BssType = (u8)a2hex_or_atoi(value);

	return 0;
}

int bgscan_parse_channelsperscan(u8 *CmdBuf, int line, char *value)
{
	HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config = 
				(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;
	
	bgscan_config->ChannelsPerScan = (u8)a2hex_or_atoi(value);

	return 0;
}

int bgscan_parse_discardwhenfull(u8 *CmdBuf, int line, char *value)
{
	HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config = 
				(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;
	
	bgscan_config->DiscardWhenFull = (u8)a2hex_or_atoi(value);

	return 0;
}

int bgscan_parse_scaninterval(u8 *CmdBuf, int line, char *value)
{
	HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config = 
				(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;
	
	bgscan_config->ScanInterval = (u32)a2hex_or_atoi(value);

	return 0;
}

int bgscan_parse_storecondition(u8 *CmdBuf, int line, char *value)
{
	HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config = 
				(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;
	
	bgscan_config->StoreCondition = a2hex_or_atoi(value);

	return 0;
}

int bgscan_parse_reportconditions(u8 *CmdBuf, int line, char *value)
{
	HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config = 
				(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;
	
	bgscan_config->ReportConditions = a2hex_or_atoi(value);

	return 0;
}

int bgscan_parse_maxscanresults(u8 *CmdBuf, int line, char *value)
{
	HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config = 
				(HostCmd_DS_802_11_BG_SCAN_CONFIG *)CmdBuf;
	
	bgscan_config->MaxScanResults = (u16)a2hex_or_atoi(value);

	return 0;
}

int bgscan_parse_ssid(u8 *CmdBuf, int line, char *value)
{
	static int 			ssidCnt;
	MrvlIEtypes_SsIdParamSet_t 	*SsIdParamSet = NULL;
	char				*buf;
	size_t				len = 0;
	
	SsIdParamSet = (MrvlIEtypes_SsIdParamSet_t *)(CmdBuf + ActualPos);

	buf = (char *)malloc(strlen(value));	

	if(wlan_config_parse_string(value, buf, &len)) {
		printf("Invalid SSID\n");
       		free(buf);
 		return -1;
	}		

	ssidCnt++;

	if(!strlen(buf)) {
		printf("The %dth SSID is NULL.\n", ssidCnt);
	}

 	SsIdParamSet->Header.Type = cpu_to_le16(TLV_TYPE_SSID); /*0x0000; */
	SsIdParamSet->Header.Len  = strlen(buf);

	TLVSsidSize += SsIdParamSet->Header.Len + 
			sizeof(MrvlIEtypesHeader_t);

	ActualPos += SsIdParamSet->Header.Len + 
			sizeof(MrvlIEtypesHeader_t);
	
	SsIdParamSet->Header.Len  = cpu_to_le16(SsIdParamSet->Header.Len);
	
	memcpy(SsIdParamSet->SsId, buf, strlen(buf));

	free(buf);
	return 0;
}		

int bgscan_parse_probes(u8 *CmdBuf, int line, char *value)
{
	MrvlIEtypes_NumProbes_t	*Probes = NULL;

#define PROBES_PAYLOAD_SIZE	2
	
	Probes = (MrvlIEtypes_NumProbes_t *)(CmdBuf + ActualPos);

	Probes->Header.Type = TLV_TYPE_NUMPROBES;
	Probes->Header.Len = PROBES_PAYLOAD_SIZE;
	
	Probes->NumProbes = (u16)a2hex_or_atoi(value);

	if (Probes->NumProbes) {
		TLVProbeSize += sizeof(MrvlIEtypesHeader_t) +
						Probes->Header.Len;
	} else {
		TLVProbeSize = 0;
	}

	ActualPos += TLVProbeSize;
	return 0;
}

int bgscan_parse_channellist(u8 *CmdBuf, int line, char *value)
{
  MrvlIEtypes_ChanListParamSet_t  *chan;
  char *buf, *grp0, *grp1;
  int len, idx;

  chan = (MrvlIEtypes_ChanListParamSet_t *)(CmdBuf + ActualPos);

  len = strlen(value) + 1;
  buf = malloc(len);

  if (buf == NULL)
    return -1;

  memset(buf, 0, len);
  strcpy(buf, value);

  chan->Header.Type = cpu_to_le16(TLV_TYPE_CHANLIST);
  grp1 = buf;
  idx = 0;

  while ((grp1 != NULL) && (*grp1 != 0))
  {
    grp0 = strsep(&grp1, "\";");

    if ((grp0 != NULL) && (*grp0 != 0))
    {
      chan->ChanScanParam[idx].RadioType    = atoi(strtok(grp0, ","));
      chan->ChanScanParam[idx].ChanNumber   = atoi(strtok(NULL, ","));
      chan->ChanScanParam[idx].ScanType     = atoi(strtok(NULL, ","));
      chan->ChanScanParam[idx].MinScanTime  = atoi(strtok(NULL, ","));
      chan->ChanScanParam[idx].MaxScanTime  = atoi(strtok(NULL, ","));
      idx ++;
    }
  }

  chan->Header.Len = (idx * sizeof(ChanScanParamSet_t));
  TLVChanSize += (chan->Header.Len + sizeof(MrvlIEtypesHeader_t));
  chan->Header.Len = cpu_to_le16(chan->Header.Len);
  ActualPos += TLVChanSize;

  free (buf);
  return 0;
}

int bgscan_parse_snrthreshold(u8 *CmdBuf, int line, char *value)
{
	MrvlIEtypes_SnrThreshold_t	*SnrThreshold = NULL;
	unsigned int 	tmp;
	
	SnrThreshold = (MrvlIEtypes_SnrThreshold_t *)(CmdBuf + ActualPos);

	SnrThreshold->Header.Type = TLV_TYPE_SNR;
	SnrThreshold->Header.Len = PROBES_PAYLOAD_SIZE;
	
	tmp = (u16)a2hex_or_atoi(value);
	SnrThreshold->SNRValue = tmp & 0xff;
	SnrThreshold->SNRFreq = (tmp >> 8) & 0xff;

    	TLVSnrSize += sizeof(MrvlIEtypesHeader_t) + SnrThreshold->Header.Len; 
	ActualPos += TLVSnrSize;
	return 0;
}

int bgscan_parse_bcastprobe(u8 *CmdBuf, int line, char *value)
{
	MrvlIEtypes_BcastProbe_t *BcastProbe = NULL;


	BcastProbe = (MrvlIEtypes_BcastProbe_t *)(CmdBuf + ActualPos);

	BcastProbe->Header.Type = TLV_TYPE_BCASTPROBE;
	BcastProbe->Header.Len = PROBES_PAYLOAD_SIZE;
	
	BcastProbe->BcastProbe = (u16)a2hex_or_atoi(value);

    	TLVBcProbeSize = sizeof(MrvlIEtypesHeader_t) + BcastProbe->Header.Len;
	ActualPos += TLVBcProbeSize;
	return 0;
}

int bgscan_parse_numssidprobe(u8 *CmdBuf, int line, char *value)
{
	MrvlIEtypes_NumSSIDProbe_t *NumSSIDProbe = NULL;


	NumSSIDProbe = (MrvlIEtypes_NumSSIDProbe_t *)(CmdBuf + ActualPos);

	NumSSIDProbe->Header.Type = TLV_TYPE_NUMSSID_PROBE;
	NumSSIDProbe->Header.Len = PROBES_PAYLOAD_SIZE;
	
	NumSSIDProbe->NumSSIDProbe = (u16)a2hex_or_atoi(value);

    	TLVNumSsidProbeSize = sizeof(MrvlIEtypesHeader_t) + NumSSIDProbe->Header.Len;
	ActualPos += TLVNumSsidProbeSize;
	return 0;
}

int wlan_get_bgscan_data(FILE *fp, int *line, 
				HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config)
{
	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 bgscan 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_BGSCAN_FIELDS; i++) {
			if (strcmp(pos, bgscan_fields[i].name) == 0) {
				if (bgscan_fields[i].parser((u8 *)bgscan_config,
								*line, pos2)) {
					printf("Line %d: failed to parse %s"
						"'%s'.", *line, pos, pos2);
					errors++;
					}
				break;
			}
		}
		if (i == NUM_BGSCAN_FIELDS) {
			printf("Line %d: unknown bgscan field '%s'.\n", 
								*line, pos);
			errors++;
		}
	}
	return 0;
}

int process_bg_scan_config(int argc, char *argv[])
{
	u8				scanCfg[512], *pos, *buf = NULL;
	char				filename[48] = "";
	FILE				*fp;
	HostCmd_DS_802_11_BG_SCAN_CONFIG *bgscan_config;
	struct ifreq			userdata;
	int 				line = 0;
	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 + TLVSnrSize + TLVBcProbeSize + TLVNumSsidProbeSize;

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

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

	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) {

⌨️ 快捷键说明

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