• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify it
6  * under the terms of version 2 of the GNU General Public License as
7  * published by the Free Software Foundation.
8  *
9  * This program is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12  * more details.
13  *
14  ******************************************************************************/
15 #define _RTW_DEBUG_C_
16 
17 #include <rtw_debug.h>
18 #include <usb_ops_linux.h>
19 
proc_get_drv_version(char * page,char ** start,off_t offset,int count,int * eof,void * data)20 int proc_get_drv_version(char *page, char **start,
21 			  off_t offset, int count,
22 			  int *eof, void *data)
23 {
24 	int len = 0;
25 
26 	len += snprintf(page + len, count - len, "%s\n", DRIVERVERSION);
27 
28 	*eof = 1;
29 	return len;
30 }
31 
proc_get_write_reg(char * page,char ** start,off_t offset,int count,int * eof,void * data)32 int proc_get_write_reg(char *page, char **start,
33 			  off_t offset, int count,
34 			  int *eof, void *data)
35 {
36 	*eof = 1;
37 	return 0;
38 }
39 
proc_set_write_reg(struct file * file,const char __user * buffer,unsigned long count,void * data)40 int proc_set_write_reg(struct file *file, const char __user *buffer,
41 		unsigned long count, void *data)
42 {
43 	struct net_device *dev = data;
44 	struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
45 	char tmp[32];
46 	u32 addr, val, len;
47 
48 	if (count < 3) {
49 		DBG_88E("argument size is less than 3\n");
50 		return -EFAULT;
51 	}
52 
53 	if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
54 		int num = sscanf(tmp, "%x %x %x", &addr, &val, &len);
55 
56 		if (num !=  3) {
57 			DBG_88E("invalid write_reg parameter!\n");
58 			return count;
59 		}
60 		switch (len) {
61 		case 1:
62 			usb_write8(padapter, addr, (u8)val);
63 			break;
64 		case 2:
65 			usb_write16(padapter, addr, (u16)val);
66 			break;
67 		case 4:
68 			usb_write32(padapter, addr, val);
69 			break;
70 		default:
71 			DBG_88E("error write length =%d", len);
72 			break;
73 		}
74 	}
75 	return count;
76 }
77 
78 static u32 proc_get_read_addr = 0xeeeeeeee;
79 static u32 proc_get_read_len = 0x4;
80 
proc_get_read_reg(char * page,char ** start,off_t offset,int count,int * eof,void * data)81 int proc_get_read_reg(char *page, char **start,
82 			  off_t offset, int count,
83 			  int *eof, void *data)
84 {
85 	struct net_device *dev = data;
86 	struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
87 
88 	int len = 0;
89 
90 	if (proc_get_read_addr == 0xeeeeeeee) {
91 		*eof = 1;
92 		return len;
93 	}
94 
95 	switch (proc_get_read_len) {
96 	case 1:
97 		len += snprintf(page + len, count - len, "usb_read8(0x%x)=0x%x\n", proc_get_read_addr, usb_read8(padapter, proc_get_read_addr));
98 		break;
99 	case 2:
100 		len += snprintf(page + len, count - len, "usb_read16(0x%x)=0x%x\n", proc_get_read_addr, usb_read16(padapter, proc_get_read_addr));
101 		break;
102 	case 4:
103 		len += snprintf(page + len, count - len, "usb_read32(0x%x)=0x%x\n", proc_get_read_addr, usb_read32(padapter, proc_get_read_addr));
104 		break;
105 	default:
106 		len += snprintf(page + len, count - len, "error read length=%d\n", proc_get_read_len);
107 		break;
108 	}
109 
110 	*eof = 1;
111 	return len;
112 }
113 
proc_set_read_reg(struct file * file,const char __user * buffer,unsigned long count,void * data)114 int proc_set_read_reg(struct file *file, const char __user *buffer,
115 		unsigned long count, void *data)
116 {
117 	char tmp[16];
118 	u32 addr, len;
119 
120 	if (count < 2) {
121 		DBG_88E("argument size is less than 2\n");
122 		return -EFAULT;
123 	}
124 
125 	if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {
126 		int num = sscanf(tmp, "%x %x", &addr, &len);
127 
128 		if (num !=  2) {
129 			DBG_88E("invalid read_reg parameter!\n");
130 			return count;
131 		}
132 
133 		proc_get_read_addr = addr;
134 
135 		proc_get_read_len = len;
136 	}
137 
138 	return count;
139 }
140 
proc_get_adapter_state(char * page,char ** start,off_t offset,int count,int * eof,void * data)141 int proc_get_adapter_state(char *page, char **start,
142 			  off_t offset, int count,
143 			  int *eof, void *data)
144 {
145 	struct net_device *dev = data;
146 	struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
147 	int len = 0;
148 
149 	len += snprintf(page + len, count - len, "bSurpriseRemoved=%d, bDriverStopped=%d\n",
150 						padapter->bSurpriseRemoved, padapter->bDriverStopped);
151 
152 	*eof = 1;
153 	return len;
154 }
155 
proc_get_best_channel(char * page,char ** start,off_t offset,int count,int * eof,void * data)156 int proc_get_best_channel(char *page, char **start,
157 			  off_t offset, int count,
158 			  int *eof, void *data)
159 {
160 	struct net_device *dev = data;
161 	struct adapter *padapter = (struct adapter *)rtw_netdev_priv(dev);
162 	struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
163 	int len = 0;
164 	u32 i, best_channel_24G = 1, best_channel_5G = 36, index_24G = 0, index_5G = 0;
165 
166 	for (i = 0; pmlmeext->channel_set[i].ChannelNum != 0; i++) {
167 		if (pmlmeext->channel_set[i].ChannelNum == 1)
168 			index_24G = i;
169 		if (pmlmeext->channel_set[i].ChannelNum == 36)
170 			index_5G = i;
171 	}
172 
173 	for (i = 0; pmlmeext->channel_set[i].ChannelNum != 0; i++) {
174 		/*  2.4G */
175 		if (pmlmeext->channel_set[i].ChannelNum == 6) {
176 			if (pmlmeext->channel_set[i].rx_count < pmlmeext->channel_set[index_24G].rx_count) {
177 				index_24G = i;
178 				best_channel_24G = pmlmeext->channel_set[i].ChannelNum;
179 			}
180 		}
181 
182 		/*  5G */
183 		if (pmlmeext->channel_set[i].ChannelNum >= 36 &&
184 		    pmlmeext->channel_set[i].ChannelNum < 140) {
185 			/*  Find primary channel */
186 			if (((pmlmeext->channel_set[i].ChannelNum - 36) % 8 == 0) &&
187 			    (pmlmeext->channel_set[i].rx_count < pmlmeext->channel_set[index_5G].rx_count)) {
188 				index_5G = i;
189 				best_channel_5G = pmlmeext->channel_set[i].ChannelNum;
190 			}
191 		}
192 
193 		if (pmlmeext->channel_set[i].ChannelNum >= 149 &&
194 		    pmlmeext->channel_set[i].ChannelNum < 165) {
195 			/*  find primary channel */
196 			if (((pmlmeext->channel_set[i].ChannelNum - 149) % 8 == 0) &&
197 			    (pmlmeext->channel_set[i].rx_count < pmlmeext->channel_set[index_5G].rx_count)) {
198 				index_5G = i;
199 				best_channel_5G = pmlmeext->channel_set[i].ChannelNum;
200 			}
201 		}
202 		/*  debug */
203 		len += snprintf(page + len, count - len, "The rx cnt of channel %3d = %d\n",
204 					pmlmeext->channel_set[i].ChannelNum, pmlmeext->channel_set[i].rx_count);
205 	}
206 
207 	len += snprintf(page + len, count - len, "best_channel_5G = %d\n", best_channel_5G);
208 	len += snprintf(page + len, count - len, "best_channel_24G = %d\n", best_channel_24G);
209 
210 	*eof = 1;
211 	return len;
212 }
213