1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
4 * Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
6 ******************************************************************************/
8 #include <linux/module.h>
9 #include <linux/netdevice.h>
11 #include <rtw_android.h>
12 #include <osdep_service.h>
13 #include <rtw_debug.h>
14 #include <rtw_ioctl_set.h>
16 static const char *android_wifi_cmd_str[ANDROID_WIFI_CMD_MAX] = {
49 struct android_wifi_priv_cmd {
50 const char __user *buf;
56 * Local (static) functions and variables
59 /* Initialize g_wifi_on to 1 so dhd_bus_start will be called for the first
60 * time (only) in dhd_open, subsequential wifi on will be handled by
63 static int g_wifi_on = true;
65 int rtw_android_cmdstr_to_num(char *cmdstr)
69 for (cmd_num = 0; cmd_num < ANDROID_WIFI_CMD_MAX; cmd_num++)
70 if (0 == strncasecmp(cmdstr, android_wifi_cmd_str[cmd_num],
71 strlen(android_wifi_cmd_str[cmd_num])))
76 static int rtw_android_get_rssi(struct net_device *net, char *command,
79 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(net);
80 struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
81 struct wlan_network *pcur_network = &pmlmepriv->cur_network;
82 int bytes_written = 0;
84 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
85 bytes_written += snprintf(&command[bytes_written], total_len,
87 pcur_network->network.Ssid.Ssid,
88 padapter->recvpriv.rssi);
93 static int rtw_android_get_link_speed(struct net_device *net, char *command,
96 struct adapter *padapter = (struct adapter *)rtw_netdev_priv(net);
99 link_speed = rtw_get_cur_max_rate(padapter) / 10;
100 return snprintf(command, total_len, "LinkSpeed %d",
104 static int rtw_android_get_macaddr(struct net_device *net, char *command,
107 return snprintf(command, total_len, "Macaddr = %pM",
111 static int android_set_cntry(struct net_device *net, char *command,
114 struct adapter *adapter = (struct adapter *)rtw_netdev_priv(net);
115 char *country_code = command + strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_COUNTRY]) + 1;
118 ret = rtw_set_country(adapter, country_code);
119 return (ret == _SUCCESS) ? 0 : -1;
122 static int android_get_p2p_addr(struct net_device *net, char *command,
125 /* We use the same address as our HW MAC address */
126 memcpy(command, net->dev_addr, ETH_ALEN);
130 static int rtw_android_set_block(struct net_device *net, char *command,
136 int rtw_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
141 int bytes_written = 0;
142 struct android_wifi_priv_cmd priv_cmd;
146 if (copy_from_user(&priv_cmd, ifr->ifr_data, sizeof(priv_cmd)))
148 if (priv_cmd.total_len < 1)
150 command = memdup_user(priv_cmd.buf, priv_cmd.total_len);
152 return PTR_ERR(command);
153 command[priv_cmd.total_len - 1] = 0;
154 DBG_88E("%s: Android private cmd \"%s\" on %s\n",
155 __func__, command, ifr->ifr_name);
156 cmd_num = rtw_android_cmdstr_to_num(command);
158 case ANDROID_WIFI_CMD_START:
160 case ANDROID_WIFI_CMD_SETFWPATH:
164 DBG_88E("%s: Ignore private cmd \"%s\" - iface %s is down\n",
165 __func__, command, ifr->ifr_name);
170 case ANDROID_WIFI_CMD_STOP:
172 case ANDROID_WIFI_CMD_SCAN_ACTIVE:
174 case ANDROID_WIFI_CMD_SCAN_PASSIVE:
176 case ANDROID_WIFI_CMD_RSSI:
177 bytes_written = rtw_android_get_rssi(net, command,
180 case ANDROID_WIFI_CMD_LINKSPEED:
181 bytes_written = rtw_android_get_link_speed(net, command,
184 case ANDROID_WIFI_CMD_MACADDR:
185 bytes_written = rtw_android_get_macaddr(net, command,
188 case ANDROID_WIFI_CMD_BLOCK:
189 bytes_written = rtw_android_set_block(net, command,
192 case ANDROID_WIFI_CMD_RXFILTER_START:
194 case ANDROID_WIFI_CMD_RXFILTER_STOP:
196 case ANDROID_WIFI_CMD_RXFILTER_ADD:
198 case ANDROID_WIFI_CMD_RXFILTER_REMOVE:
200 case ANDROID_WIFI_CMD_BTCOEXSCAN_START:
201 /* TBD: BTCOEXSCAN-START */
203 case ANDROID_WIFI_CMD_BTCOEXSCAN_STOP:
204 /* TBD: BTCOEXSCAN-STOP */
206 case ANDROID_WIFI_CMD_BTCOEXMODE:
208 case ANDROID_WIFI_CMD_SETSUSPENDOPT:
210 case ANDROID_WIFI_CMD_SETBAND:
212 case ANDROID_WIFI_CMD_GETBAND:
214 case ANDROID_WIFI_CMD_COUNTRY:
215 bytes_written = android_set_cntry(net, command,
218 case ANDROID_WIFI_CMD_P2P_DEV_ADDR:
219 bytes_written = android_get_p2p_addr(net, command,
222 case ANDROID_WIFI_CMD_P2P_SET_NOA:
224 case ANDROID_WIFI_CMD_P2P_GET_NOA:
226 case ANDROID_WIFI_CMD_P2P_SET_PS:
229 DBG_88E("Unknown PRIVATE command %s - ignored\n", command);
230 snprintf(command, 3, "OK");
231 bytes_written = strlen("OK");
235 if (bytes_written >= 0) {
236 if ((bytes_written == 0) && (priv_cmd.total_len > 0))
238 if (bytes_written >= priv_cmd.total_len) {
239 DBG_88E("%s: bytes_written = %d\n", __func__,
241 bytes_written = priv_cmd.total_len;
245 priv_cmd.used_len = bytes_written;
246 if (copy_to_user((char __user *)priv_cmd.buf, command,
248 DBG_88E("%s: failed to copy data to user buffer\n",