wireless: Add ioctl cmd to setting PTA prio

Signed-off-by: zhanghongyu <zhanghongyu@xiaomi.com>
This commit is contained in:
zhanghongyu 2022-05-14 18:40:53 +08:00 committed by Xiang Xiao
parent 9dd3055014
commit 8fe295de32
4 changed files with 164 additions and 0 deletions

View File

@ -289,6 +289,17 @@ struct wpa_wconfig_s
FAR const char *passphrase; /* E.g., "mySSIDpassphrase" */
};
/* COEX *********************************************************************/
enum wapi_pta_prio_e
{
WAPI_PTA_PRIORITY_COEX_MAXIMIZED = IW_PTA_PRIORITY_COEX_MAXIMIZED,
WAPI_PTA_PRIORITY_COEX_HIGH = IW_PTA_PRIORITY_COEX_HIGH,
WAPI_PTA_PRIORITY_BALANCED = IW_PTA_PRIORITY_BALANCED,
WAPI_PTA_PRIORITY_WLAN_HIGHD = IW_PTA_PRIORITY_WLAN_HIGH,
WAPI_PTA_PRIORITY_WLAN_MAXIMIZED = IW_PTA_PRIORITY_WLAN_MAXIMIZED
};
/****************************************************************************
* Public Data
****************************************************************************/
@ -325,6 +336,10 @@ EXTERN FAR const char *g_wapi_bitrate_flags[];
EXTERN FAR const char *g_wapi_txpower_flags[];
/* PTA priority flag names. */
EXTERN FAR const char *g_wapi_pta_prio_flags[];
/****************************************************************************
* Public Function Prototyppes
****************************************************************************/
@ -889,6 +904,28 @@ int wpa_driver_wext_get_auth_param(int sockfd, FAR const char *ifname,
void wpa_driver_wext_disconnect(int sockfd, FAR const char *ifname);
/****************************************************************************
* Name: wapi_set_pta_prio
*
* Description:
* Sets the pta priority of the device.
*
****************************************************************************/
int wapi_set_pta_prio(int sock, FAR const char *ifname,
enum wapi_pta_prio_e pta_prio);
/****************************************************************************
* Name: wapi_get_pta_prio
*
* Description:
* Gets the pta priority of the device.
*
****************************************************************************/
int wapi_get_pta_prio(int sock, FAR const char *ifname,
enum wapi_pta_prio_e *pta_prio);
#undef EXTERN
#ifdef __cplusplus
}

View File

@ -241,6 +241,9 @@ FAR const char *wapi_ioctl_command_name(int cmd)
case SIOCGIWTXPOW:
return "SIOCGIWTXPOW";
case SIOCGIWPTAPRIO:
return "SIOCGIWPTAPRIO";
case SIOCSIFADDR:
return "SIOCSIFADDR";
@ -268,6 +271,9 @@ FAR const char *wapi_ioctl_command_name(int cmd)
case SIOCSIWTXPOW:
return "SIOCSIWTXPOW";
case SIOCSIWPTAPRIO:
return "SIOCSIWPTAPRIO";
default:
snprintf(g_ioctl_command_namebuf, WAPI_IOCTL_COMMAND_NAMEBUFSIZ,
"0x%x", cmd);

View File

