1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
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.
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
14 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
21 #include <linux/module.h>
22 #include <linux/netdevice.h>
24 #include <rtw_android.h>
25 #include <osdep_service.h>
26 #include <rtw_debug.h>
27 #include <rtw_ioctl_set.h>
29 static const char *android_wifi_cmd_str[ANDROID_WIFI_CMD_MAX] = {
62 struct android_wifi_priv_cmd {
63 const char __user *buf;
69 * Local (static) functions and variables
72 /* Initialize g_wifi_on to 1 so dhd_bus_start will be called for the first
73 * time (only) in dhd_open, subsequential wifi on will be handled by
76 static int g_wifi_on = true;
78 int rtw_android_cmdstr_to_num(char *cmdstr)
81 for (cmd_num = 0; cmd_num < ANDROID_WIFI_CMD_MAX; cmd_num++)
82 if (0 == strnicmp(cmdstr , android_wifi_cmd_str[cmd_num],
83 strlen(android_wifi_cmd_str[cmd_num])))
88 static int rtw_android_get_rssi(struct net_device *net, char *command,
91 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(net);
92 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
93 struct wlan_network *pcur_network = &pmlmepriv->cur_network;
94 int bytes_written = 0;
96 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
97 bytes_written += snprintf(&command[bytes_written], total_len,
99 pcur_network->network.Ssid.Ssid,
100 padapter->recvpriv.rssi);
102 return bytes_written;
105 static int rtw_android_get_link_speed(struct net_device *net, char *command,
108 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(net);
111 link_speed = rtw_get_cur_max_rate(padapter) / 10;
112 return snprintf(command, total_len, "LinkSpeed %d",
116 static int rtw_android_get_macaddr(struct net_device *net, char *command,
119 return snprintf(command, total_len, "Macaddr = %pM",
123 static int android_set_cntry(struct net_device *net, char *command,
126 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(net);
127 char *country_code = command + strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_COUNTRY]) + 1;
130 ret = rtw_set_country(adapter, country_code);
131 return (ret == _SUCCESS) ? 0 : -1;
134 static int android_get_p2p_addr(struct net_device *net, char *command,
137 /* We use the same address as our HW MAC address */
138 memcpy(command, net->dev_addr, ETH_ALEN);
142 static int rtw_android_set_block(struct net_device *net, char *command,
148 int rtw_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
151 char *command = NULL;
153 int bytes_written = 0;
154 struct android_wifi_priv_cmd priv_cmd;
156 if (!ifr->ifr_data) {
160 if (copy_from_user(&priv_cmd, ifr->ifr_data,
161 sizeof(struct android_wifi_priv_cmd))) {
165 command = kmalloc(priv_cmd.total_len, GFP_KERNEL);
167 DBG_88E("%s: failed to allocate memory\n", __func__);
171 if (!access_ok(VERIFY_READ, priv_cmd.buf, priv_cmd.total_len)) {
172 DBG_88E("%s: failed to access memory\n", __func__);
176 if (copy_from_user(command, (char __user *)priv_cmd.buf,
177 priv_cmd.total_len)) {
181 DBG_88E("%s: Android private cmd \"%s\" on %s\n",
182 __func__, command, ifr->ifr_name);
183 cmd_num = rtw_android_cmdstr_to_num(command);
185 case ANDROID_WIFI_CMD_START:
187 case ANDROID_WIFI_CMD_SETFWPATH:
191 DBG_88E("%s: Ignore private cmd \"%s\" - iface %s is down\n",
192 __func__, command, ifr->ifr_name);
197 case ANDROID_WIFI_CMD_STOP:
199 case ANDROID_WIFI_CMD_SCAN_ACTIVE:
201 case ANDROID_WIFI_CMD_SCAN_PASSIVE:
203 case ANDROID_WIFI_CMD_RSSI:
204 bytes_written = rtw_android_get_rssi(net, command,
207 case ANDROID_WIFI_CMD_LINKSPEED:
208 bytes_written = rtw_android_get_link_speed(net, command,
211 case ANDROID_WIFI_CMD_MACADDR:
212 bytes_written = rtw_android_get_macaddr(net, command,
215 case ANDROID_WIFI_CMD_BLOCK:
216 bytes_written = rtw_android_set_block(net, command,
219 case ANDROID_WIFI_CMD_RXFILTER_START:
221 case ANDROID_WIFI_CMD_RXFILTER_STOP:
223 case ANDROID_WIFI_CMD_RXFILTER_ADD:
225 case ANDROID_WIFI_CMD_RXFILTER_REMOVE:
227 case ANDROID_WIFI_CMD_BTCOEXSCAN_START:
228 /* TBD: BTCOEXSCAN-START */
230 case ANDROID_WIFI_CMD_BTCOEXSCAN_STOP:
231 /* TBD: BTCOEXSCAN-STOP */
233 case ANDROID_WIFI_CMD_BTCOEXMODE:
235 case ANDROID_WIFI_CMD_SETSUSPENDOPT:
237 case ANDROID_WIFI_CMD_SETBAND:
239 case ANDROID_WIFI_CMD_GETBAND:
241 case ANDROID_WIFI_CMD_COUNTRY:
242 bytes_written = android_set_cntry(net, command,
245 case ANDROID_WIFI_CMD_P2P_DEV_ADDR:
246 bytes_written = android_get_p2p_addr(net, command,
249 case ANDROID_WIFI_CMD_P2P_SET_NOA:
251 case ANDROID_WIFI_CMD_P2P_GET_NOA:
253 case ANDROID_WIFI_CMD_P2P_SET_PS:
256 DBG_88E("Unknown PRIVATE command %s - ignored\n", command);
257 snprintf(command, 3, "OK");
258 bytes_written = strlen("OK");
262 if (bytes_written >= 0) {
263 if ((bytes_written == 0) && (priv_cmd.total_len > 0))
265 if (bytes_written >= priv_cmd.total_len) {
266 DBG_88E("%s: bytes_written = %d\n", __func__,
268 bytes_written = priv_cmd.total_len;
272 priv_cmd.used_len = bytes_written;
273 if (copy_to_user((char __user *)priv_cmd.buf, command,
275 DBG_88E("%s: failed to copy data to user buffer\n",