Skip to content

Commit 72e38a2

Browse files
committed
Add code for supporting loopback mode and throughput calculation
Adding initial code for throughput calculation and loopback mode Signed-off-by: Vivekananda Uppunda <[email protected]>
1 parent afa22e5 commit 72e38a2

File tree

9 files changed

+171
-7
lines changed

9 files changed

+171
-7
lines changed

drivers/wifi/nrf_wifi/inc/wifi_mgmt.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ int nrf_wifi_filter(const struct device *dev,
7070
struct wifi_filter_info *filter);
7171
#endif /* CONFIG_NRF70_RAW_DATA_RX || CONFIG_NRF70_PROMISC_DATA_RX */
7272

73+
int nrf_wifi_set_loopback_mode(const struct device *dev,
74+
unsigned char loopback_mode);
75+
76+
int nrf_wifi_get_throughput(const struct device *dev,
77+
struct wifi_throughput_info *throughput_info);
78+
7379
int nrf_wifi_set_rts_threshold(const struct device *dev,
7480
unsigned int rts_threshold);
7581

drivers/wifi/nrf_wifi/src/fmac_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -847,6 +847,8 @@ static struct wifi_mgmt_ops nrf_wifi_mgmt_ops = {
847847
#if defined(CONFIG_NRF70_RAW_DATA_RX) || defined(CONFIG_NRF70_PROMISC_DATA_RX)
848848
.filter = nrf_wifi_filter,
849849
#endif /* CONFIG_NRF70_RAW_DATA_RX || CONFIG_NRF70_PROMISC_DATA_RX */
850+
.loopback_mode = nrf_wifi_set_loopback_mode,
851+
.throughput = nrf_wifi_get_throughput,
850852
};
851853
#endif /* CONFIG_NET_L2_WIFI_MGMT */
852854

drivers/wifi/nrf_wifi/src/wifi_mgmt.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -986,6 +986,70 @@ int nrf_wifi_filter(const struct device *dev,
986986
return ret;
987987
}
988988
#endif /* CONFIG_NRF70_RAW_DATA_RX || CONFIG_NRF70_PROMISC_DATA_RX */
989+
int nrf_wifi_get_throughput(const struct device *dev,
990+
struct wifi_throughput_info *throughput_info)
991+
{
992+
enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL;
993+
struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
994+
struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
995+
struct nrf_wifi_fmac_dev_ctx *fmac_dev_ctx = NULL;
996+
struct nrf_wifi_fmac_dev_ctx_def *def_dev_ctx = NULL;
997+
int ret = -1;
998+
999+
if (!dev || !throughput_info) {
1000+
LOG_ERR("%s: Illegal input parameters", __func__);
1001+
goto out;
1002+
}
1003+
1004+
vif_ctx_zep = dev->data;
1005+
if (!vif_ctx_zep) {
1006+
LOG_ERR("%s: vif_ctx_zep is NULL\n", __func__);
1007+
goto out;
1008+
}
1009+
1010+
rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep;
1011+
fmac_dev_ctx = rpu_ctx_zep->rpu_ctx;
1012+
def_dev_ctx = wifi_dev_priv(fmac_dev_ctx);
1013+
1014+
/* Fill throughput data here */
1015+
out:
1016+
return status;
1017+
}
1018+
1019+
int nrf_wifi_set_loopback_mode(const struct device *dev,
1020+
unsigned char loopback_mode)
1021+
{
1022+
enum nrf_wifi_status status = NRF_WIFI_STATUS_FAIL;
1023+
struct nrf_wifi_ctx_zep *rpu_ctx_zep = NULL;
1024+
struct nrf_wifi_vif_ctx_zep *vif_ctx_zep = NULL;
1025+
int ret = -1;
1026+
1027+
if (!dev) {
1028+
LOG_ERR("%s: dev is NULL", __func__);
1029+
return ret;
1030+
}
1031+
1032+
vif_ctx_zep = dev->data;
1033+
if (!vif_ctx_zep) {
1034+
LOG_ERR("%s: vif_ctx_zep is NULL", __func__);
1035+
return ret;
1036+
}
1037+
1038+
rpu_ctx_zep = vif_ctx_zep->rpu_ctx_zep;
1039+
if (!rpu_ctx_zep) {
1040+
LOG_ERR("%s: rpu_ctx_zep is NULL", __func__);
1041+
return ret;
1042+
}
1043+
1044+
status = nrf_wifi_fmac_set_loopback_mode(rpu_ctx_zep->rpu_ctx,
1045+
vif_ctx_zep->vif_idx,
1046+
loopback_mode);
1047+
if (status != NRF_WIFI_STATUS_SUCCESS) {
1048+
LOG_ERR("%s: Set loopback mode failed\n", __func__);
1049+
}
1050+
1051+
return status;
1052+
}
9891053

