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 ******************************************************************************/
16 #include <linux/module.h>
17 #include <linux/netdevice.h>
19 #include <rtw_android.h>
20 #include <osdep_service.h>
21 #include <rtw_debug.h>
22 #include <rtw_ioctl_set.h>
24 static const char *android_wifi_cmd_str[ANDROID_WIFI_CMD_MAX] = {
57 struct android_wifi_priv_cmd {
58 const char __user *buf;
64 * Local (static) functions and variables
67 /* Initialize g_wifi_on to 1 so dhd_bus_start will be called for the first
68 * time (only) in dhd_open, subsequential wifi on will be handled by
71 static int g_wifi_on = true;
73 int rtw_android_cmdstr_to_num(char *cmdstr)
77 for (cmd_num = 0; cmd_num < ANDROID_WIFI_CMD_MAX; cmd_num++)
78 if (0 == strncasecmp(cmdstr, android_wifi_cmd_str[cmd_num],
79 strlen(android_wifi_cmd_str[cmd_num])))
84 static int rtw_android_get_rssi(struct net_device *net, char *command,
87 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(net);
88 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
89 struct wlan_network *pcur_network = &pmlmepriv->cur_network;
90 int bytes_written = 0;
92 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
93 bytes_written += snprintf(&command[bytes_written], total_len,
95 pcur_network->network.Ssid.Ssid,
96 padapter->recvpriv.rssi);
101 static int rtw_android_get_link_speed(struct net_device *net, char *command,
104 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(net);
107 link_speed = rtw_get_cur_max_rate(padapter) / 10;
108 return snprintf(command, total_len, "LinkSpeed %d",
112 static int rtw_android_get_macaddr(struct net_device *net, char *command,
115 return snprintf(command, total_len, "Macaddr = %pM",
119 static int android_set_cntry(struct net_device *net, char *command,
122 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(net);
123 char *country_code = command + strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_COUNTRY]) + 1;
126 ret = rtw_set_country(adapter, country_code);
127 return (ret == _SUCCESS) ? 0 : -1;
130 static int android_get_p2p_addr(struct net_device *net, char *command,
133 /* We use the same address as our HW MAC address */
134 memcpy(command, net->dev_addr, ETH_ALEN);
138 static int rtw_android_set_block(struct net_device *net, char *command,
144 int rtw_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
149 int bytes_written = 0;
150 struct android_wifi_priv_cmd priv_cmd;
154 if (copy_from_user(&priv_cmd, ifr->ifr_data, sizeof(priv_cmd)))
156 if (priv_cmd.total_len < 1)
158 command = memdup_user(priv_cmd.buf, priv_cmd.total_len);
160 return PTR_ERR(command);
161 command[priv_cmd.total_len - 1] = 0;
162 DBG_88E("%s: Android private cmd \"%s\" on %s\n",
163 __func__, command, ifr->ifr_name);
164 cmd_num = rtw_android_cmdstr_to_num(command);
166 case ANDROID_WIFI_CMD_START:
168 case ANDROID_WIFI_CMD_SETFWPATH:
172 DBG_88E("%s: Ignore private cmd \"%s\" - iface %s is down\n",
173 __func__, command, ifr->ifr_name);
178 case ANDROID_WIFI_CMD_STOP:
180 case ANDROID_WIFI_CMD_SCAN_ACTIVE:
182 case ANDROID_WIFI_CMD_SCAN_PASSIVE:
184 case ANDROID_WIFI_CMD_RSSI:
185 bytes_written = rtw_android_get_rssi(net, command,
188 case ANDROID_WIFI_CMD_LINKSPEED:
189 bytes_written = rtw_android_get_link_speed(net, command,
192 case ANDROID_WIFI_CMD_MACADDR:
193 bytes_written = rtw_android_get_macaddr(net, command,
196 case ANDROID_WIFI_CMD_BLOCK:
197 bytes_written = rtw_android_set_block(net, command,
200 case ANDROID_WIFI_CMD_RXFILTER_START:
202 case ANDROID_WIFI_CMD_RXFILTER_STOP:
204 case ANDROID_WIFI_CMD_RXFILTER_ADD:
206 case ANDROID_WIFI_CMD_RXFILTER_REMOVE:
208 case ANDROID_WIFI_CMD_BTCOEXSCAN_START:
209 /* TBD: BTCOEXSCAN-START */
211 case ANDROID_WIFI_CMD_BTCOEXSCAN_STOP:
212 /* TBD: BTCOEXSCAN-STOP */
214 case ANDROID_WIFI_CMD_BTCOEXMODE:
216 case ANDROID_WIFI_CMD_SETSUSPENDOPT:
218 case ANDROID_WIFI_CMD_SETBAND:
220 case ANDROID_WIFI_CMD_GETBAND:
222 case ANDROID_WIFI_CMD_COUNTRY:
223 bytes_written = android_set_cntry(net, command,
226 case ANDROID_WIFI_CMD_P2P_DEV_ADDR:
227 bytes_written = android_get_p2p_addr(net, command,
230 case ANDROID_WIFI_CMD_P2P_SET_NOA:
232 case ANDROID_WIFI_CMD_P2P_GET_NOA:
234 case ANDROID_WIFI_CMD_P2P_SET_PS:
237 DBG_88E("Unknown PRIVATE command %s - ignored\n", command);
238 snprintf(command, 3, "OK");
239 bytes_written = strlen("OK");
243 if (bytes_written >= 0) {
244 if ((bytes_written == 0) && (priv_cmd.total_len > 0))
246 if (bytes_written >= priv_cmd.total_len) {
247 DBG_88E("%s: bytes_written = %d\n", __func__,
249 bytes_written = priv_cmd.total_len;
253 priv_cmd.used_len = bytes_written;
254 if (copy_to_user((char __user *)priv_cmd.buf, command,
256 DBG_88E("%s: failed to copy data to user buffer\n",