mirror of
https://github.com/apache/nuttx.git
synced 2025-01-13 13:18:50 +08:00
simwifi: Support the ioctl of SIOCGIWENCODEEXT and SIOCGIWSENS.
Signed-off-by: liqinhui <liqinhui@xiaomi.com>
This commit is contained in:
parent
be942853c4
commit
01b39074a2
1 changed files with 99 additions and 9 deletions
|
@ -161,7 +161,7 @@ struct sim_netdev_s
|
|||
char bssid[ETH_ALEN];
|
||||
uint16_t channel;
|
||||
uint32_t freq;
|
||||
uint8_t password[64];
|
||||
char password[64];
|
||||
int key_mgmt;
|
||||
int proto;
|
||||
int auth_alg;
|
||||
|
@ -926,6 +926,23 @@ static bool get_wpa_bssid(struct sim_netdev_s *wifidev,
|
|||
return false;
|
||||
}
|
||||
|
||||
static bool get_wpa_rssi(struct sim_netdev_s *wifidev, int32_t *rssi)
|
||||
{
|
||||
int ret;
|
||||
char rbuf[BUF_LEN];
|
||||
|
||||
ret = host_system(rbuf, BUF_LEN, "iwconfig wlan%d | grep level "
|
||||
"| awk '{print $4}'| awk -F'=' '{print $2}'",
|
||||
wifidev->devidx);
|
||||
if (ret > 0)
|
||||
{
|
||||
*rssi = atoi(rbuf);
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
static void get_wpa_ssid(struct sim_netdev_s *wifidev,
|
||||
struct iw_point *essid)
|
||||
{
|
||||
|
@ -1192,16 +1209,16 @@ static int wifidriver_get_auth(struct sim_netdev_s *wifidev,
|
|||
static int wifidriver_set_psk(struct sim_netdev_s *wifidev,
|
||||
struct iwreq *pwrq)
|
||||
{
|
||||
char psk_buf[64];
|
||||
struct iw_encode_ext *ext;
|
||||
int ret = 0;
|
||||
|
||||
ext = (struct iw_encode_ext *)pwrq->u.encoding.pointer;
|
||||
|
||||
memset(psk_buf, 0, sizeof(psk_buf));
|
||||
memcpy(psk_buf, ext->key, ext->key_len);
|
||||
memset(wifidev->password, 0, sizeof(wifidev->password));
|
||||
memcpy(wifidev->password, ext->key, ext->key_len);
|
||||
|
||||
ninfo("psk=%s, key_len= %d, alg=%u\n", psk_buf, ext->key_len, ext->alg);
|
||||
ninfo("psk=%s, key_len= %d, alg=%u\n", wifidev->password,
|
||||
ext->key_len, ext->alg);
|
||||
|
||||
/* set auth_alg */
|
||||
|
||||
|
@ -1216,11 +1233,13 @@ static int wifidriver_set_psk(struct sim_netdev_s *wifidev,
|
|||
return -ENOSYS;
|
||||
}
|
||||
|
||||
wifidev->auth_alg = ext->alg;
|
||||
|
||||
switch (wifidev->mode)
|
||||
{
|
||||
case IW_MODE_INFRA:
|
||||
WPA_SET_NETWORK(wifidev, "auth_alg %s", get_auth_algstr(ext->alg));
|
||||
WPA_SET_NETWORK(wifidev, "psk \\\"%s\\\"", psk_buf);
|
||||
WPA_SET_NETWORK(wifidev, "psk \\\"%s\\\"", wifidev->password);
|
||||
WPA_SET_NETWORK(wifidev, "key_mgmt %s", "WPA-PSK WPA-EAP");
|
||||
|
||||
/* Set the psk flag for security ap. */
|
||||
|
@ -1231,7 +1250,7 @@ static int wifidriver_set_psk(struct sim_netdev_s *wifidev,
|
|||
|
||||
/* set wpa_passphrase psk_buf */
|
||||
|
||||
ret = set_cmd(wifidev, "set wpa_passphrase %s", psk_buf);
|
||||
ret = set_cmd(wifidev, "set wpa_passphrase %s", wifidev->password);
|
||||
wifidev->psk_flag = 1;
|
||||
break;
|
||||
default:
|
||||
|
@ -1241,6 +1260,42 @@ static int wifidriver_set_psk(struct sim_netdev_s *wifidev,
|
|||
return ret ;
|
||||
}
|
||||
|
||||
static int wifidriver_get_psk(struct sim_netdev_s *wifidev,
|
||||
struct iwreq *pwrq)
|
||||
{
|
||||
struct iw_encode_ext *ext;
|
||||
int ret = 0;
|
||||
int len;
|
||||
int size;
|
||||
|
||||
ext = (struct iw_encode_ext *)pwrq->u.encoding.pointer;
|
||||
len = pwrq->u.encoding.length - sizeof(*ext);
|
||||
|
||||
switch (wifidev->mode)
|
||||
{
|
||||
case IW_MODE_INFRA:
|
||||
size = strnlen(wifidev->password, 64);
|
||||
if (len < size)
|
||||
{
|
||||
return -EINVAL;
|
||||
}
|
||||
else
|
||||
{
|
||||
ext->key_len = size;
|
||||
memcpy(ext->key, wifidev->password, ext->key_len);
|
||||
ext->alg = wifidev->auth_alg;
|
||||
}
|
||||
break;
|
||||
|
||||
case IW_MODE_MASTER:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return ret ;
|
||||
}
|
||||
|
||||
static int wifidriver_set_essid(struct sim_netdev_s *wifidev,
|
||||
struct iwreq *pwrq)
|
||||
{
|
||||
|
@ -1603,6 +1658,32 @@ static int wifidriver_get_country(struct sim_netdev_s *wifidev,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static int wifidriver_get_sensitivity(struct sim_netdev_s *wifidev,
|
||||
struct iwreq *pwrq)
|
||||
{
|
||||
int32_t rssi;
|
||||
int ret;
|
||||
|
||||
if (wifidev->mode != IW_MODE_INFRA)
|
||||
{
|
||||
return OK;
|
||||
}
|
||||
|
||||
if (get_wpa_state(wifidev) && get_wpa_rssi(wifidev, &rssi))
|
||||
{
|
||||
pwrq->u.sens.value = -rssi;
|
||||
ret = OK;
|
||||
|
||||
ninfo("get rssi is %"PRId32 "\n", pwrq->u.sens.value);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -ENOTTY;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
int wifidriver_set_freq(struct sim_netdev_s *wifidev, struct iwreq *pwrq)
|
||||
{
|
||||
int channel;
|
||||
|
@ -1751,7 +1832,7 @@ static int wifidriver_passwd(struct netdev_lowerhalf_s *dev,
|
|||
}
|
||||
else
|
||||
{
|
||||
return -ENOTTY;
|
||||
return wifidriver_get_psk((struct sim_netdev_s *)dev, iwr);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1830,7 +1911,16 @@ static int wifidriver_country(struct netdev_lowerhalf_s *dev,
|
|||
static int wifidriver_sensitivity(struct netdev_lowerhalf_s *dev,
|
||||
struct iwreq *iwr, bool set)
|
||||
{
|
||||
return -ENOTTY;
|
||||
struct sim_netdev_s *wifidev = (struct sim_netdev_s *)dev;
|
||||
|
||||
if (set)
|
||||
{
|
||||
return -ENOTTY;
|
||||
}
|
||||
else
|
||||
{
|
||||
return wifidriver_get_sensitivity(wifidev, iwr);
|
||||
}
|
||||
}
|
||||
|
||||
static int wifidriver_scan(struct netdev_lowerhalf_s *dev,
|
||||
|
|
Loading…
Reference in a new issue