wireless/wapi: add get country code support

Country command with no args to get the ccode:

Get country code:
cp> wapi country wlan0
CN

Set country code:
cp> wapi country wlan0 JP

Get country code:
cp> wapi country wlan0
JP

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2022-06-23 14:44:38 +08:00 committed by Xiang Xiao
parent 23f35ea1b3
commit 61250d5516
3 changed files with 70 additions and 2 deletions

View File

@ -731,6 +731,17 @@ void wapi_scan_coll_free(FAR struct wapi_list_s *aps);
int wapi_set_country(int sock, FAR const char *ifname,
FAR const char *country);
/****************************************************************************
* Name: wapi_get_country
*
* Description:
* Get the country code
*
****************************************************************************/
int wapi_get_country(int sock, FAR const char *ifname,
FAR char *country);
/****************************************************************************
* Name: wapi_get_sensitivity
*

View File

@ -123,7 +123,7 @@ static const struct wapi_command_s g_wapi_commands[] =
{"ap", 2, 2, wapi_ap_cmd},
{"bitrate", 3, 3, wapi_bitrate_cmd},
{"txpower", 3, 3, wapi_txpower_cmd},
{"country", 2, 2, wapi_country_cmd},
{"country", 1, 2, wapi_country_cmd},
{"sense", 1, 1, wapi_sense_cmd},
#ifdef CONFIG_WIRELESS_WAPI_INITCONF
{"reconnect", 1, 1, wapi_reconnect_cmd},
@ -259,6 +259,7 @@ static int wapi_show_cmd(int sock, int argc, FAR char **argv)
enum wapi_mode_e mode;
struct ether_addr ap;
struct in_addr addr;
char country[4];
double tmpfreq;
int bitrate;
int txpower;
@ -404,6 +405,15 @@ static int wapi_show_cmd(int sock, int argc, FAR char **argv)
printf(" Sense: %d\n", sense);
}
/* Get Country Code */
memset(country, 0, sizeof(country));
ret = wapi_get_country(sock, ifname, country);
if (ret == 0)
{
printf(" Country: %s\n", country);
}
return 0;
}
@ -806,7 +816,7 @@ static int wapi_scan_cmd(int sock, int argc, FAR char **argv)
* Name: wapi_country_cmd
*
* Description:
* Set the country code
* Set/Get the country code
*
* Returned Value:
* None
@ -815,6 +825,20 @@ static int wapi_scan_cmd(int sock, int argc, FAR char **argv)
static int wapi_country_cmd(int sock, int argc, FAR char **argv)
{
char country[4];
int ret;
if (argc == 1)
{
ret = wapi_get_country(sock, argv[0], country);
if (ret == 0)
{
printf("%s\n", country);
}
return ret;
}
return wapi_set_country(sock, argv[0], argv[1]);
}

View File

@ -1440,6 +1440,39 @@ int wapi_set_country(int sock, FAR const char *ifname,
return ret;
}
/****************************************************************************
* Name: wapi_get_country
*
* Description:
* Get the country code
*
****************************************************************************/
int wapi_get_country(int sock, FAR const char *ifname,
FAR char *country)
{
struct iwreq wrq =
{
};
int ret;
/* Prepare request. */
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
wrq.u.data.pointer = (FAR void *)country;
wrq.u.data.length = 2;
ret = ioctl(sock, SIOCGIWCOUNTRY, (unsigned long)((uintptr_t)&wrq));
if (ret < 0)
{
int errcode = errno;
WAPI_IOCTL_STRERROR(SIOCGIWSENS, errcode);
ret = -errcode;
}
return ret;
}
/****************************************************************************
* Name: wapi_get_sensitivity
*