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)
76 for (cmd_num = 0; cmd_num < ANDROID_WIFI_CMD_MAX; cmd_num++)
77 if (0 == strncasecmp(cmdstr, android_wifi_cmd_str[cmd_num],
78 strlen(android_wifi_cmd_str[cmd_num])))
83 static int rtw_android_get_rssi(struct net_device *net, char *command,
86 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(net);
87 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
88 struct wlan_network *pcur_network = &pmlmepriv->cur_network;
89 int bytes_written = 0;
91 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
92 bytes_written += snprintf(&command[bytes_written], total_len,
94 pcur_network->network.Ssid.Ssid,
95 padapter->recvpriv.rssi);
100 static int rtw_android_get_link_speed(struct net_device *net, char *command,
103 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(net);
106 link_speed = rtw_get_cur_max_rate(padapter) / 10;
107 return snprintf(command, total_len, "LinkSpeed %d",
111 static int rtw_android_get_macaddr(struct net_device *net, char *command,
114 return snprintf(command, total_len, "Macaddr = %pM",
118 static int android_set_cntry(struct net_device *net, char *command,
121 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(net);
122 char *country_code = command + strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_COUNTRY]) + 1;
125 ret = rtw_set_country(adapter, country_code);
126 return (ret == _SUCCESS) ? 0 : -1;
129 static int android_get_p2p_addr(struct net_device *net, char *command,
132 /* We use the same address as our HW MAC address */
133 memcpy(command, net->dev_addr, ETH_ALEN);
137 static int rtw_android_set_block(struct net_device *net, char *command,
143 int rtw_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
148 int bytes_written = 0;
149 struct android_wifi_priv_cmd priv_cmd;
153 if (copy_from_user(&priv_cmd, ifr->ifr_data, sizeof(priv_cmd)))
155 if (priv_cmd.total_len < 1)
157 command = memdup_user(priv_cmd.buf, priv_cmd.total_len);
159 return PTR_ERR(command);
160 command[priv_cmd.total_len - 1] = 0;
161 DBG_88E("%s: Android private cmd \"%s\" on %s\n",
162 __func__, command, ifr->ifr_name);
163 cmd_num = rtw_android_cmdstr_to_num(command);
165 case ANDROID_WIFI_CMD_START:
167 case ANDROID_WIFI_CMD_SETFWPATH:
171 DBG_88E("%s: Ignore private cmd \"%s\" - iface %s is down\n",
172 __func__, command, ifr->ifr_name);
177 case ANDROID_WIFI_CMD_STOP:
179 case ANDROID_WIFI_CMD_SCAN_ACTIVE:
181 case ANDROID_WIFI_CMD_SCAN_PASSIVE:
183 case ANDROID_WIFI_CMD_RSSI:
184 bytes_written = rtw_android_get_rssi(net, command,
187 case ANDROID_WIFI_CMD_LINKSPEED:
188 bytes_written = rtw_android_get_link_speed(net, command,
191 case ANDROID_WIFI_CMD_MACADDR:
192 bytes_written = rtw_android_get_macaddr(net, command,
195 case ANDROID_WIFI_CMD_BLOCK:
196 bytes_written = rtw_android_set_block(net, command,
199 case ANDROID_WIFI_CMD_RXFILTER_START:
201 case ANDROID_WIFI_CMD_RXFILTER_STOP:
203 case ANDROID_WIFI_CMD_RXFILTER_ADD:
205 case ANDROID_WIFI_CMD_RXFILTER_REMOVE:
207 case ANDROID_WIFI_CMD_BTCOEXSCAN_START:
208 /* TBD: BTCOEXSCAN-START */
210 case ANDROID_WIFI_CMD_BTCOEXSCAN_STOP:
211 /* TBD: BTCOEXSCAN-STOP */
213 case ANDROID_WIFI_CMD_BTCOEXMODE:
215 case ANDROID_WIFI_CMD_SETSUSPENDOPT:
217 case ANDROID_WIFI_CMD_SETBAND:
219 case ANDROID_WIFI_CMD_GETBAND:
221 case ANDROID_WIFI_CMD_COUNTRY:
222 bytes_written = android_set_cntry(net, command,
225 case ANDROID_WIFI_CMD_P2P_DEV_ADDR:
226 bytes_written = android_get_p2p_addr(net, command,
229 case ANDROID_WIFI_CMD_P2P_SET_NOA:
231 case ANDROID_WIFI_CMD_P2P_GET_NOA:
233 case ANDROID_WIFI_CMD_P2P_SET_PS:
236 DBG_88E("Unknown PRIVATE command %s - ignored\n", command);
237 snprintf(command, 3, "OK");
238 bytes_written = strlen("OK");
242 if (bytes_written >= 0) {
243 if ((bytes_written == 0) && (priv_cmd.total_len > 0))
245 if (bytes_written >= priv_cmd.total_len) {
246 DBG_88E("%s: bytes_written = %d\n", __func__,
248 bytes_written = priv_cmd.total_len;
252 priv_cmd.used_len = bytes_written;
253 if (copy_to_user((char __user *)priv_cmd.buf, command,
255 DBG_88E("%s: failed to copy data to user buffer\n",