Skip to content

[wlan] add get_info api for more new sta information #9837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions components/drivers/wlan/dev_wlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2018-08-03 tyx the first version
* 2024-12-25 Evlers add get_info api for more new sta information
*/

#include <rthw.h>
Expand Down Expand Up @@ -249,6 +250,25 @@ int rt_wlan_dev_get_rssi(struct rt_wlan_device *device)
return rssi;
}

rt_err_t rt_wlan_dev_get_info(struct rt_wlan_device *device, struct rt_wlan_info *info)
{
rt_err_t result = RT_EOK;

if (device == RT_NULL)
{
return -RT_EIO;
}

result = rt_device_control(RT_DEVICE(device), RT_WLAN_CMD_GET_INFO, info);
if (result != RT_EOK)
{
rt_set_errno(result);
return 0;
}

return result;
}

rt_err_t rt_wlan_dev_get_mac(struct rt_wlan_device *device, rt_uint8_t mac[6])
{
rt_err_t result = RT_EOK;
Expand Down Expand Up @@ -784,6 +804,17 @@ static rt_err_t _rt_wlan_dev_control(rt_device_t dev, int cmd, void *args)
*rssi = wlan->ops->wlan_get_rssi(wlan);
break;
}
case RT_WLAN_CMD_GET_INFO:
{
struct rt_wlan_info *info = args;

LOG_D("%s %d cmd[%d]:%s run......", __FUNCTION__, __LINE__, RT_WLAN_CMD_GET_INFO, "RT_WLAN_CMD_GET_INFO");
if (wlan->ops->wlan_get_info)
err = wlan->ops->wlan_get_info(wlan, info);
else
err = -RT_ERROR;
break;
}
case RT_WLAN_CMD_SET_POWERSAVE:
{
int level = *((int *)args);
Expand Down
6 changes: 6 additions & 0 deletions components/drivers/wlan/dev_wlan.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
* Change Logs:
* Date Author Notes
* 2018-08-03 tyx the first version
* 2024-12-25 Evlers add get_info api for more new sta information
*/

#ifndef __DEV_WLAN_DEVICE_H__
Expand All @@ -15,6 +16,8 @@
extern "C" {
#endif

#define RT_WLAN_DEV_VERSION 0x10000 /* 1.0.0 */

typedef enum
{
RT_WLAN_NONE,
Expand All @@ -34,6 +37,7 @@ typedef enum
RT_WLAN_CMD_AP_DEAUTH,
RT_WLAN_CMD_SCAN_STOP,
RT_WLAN_CMD_GET_RSSI, /* get sensitivity (dBm) */
RT_WLAN_CMD_GET_INFO, /* get information (rssi, channel, datarate.) */
RT_WLAN_CMD_SET_POWERSAVE,
RT_WLAN_CMD_GET_POWERSAVE,
RT_WLAN_CMD_CFG_PROMISC, /* start/stop minitor */
Expand Down Expand Up @@ -497,6 +501,7 @@ struct rt_wlan_dev_ops
rt_err_t (*wlan_ap_deauth)(struct rt_wlan_device *wlan, rt_uint8_t mac[]);
rt_err_t (*wlan_scan_stop)(struct rt_wlan_device *wlan);
int (*wlan_get_rssi)(struct rt_wlan_device *wlan);
int (*wlan_get_info)(struct rt_wlan_device *wlan, struct rt_wlan_info *info);
rt_err_t (*wlan_set_powersave)(struct rt_wlan_device *wlan, int level);
int (*wlan_get_powersave)(struct rt_wlan_device *wlan);
rt_err_t (*wlan_cfg_promisc)(struct rt_wlan_device *wlan, rt_bool_t start);
Expand Down Expand Up @@ -527,6 +532,7 @@ rt_err_t rt_wlan_dev_connect(struct rt_wlan_device *device, struct rt_wlan_info
rt_err_t rt_wlan_dev_fast_connect(struct rt_wlan_device *device, struct rt_wlan_info *info, const char *password, int password_len);
rt_err_t rt_wlan_dev_disconnect(struct rt_wlan_device *device);
int rt_wlan_dev_get_rssi(struct rt_wlan_device *device);
rt_err_t rt_wlan_dev_get_info(struct rt_wlan_device *device, struct rt_wlan_info *info);

/*
* wlan device ap interface
Expand Down
9 changes: 8 additions & 1 deletion components/drivers/wlan/dev_wlan_mgnt.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Date Author Notes
* 2018-08-06 tyx the first version
* 2023-12-12 Evlers add the wlan join scan function
* 2024-12-25 Evlers add get_info api for more new sta information
*/

#include <rthw.h>
Expand Down Expand Up @@ -1185,8 +1186,14 @@ rt_err_t rt_wlan_get_info(struct rt_wlan_info *info)

if (rt_wlan_is_connected() == RT_TRUE)
{
/* Initialize the information to the scan first */
*info = _sta_mgnt.info;
info->rssi = rt_wlan_get_rssi();
/* Try using get_info's API for more new information */
if (rt_wlan_dev_get_info(STA_DEVICE(), info) != RT_EOK)
{
/* The get_info returns an error and gets the rssi value separately */
info->rssi = rt_wlan_get_rssi();
}
return RT_EOK;
}
return -RT_ERROR;
Expand Down
Loading