9901054
int nrf_wifi_set_rts_threshold(const struct device *dev,
9911055
unsigned int rts_threshold)

drivers/wifi/nrf_wifi/src/wifi_util.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ int nrf_wifi_util_conf_init(struct rpu_conf_params *conf_params)
7979
return 0;
8080
}
8181

82-
8382
static int nrf_wifi_util_set_he_ltf(const struct shell *sh,
8483
size_t argc,
8584
const char *argv[])
@@ -110,7 +109,6 @@ static int nrf_wifi_util_set_he_ltf(const struct shell *sh,
110109
return 0;
111110
}
112111

113-
114112
static int nrf_wifi_util_set_he_gi(const struct shell *sh,
115113
size_t argc,
116114
const char *argv[])
@@ -217,7 +215,6 @@ static int nrf_wifi_util_set_uapsd_queue(const struct shell *sh,
217215
}
218216
#endif /* CONFIG_NRF70_STA_MODE */
219217

220-
221218
static int nrf_wifi_util_show_cfg(const struct shell *sh,
222219
size_t argc,
223220
const char *argv[])
@@ -324,7 +321,6 @@ static int nrf_wifi_util_tx_stats(const struct shell *sh,
324321
}
325322
#endif /* CONFIG_NRF70_STA_MODE */
326323

327-
328324
static int nrf_wifi_util_tx_rate(const struct shell *sh,
329325
size_t argc,
330326
const char *argv[])
@@ -390,7 +386,6 @@ static int nrf_wifi_util_tx_rate(const struct shell *sh,
390386
return 0;
391387
}
392388

393-
394389
#ifdef CONFIG_NRF_WIFI_LOW_POWER
395390
static int nrf_wifi_util_show_host_rpu_ps_ctrl_state(const struct shell *sh,
396391
size_t argc,
@@ -1067,8 +1062,6 @@ SHELL_STATIC_SUBCMD_SET_CREATE(
10671062
0),
10681063
#endif /* CONFIG_NRF_WIFI_RPU_RECOVERY */
10691064
SHELL_SUBCMD_SET_END);
1070-
1071-
10721065
SHELL_CMD_REGISTER(wifi_util,
10731066
&nrf_wifi_util_subcmds,
10741067
"nRF Wi-Fi utility shell commands",

include/zephyr/net/wifi_mgmt.h

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ enum net_request_wifi_cmd {
108108
NET_REQUEST_WIFI_CMD_RTS_THRESHOLD_CONFIG,
109109
/** WPS config */
110110
NET_REQUEST_WIFI_CMD_WPS_CONFIG,
111+
/** Wezen Loopback mode */
112+
NET_REQUEST_WIFI_CMD_LOOPBACK,
113+
/** Wezen get throughput API */
114+
NET_REQUEST_WIFI_CMD_THROUGHPUT,
111115
/** @cond INTERNAL_HIDDEN */
112116
NET_REQUEST_WIFI_CMD_MAX
113117
/** @endcond */
@@ -191,6 +195,18 @@ NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_PACKET_FILTER);
191195

192196
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_CHANNEL);
193197

198+
/** Request a Wi-Fi loopback mode setting */
199+
#define NET_REQUEST_WIFI_LOOPBACK_MODE \
200+
(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_LOOPBACK)
201+
202+
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_LOOPBACK_MODE);
203+
204+
/** Request Wi-Fi TX burst througput setting */
205+
#define NET_REQUEST_WIFI_THROUGHPUT \
206+
(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_THROUGHPUT)
207+
208+
NET_MGMT_DEFINE_REQUEST_HANDLER(NET_REQUEST_WIFI_THROUGHPUT);
209+
194210
/** Request a Wi-Fi access point to disconnect a station */
195211
#define NET_REQUEST_WIFI_AP_STA_DISCONNECT \
196212
(_NET_WIFI_BASE | NET_REQUEST_WIFI_CMD_AP_STA_DISCONNECT)
@@ -850,6 +866,15 @@ struct wifi_mode_info {
850866
enum wifi_mgmt_op oper;
851867
};
852868