@ -102,6 +102,7 @@ static int wapi_sense_cmd (int sock, int argc, FAR char **argv);
static int wapi_reconnect_cmd (int sock, int argc, FAR char **argv);
static int wapi_save_config_cmd (int sock, int argc, FAR char **argv);
#endif
static int wapi_pta_prio_cmd (int sock, int argc, FAR char **argv);
/****************************************************************************
* Private Data
@ -129,6 +130,7 @@ static const struct wapi_command_s g_wapi_commands[] =
{"reconnect", 1, 1, wapi_reconnect_cmd},
{"save_config", 1, 1, wapi_save_config_cmd},
#endif
{"pta_prio", 2, 2, wapi_pta_prio_cmd},
};
/****************************************************************************
@ -255,6 +257,7 @@ static int wapi_show_cmd(int sock, int argc, FAR char **argv)
char essid[WAPI_ESSID_MAX_SIZE + 1];
enum wapi_essid_flag_e essid_flag;
FAR const char *ifname = argv[0];
enum wapi_pta_prio_e pta_prio;
enum wapi_freq_flag_e freq_flag;
enum wapi_mode_e mode;
struct ether_addr ap;
@ -417,6 +420,14 @@ static int wapi_show_cmd(int sock, int argc, FAR char **argv)
printf(" Country: %s\n", country);
}
/* Get pta prio */
ret = wapi_get_pta_prio(sock, ifname, &pta_prio);
if (ret >= 0)
{
printf(" PTA prio: %d\n", pta_prio);
}
return 0;
}
@ -1009,6 +1020,30 @@ static int wapi_save_config_cmd(int sock, int argc, FAR char **argv)
}
#endif
/****************************************************************************
* Name: wapi_pta_prio_cmd
*
* Description:
* Manually configure the pta priority.
*
* Returned Value:
* None
*
****************************************************************************/
static int wapi_pta_prio_cmd(int sock, int argc, FAR char **argv)
{
enum wapi_pta_prio_e pta_prio;
/* Convert input strings to values */
pta_prio = (enum wapi_mode_e)wapi_str2ndx(argv[1], g_wapi_pta_prio_flags);
/* Set operating mode */
return wapi_set_pta_prio(sock, argv[0], pta_prio);
}
/****************************************************************************
* Name: wapi_showusage
*
@ -1051,6 +1086,8 @@ static void wapi_showusage(FAR const char *progname, int exitcode)
fprintf(stderr, "\t%s reconnect <ifname>\n", progname);
fprintf(stderr, "\t%s save_config <ifname>\n", progname);
#endif
fprintf(stderr, "\t%s pta_prio <ifname> <index/flag>\n", progname);
fprintf(stderr, "\t%s help\n", progname);
fprintf(stderr, "\nFrequency Flags:\n");
@ -1089,6 +1126,12 @@ static void wapi_showusage(FAR const char *progname, int exitcode)
fprintf(stderr, "\t[%d] %s\n", i, g_wapi_txpower_flags[i]);
}
fprintf(stderr, "\npta prio Flags:\n");
for (i = 0; g_wapi_pta_prio_flags[i]; i++)
{
fprintf(stderr, "\t[%d] %s\n", i, g_wapi_pta_prio_flags[i]);
}
exit(exitcode);
}

View File

@ -131,6 +131,18 @@ FAR const char *g_wapi_alg_flags[] =
NULL
};
/* PTA PRIORITY */
FAR const char *g_wapi_pta_prio_flags[] =
{
"WAPI_PTA_PRIORITY_COEX_MAXIMIZED",
"WAPI_PTA_PRIORITY_COEX_HIGH",
"WAPI_PTA_PRIORITY_BALANCED",
"WAPI_PTA_PRIORITY_WLAN_HIGHD",
"WAPI_PTA_PRIORITY_WLAN_MAXIMIZED",
NULL
};
/****************************************************************************
* Private Functions
****************************************************************************/
@ -1503,3 +1515,69 @@ int wapi_get_sensitivity(int sock, FAR const char *ifname, FAR int *sense)
return ret;
}
/****************************************************************************
* Name: wapi_set_pta_prio
*
* Description:
* Sets the pta priority of the device.
*
****************************************************************************/
int wapi_set_pta_prio(int sock, FAR const char *ifname,
enum wapi_pta_prio_e pta_prio)
{
struct iwreq wrq =
{
};
int ret;
wrq.u.param.value = pta_prio;
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCSIWPTAPRIO, (unsigned long)((uintptr_t)&wrq));
if (ret < 0)
{
int errcode = errno;
WAPI_IOCTL_STRERROR(SIOCSIWPTAPRIO, errcode);
ret = -errcode;
}
return ret;
}
/****************************************************************************
* Name: wapi_get_pta_prio
*
* Description:
* Gets the pta priority of the device.
*
****************************************************************************/
int wapi_get_pta_prio(int sock, FAR const char *ifname,
enum wapi_pta_prio_e *pta_prio)
{
struct iwreq wrq =
{
};
int ret;
WAPI_VALIDATE_PTR(pta_prio);
strlcpy(wrq.ifr_name, ifname, IFNAMSIZ);
ret = ioctl(sock, SIOCGIWPTAPRIO, (unsigned long)((uintptr_t)&wrq));
if (ret >= 0)
{
*pta_prio = wrq.u.param.value;
}
else
{
int errcode = errno;
WAPI_IOCTL_STRERROR(SIOCGIWPTAPRIO, errcode);
ret = -errcode;
}
return ret;
}