2013-05-08 21:45:39 +00:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright(c) 2007 - 2011 Realtek Corporation. All rights reserved.
|
2013-05-19 04:28:07 +00:00
|
|
|
*
|
2013-05-08 21:45:39 +00:00
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of version 2 of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
|
|
|
*
|
|
|
|
*
|
|
|
|
******************************************************************************/
|
|
|
|
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/netdevice.h>
|
2015-02-26 19:56:27 +00:00
|
|
|
#include <linux/version.h>
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
#include <rtw_android.h>
|
|
|
|
#include <osdep_service.h>
|
|
|
|
#include <rtw_debug.h>
|
|
|
|
#include <ioctl_cfg80211.h>
|
|
|
|
#include <rtw_ioctl_set.h>
|
|
|
|
|
2013-05-29 19:26:48 +00:00
|
|
|
static const char *android_wifi_cmd_str[ANDROID_WIFI_CMD_MAX] = {
|
2013-05-08 21:45:39 +00:00
|
|
|
"START",
|
|
|
|
"STOP",
|
|
|
|
"SCAN-ACTIVE",
|
|
|
|
"SCAN-PASSIVE",
|
|
|
|
"RSSI",
|
|
|
|
"LINKSPEED",
|
|
|
|
"RXFILTER-START",
|
|
|
|
"RXFILTER-STOP",
|
|
|
|
"RXFILTER-ADD",
|
|
|
|
"RXFILTER-REMOVE",
|
|
|
|
"BTCOEXSCAN-START",
|
|
|
|
"BTCOEXSCAN-STOP",
|
|
|
|
"BTCOEXMODE",
|
|
|
|
"SETSUSPENDOPT",
|
|
|
|
"P2P_DEV_ADDR",
|
|
|
|
"SETFWPATH",
|
|
|
|
"SETBAND",
|
|
|
|
"GETBAND",
|
|
|
|
"COUNTRY",
|
|
|
|
"P2P_SET_NOA",
|
|
|
|
"P2P_GET_NOA",
|
|
|
|
"P2P_SET_PS",
|
|
|
|
"SET_AP_WPS_P2P_IE",
|
|
|
|
"MACADDR",
|
|
|
|
"BLOCK",
|
|
|
|
"WFD-ENABLE",
|
|
|
|
"WFD-DISABLE",
|
|
|
|
"WFD-SET-TCPPORT",
|
|
|
|
"WFD-SET-MAXTPUT",
|
2013-05-19 04:28:07 +00:00
|
|
|
"WFD-SET-DEVTYPE",
|
2013-05-08 21:45:39 +00:00
|
|
|
};
|
|
|
|
|
2013-07-23 01:42:09 +00:00
|
|
|
struct android_wifi_priv_cmd {
|
2013-06-07 17:46:59 +00:00
|
|
|
const char __user *buf;
|
2013-05-08 21:45:39 +00:00
|
|
|
int used_len;
|
|
|
|
int total_len;
|
2013-07-23 01:42:09 +00:00
|
|
|
};
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Local (static) functions and variables
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* Initialize g_wifi_on to 1 so dhd_bus_start will be called for the first
|
|
|
|
* time (only) in dhd_open, subsequential wifi on will be handled by
|
|
|
|
* wl_android_wifi_on
|
|
|
|
*/
|
2013-05-26 03:02:10 +00:00
|
|
|
static int g_wifi_on = true;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
int rtw_android_cmdstr_to_num(char *cmdstr)
|
|
|
|
{
|
|
|
|
int cmd_num;
|
2015-02-24 15:42:06 +00:00
|
|
|
for(cmd_num=0; cmd_num < ANDROID_WIFI_CMD_MAX; cmd_num++)
|
|
|
|
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 0, 0))
|
|
|
|
if (!strncasecmp(cmdstr, android_wifi_cmd_str[cmd_num],
|
|
|
|
strlen(android_wifi_cmd_str[cmd_num])))
|
|
|
|
#else
|
|
|
|
if(0 == strnicmp(cmdstr, android_wifi_cmd_str[cmd_num],
|
|
|
|
strlen(android_wifi_cmd_str[cmd_num])))
|
|
|
|
#endif
|
2013-05-08 21:45:39 +00:00
|
|
|
break;
|
|
|
|
return cmd_num;
|
|
|
|
}
|
|
|
|
|
2013-08-11 03:41:06 +00:00
|
|
|
static int rtw_android_get_rssi(struct net_device *net, char *command,
|
|
|
|
int total_len)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-07-27 01:08:39 +00:00
|
|
|
struct adapter *padapter = (struct adapter *)rtw_netdev_priv(net);
|
2013-05-19 04:28:07 +00:00
|
|
|
struct mlme_priv *pmlmepriv = &(padapter->mlmepriv);
|
2013-05-08 21:45:39 +00:00
|
|
|
struct wlan_network *pcur_network = &pmlmepriv->cur_network;
|
|
|
|
int bytes_written = 0;
|
|
|
|
|
2013-08-11 03:41:06 +00:00
|
|
|
if (check_fwstate(pmlmepriv, _FW_LINKED)) {
|
|
|
|
bytes_written += snprintf(&command[bytes_written], total_len,
|
|
|
|
"%s rssi %d",
|
|
|
|
pcur_network->network.Ssid.Ssid,
|
|
|
|
padapter->recvpriv.rssi);
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
return bytes_written;
|
|
|
|
}
|
|
|
|
|
2013-08-11 03:41:06 +00:00
|
|
|
static int rtw_android_get_link_speed(struct net_device *net, char *command,
|
|
|
|
int total_len)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-07-27 01:08:39 +00:00
|
|
|
struct adapter *padapter = (struct adapter *)rtw_netdev_priv(net);
|
2013-10-19 17:45:47 +00:00
|
|
|
int bytes_written;
|
|
|
|
u16 link_speed;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
2013-10-19 17:45:47 +00:00
|
|
|
link_speed = rtw_get_cur_max_rate(padapter) / 10;
|
2013-08-11 03:41:06 +00:00
|
|
|
bytes_written = snprintf(command, total_len, "LinkSpeed %d",
|
|
|
|
link_speed);
|
2013-05-08 21:45:39 +00:00
|
|
|
return bytes_written;
|
|
|
|
}
|
|
|
|
|
2013-08-11 03:41:06 +00:00
|
|
|
static int rtw_android_get_macaddr(struct net_device *net, char *command,
|
|
|
|
int total_len)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-10-19 17:45:47 +00:00
|
|
|
int bytes_written;
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-08-11 03:41:06 +00:00
|
|
|
bytes_written = snprintf(command, total_len, "Macaddr = %pM",
|
|
|
|
net->dev_addr);
|
2013-05-08 21:45:39 +00:00
|
|
|
return bytes_written;
|
|
|
|
}
|
|
|
|
|
2013-08-11 03:41:06 +00:00
|
|
|
static int android_set_cntry(struct net_device *net, char *command,
|
|
|
|
int total_len)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-07-27 01:08:39 +00:00
|
|
|
struct adapter *adapter = (struct adapter *)rtw_netdev_priv(net);
|
2013-05-08 21:45:39 +00:00
|
|
|
char *country_code = command + strlen(android_wifi_cmd_str[ANDROID_WIFI_CMD_COUNTRY]) + 1;
|
|
|
|
int ret;
|
2013-05-19 04:28:07 +00:00
|
|
|
|
2013-05-08 21:45:39 +00:00
|
|
|
ret = rtw_set_country(adapter, country_code);
|
2013-08-11 03:41:06 +00:00
|
|
|
return (ret == _SUCCESS) ? 0 : -1;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2013-08-11 03:41:06 +00:00
|
|
|
static int android_get_p2p_addr(struct net_device *net, char *command,
|
|
|
|
int total_len)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
2013-08-11 03:41:06 +00:00
|
|
|
/* We use the same address as our HW MAC address */
|
2013-10-19 17:45:47 +00:00
|
|
|
memcpy(command, net->dev_addr, ETH_ALEN);
|
|
|
|
return ETH_ALEN;
|
2013-05-08 21:45:39 +00:00
|
|
|
}
|
|
|
|
|
2013-08-11 03:41:06 +00:00
|
|
|
static int rtw_android_set_block(struct net_device *net, char *command,
|
|
|
|
int total_len)
|
2013-05-08 21:45:39 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rtw_android_priv_cmd(struct net_device *net, struct ifreq *ifr, int cmd)
|
|
|
|
{
|
|
|
|
int ret = 0;
|
|
|
|
char *command = NULL;
|
|
|
|
int cmd_num;
|
|
|
|
int bytes_written = 0;
|
2013-07-23 01:42:09 +00:00
|
|
|
struct android_wifi_priv_cmd priv_cmd;
|
2013-05-08 21:45:39 +00:00
|
|
|
|
|
|
|
rtw_lock_suspend();
|
|
|
|
if (!ifr->ifr_data) {
|
|
|
|
ret = -EINVAL;
|
|
|
|
goto exit;
|
|
|
|
}
|
2013-08-11 03:41:06 +00:00
|
|
|
if (copy_from_user(&priv_cmd, ifr->ifr_data,
|
|
|
|
sizeof(struct android_wifi_priv_cmd))) {
|
2013-05-08 21:45:39 +00:00
|
|
|
ret = -EFAULT;
|
|
|
|
goto exit;
|
|
|
|
}
|
|
|
|
command = kmalloc(priv_cmd.total_len, GFP_KERNEL);
|
2013-08-11 03:41:06 +00:00
|
|
|
if (!command) {
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s: failed to allocate memory\n", __func__);
|
2013-05-08 21:45:39 +00:00
|
|
|
ret = -ENOMEM;
|
|
|
|
goto exit;
|
|
|
|
}
|
2019-01-08 06:46:51 +00:00
|
|
|
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0))
|
|
|
|
if (!access_ok(priv_cmd.buf, priv_cmd.total_len)) {
|
|
|
|
#else
|
2013-08-11 03:41:06 +00:00
|
|
|
if (!access_ok(VERIFY_READ, priv_cmd.buf, priv_cmd.total_len)) {
|
2019-01-08 06:46:51 +00:00
|
|
|
#endif
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("%s: failed to access memory\n", __func__);
|
2013-05-08 21:45:39 +00:00
|
|
|
ret = -EFAULT;
|
|
|
|
goto exit;
|
2013-08-11 03:41:06 +00:00
|
|
|
}
|
|
|
|
if (copy_from_user(command, (char __user *)priv_cmd.buf,
|
|
|
|
priv_cmd.total_len)) {
|
2013-05-08 21:45:39 +00:00
|
|
|
ret = -EFAULT;
|
|
|
|
goto exit;
|
|
|
|
}
|
2013-08-11 03:41:06 +00:00
|
|
|
DBG_88E("%s: Android private cmd \"%s\" on %s\n",
|
|
|
|
__func__, command, ifr->ifr_name);
|
2013-05-08 21:45:39 +00:00
|
|
|
cmd_num = rtw_android_cmdstr_to_num(command);
|
2013-05-09 04:04:25 +00:00
|
|
|
switch (cmd_num) {
|
2013-05-08 21:45:39 +00:00
|
|
|
case ANDROID_WIFI_CMD_START:
|
|
|
|
goto response;
|
|
|
|
case ANDROID_WIFI_CMD_SETFWPATH:
|
|
|
|
goto response;
|
|
|
|
}
|
|
|
|
if (!g_wifi_on) {
|
2013-08-11 03:41:06 +00:00
|
|
|
DBG_88E("%s: Ignore private cmd \"%s\" - iface %s is down\n",
|
|
|
|
__func__, command, ifr->ifr_name);
|
2013-05-08 21:45:39 +00:00
|
|
|
ret = 0;
|
|
|
|
goto exit;
|
|
|
|
}
|
2013-05-09 04:04:25 +00:00
|
|
|
switch (cmd_num) {
|
2013-05-08 21:45:39 +00:00
|
|
|
case ANDROID_WIFI_CMD_STOP:
|
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_SCAN_ACTIVE:
|
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_SCAN_PASSIVE:
|
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_RSSI:
|
2013-08-11 03:41:06 +00:00
|
|
|
bytes_written = rtw_android_get_rssi(net, command,
|
|
|
|
priv_cmd.total_len);
|
2013-05-08 21:45:39 +00:00
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_LINKSPEED:
|
2013-08-11 03:41:06 +00:00
|
|
|
bytes_written = rtw_android_get_link_speed(net, command,
|
|
|
|
priv_cmd.total_len);
|
2013-05-08 21:45:39 +00:00
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_MACADDR:
|
2013-08-11 03:41:06 +00:00
|
|
|
bytes_written = rtw_android_get_macaddr(net, command,
|
|
|
|
priv_cmd.total_len);
|
2013-05-08 21:45:39 +00:00
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_BLOCK:
|
2013-08-11 03:41:06 +00:00
|
|
|
bytes_written = rtw_android_set_block(net, command,
|
|
|
|
priv_cmd.total_len);
|
2013-05-08 21:45:39 +00:00
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_RXFILTER_START:
|
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_RXFILTER_STOP:
|
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_RXFILTER_ADD:
|
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_RXFILTER_REMOVE:
|
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_BTCOEXSCAN_START:
|
|
|
|
/* TBD: BTCOEXSCAN-START */
|
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_BTCOEXSCAN_STOP:
|
|
|
|
/* TBD: BTCOEXSCAN-STOP */
|
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_BTCOEXMODE:
|
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_SETSUSPENDOPT:
|
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_SETBAND:
|
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_GETBAND:
|
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_COUNTRY:
|
2013-08-11 03:41:06 +00:00
|
|
|
bytes_written = android_set_cntry(net, command,
|
|
|
|
priv_cmd.total_len);
|
2013-05-08 21:45:39 +00:00
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_P2P_DEV_ADDR:
|
2013-08-11 03:41:06 +00:00
|
|
|
bytes_written = android_get_p2p_addr(net, command,
|
|
|
|
priv_cmd.total_len);
|
2013-05-08 21:45:39 +00:00
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_P2P_SET_NOA:
|
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_P2P_GET_NOA:
|
|
|
|
break;
|
|
|
|
case ANDROID_WIFI_CMD_P2P_SET_PS:
|
|
|
|
break;
|
|
|
|
default:
|
2013-05-25 23:35:42 +00:00
|
|
|
DBG_88E("Unknown PRIVATE command %s - ignored\n", command);
|
2013-05-08 21:45:39 +00:00
|
|
|
snprintf(command, 3, "OK");
|
|
|
|
bytes_written = strlen("OK");
|
|
|
|
}
|
|
|
|
|
|
|
|
response:
|
|
|
|
if (bytes_written >= 0) {
|
|
|
|
if ((bytes_written == 0) && (priv_cmd.total_len > 0))
|
|
|
|
command[0] = '\0';
|
|
|
|
if (bytes_written >= priv_cmd.total_len) {
|
2013-08-11 03:41:06 +00:00
|
|
|
DBG_88E("%s: bytes_written = %d\n", __func__,
|
|
|
|
bytes_written);
|
2013-05-08 21:45:39 +00:00
|
|
|
bytes_written = priv_cmd.total_len;
|
|
|
|
} else {
|
|
|
|
bytes_written++;
|
|
|
|
}
|
|
|
|
priv_cmd.used_len = bytes_written;
|
2013-08-11 03:41:06 +00:00
|
|
|
if (copy_to_user((char __user *)priv_cmd.buf, command,
|
|
|
|
bytes_written)) {
|
|
|
|
DBG_88E("%s: failed to copy data to user buffer\n",
|
|
|
|
__func__);
|
2013-05-08 21:45:39 +00:00
|
|
|
ret = -EFAULT;
|
|
|
|
}
|
2013-05-29 19:26:48 +00:00
|
|
|
} else {
|
2013-05-08 21:45:39 +00:00
|
|
|
ret = bytes_written;
|
|
|
|
}
|
|
|
|
exit:
|
|
|
|
rtw_unlock_suspend();
|
2013-08-11 03:41:06 +00:00
|
|
|
kfree(command);
|
2013-05-08 21:45:39 +00:00
|
|
|
return ret;
|
|
|
|
}
|