869+
struct wifi_throughput_info {
870+
/** Previous second packet count */
871+
int previous_sec_packet_count;
872+
/** Current second packet count */
873+
int current_sec_packet_count;
874+
/** Interface index */
875+
uint8_t if_index;
876+
};
877+
853878
/** @brief Wi-Fi filter setting for monitor, prmoiscuous, TX-injection modes */
854879
struct wifi_filter_info {
855880
/** Filter setting */
@@ -1365,6 +1390,10 @@ struct wifi_mgmt_ops {
13651390
* @return 0 if ok, < 0 if error
13661391
*/
13671392
int (*wps_config)(const struct device *dev, struct wifi_wps_config_params *params);
1393+
1394+
int (*loopback_mode)(const struct device *dev, unsigned char loopback_mode);
1395+
1396+
int (*throughput)(const struct device *dev, struct wifi_throughput_info *throughput_info);
13681397
};
13691398

13701399
/** Wi-Fi management offload API */

modules/hostap/src/supp_api.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,31 @@ int supplicant_channel(const struct device *dev, struct wifi_channel_info *chann
15011501
return wifi_mgmt_api->channel(dev, channel);
15021502
}
15031503

1504+
int supplicant_loopback(const struct device *dev, unsigned char loopback_mode)
1505+
{
1506+
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);
1507+
1508+
if (!wifi_mgmt_api || !wifi_mgmt_api->loopback_mode) {
1509+
wpa_printf(MSG_ERROR, "Setting loopback mode not supported");
1510+
return -ENOTSUP;
1511+
}
1512+
1513+
return wifi_mgmt_api->loopback_mode(dev, loopback_mode);
1514+
}
1515+
1516+
int supplicant_throughput(const struct device *dev,
1517+
struct wifi_throughput_info *throughput_info)
1518+
{
1519+
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);
1520+
1521+
if (!wifi_mgmt_api || !wifi_mgmt_api->throughput) {
1522+
wpa_printf(MSG_ERROR, "Getting throughput not supported");
1523+
return -ENOTSUP;
1524+
}
1525+
1526+
return wifi_mgmt_api->throughput(dev, throughput_info);
1527+
}
1528+
15041529
int supplicant_set_rts_threshold(const struct device *dev, unsigned int rts_threshold)
15051530
{
15061531
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_mgmt_api(dev);

modules/hostap/src/supp_api.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,10 @@ int supplicant_get_wifi_conn_params(const struct device *dev,
224224
*/
225225
int supplicant_wps_config(const struct device *dev, struct wifi_wps_config_params *params);
226226

227+
int supplicant_loopback(const struct device *dev, unsigned char loopback_mode);
228+
229+
int supplicant_throughput(const struct device *dev, struct wifi_throughput_info *throughput_info);
230+
227231
#ifdef CONFIG_AP
228232
#ifdef CONFIG_WIFI_NM_HOSTAPD_AP
229233
/**

modules/hostap/src/supp_main.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ static const struct wifi_mgmt_ops mgmt_ops = {
6969
.mode = supplicant_mode,
7070
.filter = supplicant_filter,
7171
.channel = supplicant_channel,
72+
.loopback_mode = supplicant_loopback,
73+
.throughput = supplicant_throughput,
7274
.set_rts_threshold = supplicant_set_rts_threshold,
7375
.get_rts_threshold = supplicant_get_rts_threshold,
7476
#ifdef CONFIG_WIFI_NM_WPA_SUPPLICANT_WNM

subsys/net/l2/wifi/wifi_mgmt.c

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -780,6 +780,45 @@ static int wifi_channel(uint32_t mgmt_request, struct net_if *iface,
780780

781781
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_CHANNEL, wifi_channel);
782782

783+
static int wifi_loopback_mode(uint32_t mgmt_request, struct net_if *iface,
784+
void *data, size_t len)
785+
{
786+
const struct device *dev = net_if_get_device(iface);
787+
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
788+
unsigned char *loopback_mode = data;
789+
if (dev == NULL) {
790+
return -ENODEV;
791+
}
792+
793+
if (wifi_mgmt_api == NULL || wifi_mgmt_api->loopback_mode == NULL) {
794+
return -ENOTSUP;
795+
}
796+
797+
return wifi_mgmt_api->loopback_mode(dev, *loopback_mode);
798+
}
799+
800+
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_LOOPBACK_MODE, wifi_loopback_mode);
801+
802+
static int wifi_throughput(uint32_t mgmt_request, struct net_if *iface,
803+
void *data, size_t len)
804+
{
805+
const struct device *dev = net_if_get_device(iface);
806+
struct wifi_throughput_info *throughput_info = data;
807+
const struct wifi_mgmt_ops *const wifi_mgmt_api = get_wifi_api(iface);
808+
809+
if (dev == NULL) {
810+
return -ENODEV;
811+
}
812+
813+
if (wifi_mgmt_api == NULL || wifi_mgmt_api->throughput == NULL) {
814+
return -ENOTSUP;
815+
}
816+
817+
return wifi_mgmt_api->throughput(dev, throughput_info);
818+
}
819+
820+
NET_MGMT_REGISTER_REQUEST_HANDLER(NET_REQUEST_WIFI_THROUGPUT, wifi_throughput);
821+
783822
static int wifi_get_version(uint32_t mgmt_request, struct net_if *iface,
784823
void *data, size_t len)
785824
{

0 commit comments

Comments
 (0)