Skip to content

Commit c75e095

Browse files
EvlersRbb666
authored andcommitted
[wlan] add get_info api for more new sta information
1 parent 0932e31 commit c75e095

File tree

3 files changed

+45
-1
lines changed

3 files changed

+45
-1
lines changed

components/drivers/wlan/dev_wlan.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2018-08-03 tyx the first version
9+
* 2024-12-25 Evlers add get_info api for more new sta information
910
*/
1011

1112
#include <rthw.h>
@@ -249,6 +250,25 @@ int rt_wlan_dev_get_rssi(struct rt_wlan_device *device)
249250
return rssi;
250251
}
251252

253+
rt_err_t rt_wlan_dev_get_info(struct rt_wlan_device *device, struct rt_wlan_info *info)
254+
{
255+
rt_err_t result = RT_EOK;
256+
257+
if (device == RT_NULL)
258+
{
259+
return -RT_EIO;
260+
}
261+
262+
result = rt_device_control(RT_DEVICE(device), RT_WLAN_CMD_GET_INFO, info);
263+
if (result != RT_EOK)
264+
{
265+
rt_set_errno(result);
266+
return 0;
267+
}
268+
269+
return result;
270+
}
271+
252272
rt_err_t rt_wlan_dev_get_mac(struct rt_wlan_device *device, rt_uint8_t mac[6])
253273
{
254274
rt_err_t result = RT_EOK;
@@ -784,6 +804,17 @@ static rt_err_t _rt_wlan_dev_control(rt_device_t dev, int cmd, void *args)
784804
*rssi = wlan->ops->wlan_get_rssi(wlan);
785805
break;
786806
}
807+
case RT_WLAN_CMD_GET_INFO:
808+
{
809+
struct rt_wlan_info *info = args;
810+
811+
LOG_D("%s %d cmd[%d]:%s run......", __FUNCTION__, __LINE__, RT_WLAN_CMD_GET_INFO, "RT_WLAN_CMD_GET_INFO");
812+
if (wlan->ops->wlan_get_info)
813+
err = wlan->ops->wlan_get_info(wlan, info);
814+
else
815+
err = -RT_ERROR;
816+
break;
817+
}
787818
case RT_WLAN_CMD_SET_POWERSAVE:
788819
{
789820
int level = *((int *)args);

components/drivers/wlan/dev_wlan.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
* Change Logs:
77
* Date Author Notes
88
* 2018-08-03 tyx the first version
9+
* 2024-12-25 Evlers add get_info api for more new sta information
910
*/
1011

1112
#ifndef __DEV_WLAN_DEVICE_H__
@@ -15,6 +16,8 @@
1516
extern "C" {
1617
#endif
1718

19+
#define RT_WLAN_DEV_VERSION 0x10000 /* 1.0.0 */
20+
1821
typedef enum
1922
{
2023
RT_WLAN_NONE,
@@ -34,6 +37,7 @@ typedef enum
3437
RT_WLAN_CMD_AP_DEAUTH,
3538
RT_WLAN_CMD_SCAN_STOP,
3639
RT_WLAN_CMD_GET_RSSI, /* get sensitivity (dBm) */
40+
RT_WLAN_CMD_GET_INFO, /* get information (rssi, channel, datarate.) */
3741
RT_WLAN_CMD_SET_POWERSAVE,
3842
RT_WLAN_CMD_GET_POWERSAVE,
3943
RT_WLAN_CMD_CFG_PROMISC, /* start/stop minitor */
@@ -497,6 +501,7 @@ struct rt_wlan_dev_ops
497501
rt_err_t (*wlan_ap_deauth)(struct rt_wlan_device *wlan, rt_uint8_t mac[]);
498502
rt_err_t (*wlan_scan_stop)(struct rt_wlan_device *wlan);
499503
int (*wlan_get_rssi)(struct rt_wlan_device *wlan);
504+
int (*wlan_get_info)(struct rt_wlan_device *wlan, struct rt_wlan_info *info);
500505
rt_err_t (*wlan_set_powersave)(struct rt_wlan_device *wlan, int level);
501506
int (*wlan_get_powersave)(struct rt_wlan_device *wlan);
502507
rt_err_t (*wlan_cfg_promisc)(struct rt_wlan_device *wlan, rt_bool_t start);
@@ -527,6 +532,7 @@ rt_err_t rt_wlan_dev_connect(struct rt_wlan_device *device, struct rt_wlan_info
527532
rt_err_t rt_wlan_dev_fast_connect(struct rt_wlan_device *device, struct rt_wlan_info *info, const char *password, int password_len);
528533
rt_err_t rt_wlan_dev_disconnect(struct rt_wlan_device *device);
529534
int rt_wlan_dev_get_rssi(struct rt_wlan_device *device);
535+
rt_err_t rt_wlan_dev_get_info(struct rt_wlan_device *device, struct rt_wlan_info *info);
530536

531537
/*
532538
* wlan device ap interface

components/drivers/wlan/dev_wlan_mgnt.c

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
* Date Author Notes
88
* 2018-08-06 tyx the first version
99
* 2023-12-12 Evlers add the wlan join scan function
10+
* 2024-12-25 Evlers add get_info api for more new sta information
1011
*/
1112

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

11861187
if (rt_wlan_is_connected() == RT_TRUE)
11871188
{
1189+
/* Initialize the information to the scan first */
11881190
*info = _sta_mgnt.info;
1189-
info->rssi = rt_wlan_get_rssi();
1191+
/* Try using get_info's API for more new information */
1192+
if (rt_wlan_dev_get_info(STA_DEVICE(), info) != RT_EOK)
1193+
{
1194+
/* The get_info returns an error and gets the rssi value separately */
1195+
info->rssi = rt_wlan_get_rssi();
1196+
}
11901197
return RT_EOK;
11911198
}
11921199
return -RT_ERROR;

0 commit comments

Comments
 (0)