From ecad5e1e2012b0986ac398d506379265eb436ba2 Mon Sep 17 00:00:00 2001 From: Quytelda Kahja Date: Wed, 28 Feb 2018 21:19:09 -0800 Subject: [PATCH] staging: ks7010: Factor out repeated code into function 'ks_wlan_cap()'. The code that generates a WLAN capability mask is repeated in five functions. This change refactors that code into a new function, which is called now in each of those functions. Signed-off-by: Quytelda Kahja Reviewed-by: Tobin C. Harding Signed-off-by: Greg Kroah-Hartman --- drivers/staging/ks7010/ks_hostif.c | 88 ++++++++---------------------- 1 file changed, 23 insertions(+), 65 deletions(-) diff --git a/drivers/staging/ks7010/ks_hostif.c b/drivers/staging/ks7010/ks_hostif.c index 59f7c4e422d3..4d11627a3d72 100644 --- a/drivers/staging/ks7010/ks_hostif.c +++ b/drivers/staging/ks7010/ks_hostif.c @@ -1381,11 +1381,28 @@ void hostif_start_request(struct ks_wlan_private *priv, unsigned char mode) priv->scan_ind_count = 0; } +static __le16 ks_wlan_cap(struct ks_wlan_private *priv) +{ + u16 capability = 0x0000; + + if (priv->reg.preamble == SHORT_PREAMBLE) { + capability |= BSS_CAP_SHORT_PREAMBLE; + } + + capability &= ~(BSS_CAP_PBCC); /* pbcc not support */ + + if (priv->reg.phy_type != D_11B_ONLY_MODE) { + capability |= BSS_CAP_SHORT_SLOT_TIME; + capability &= ~(BSS_CAP_DSSS_OFDM); + } + + return cpu_to_le16((uint16_t)capability); +} + static void hostif_ps_adhoc_set_request(struct ks_wlan_private *priv) { struct hostif_ps_adhoc_set_request_t *pp; - u16 capability; DPRINTK(3, "\n"); @@ -1398,21 +1415,10 @@ void hostif_ps_adhoc_set_request(struct ks_wlan_private *priv) pp->scan_type = cpu_to_le16((uint16_t)(priv->reg.scan_type)); pp->channel = cpu_to_le16((uint16_t)(priv->reg.channel)); pp->rate_set.size = priv->reg.rate_set.size; + pp->capability = ks_wlan_cap(priv); memcpy(&pp->rate_set.body[0], &priv->reg.rate_set.body[0], priv->reg.rate_set.size); - capability = 0x0000; - if (priv->reg.preamble == SHORT_PREAMBLE) { - /* short preamble */ - capability |= BSS_CAP_SHORT_PREAMBLE; - } - capability &= ~(BSS_CAP_PBCC); /* pbcc not support */ - if (priv->reg.phy_type != D_11B_ONLY_MODE) { - capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */ - capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM */ - } - pp->capability = cpu_to_le16((uint16_t)capability); - /* send to device request */ ps_confirm_wait_inc(priv); ks_wlan_hw_tx(priv, pp, hif_align_size(sizeof(*pp)), NULL, NULL); @@ -1422,7 +1428,6 @@ static void hostif_infrastructure_set_request(struct ks_wlan_private *priv) { struct hostif_infrastructure_set_request_t *pp; - u16 capability; DPRINTK(3, "ssid.size=%d\n", priv->reg.ssid.size); @@ -1439,18 +1444,7 @@ void hostif_infrastructure_set_request(struct ks_wlan_private *priv) priv->reg.rate_set.size); pp->ssid.size = priv->reg.ssid.size; memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size); - - capability = 0x0000; - if (priv->reg.preamble == SHORT_PREAMBLE) { - /* short preamble */ - capability |= BSS_CAP_SHORT_PREAMBLE; - } - capability &= ~(BSS_CAP_PBCC); /* pbcc not support */ - if (priv->reg.phy_type != D_11B_ONLY_MODE) { - capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */ - capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not support */ - } - pp->capability = cpu_to_le16((uint16_t)capability); + pp->capability = ks_wlan_cap(priv); pp->beacon_lost_count = cpu_to_le16((uint16_t)(priv->reg.beacon_lost_count)); pp->auth_type = cpu_to_le16((uint16_t)(priv->reg.authenticate_type)); @@ -1483,7 +1477,6 @@ void hostif_infrastructure_set_request(struct ks_wlan_private *priv) static void hostif_infrastructure_set2_request(struct ks_wlan_private *priv) { struct hostif_infrastructure_set2_request_t *pp; - u16 capability; DPRINTK(2, "ssid.size=%d\n", priv->reg.ssid.size); @@ -1500,18 +1493,7 @@ static void hostif_infrastructure_set2_request(struct ks_wlan_private *priv) priv->reg.rate_set.size); pp->ssid.size = priv->reg.ssid.size; memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size); - - capability = 0x0000; - if (priv->reg.preamble == SHORT_PREAMBLE) { - /* short preamble */ - capability |= BSS_CAP_SHORT_PREAMBLE; - } - capability &= ~(BSS_CAP_PBCC); /* pbcc not support */ - if (priv->reg.phy_type != D_11B_ONLY_MODE) { - capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */ - capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not support */ - } - pp->capability = cpu_to_le16((uint16_t)capability); + pp->capability = ks_wlan_cap(priv); pp->beacon_lost_count = cpu_to_le16((uint16_t)(priv->reg.beacon_lost_count)); pp->auth_type = cpu_to_le16((uint16_t)(priv->reg.authenticate_type)); @@ -1547,7 +1529,6 @@ static void hostif_adhoc_set_request(struct ks_wlan_private *priv) { struct hostif_adhoc_set_request_t *pp; - u16 capability; DPRINTK(3, "\n"); @@ -1564,18 +1545,7 @@ void hostif_adhoc_set_request(struct ks_wlan_private *priv) priv->reg.rate_set.size); pp->ssid.size = priv->reg.ssid.size; memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size); - - capability = 0x0000; - if (priv->reg.preamble == SHORT_PREAMBLE) { - /* short preamble */ - capability |= BSS_CAP_SHORT_PREAMBLE; - } - capability &= ~(BSS_CAP_PBCC); /* pbcc not support */ - if (priv->reg.phy_type != D_11B_ONLY_MODE) { - capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */ - capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not support */ - } - pp->capability = cpu_to_le16((uint16_t)capability); + pp->capability = ks_wlan_cap(priv); /* send to device request */ ps_confirm_wait_inc(priv); @@ -1586,7 +1556,6 @@ static void hostif_adhoc_set2_request(struct ks_wlan_private *priv) { struct hostif_adhoc_set2_request_t *pp; - u16 capability; DPRINTK(3, "\n"); @@ -1602,18 +1571,7 @@ void hostif_adhoc_set2_request(struct ks_wlan_private *priv) priv->reg.rate_set.size); pp->ssid.size = priv->reg.ssid.size; memcpy(&pp->ssid.body[0], &priv->reg.ssid.body[0], priv->reg.ssid.size); - - capability = 0x0000; - if (priv->reg.preamble == SHORT_PREAMBLE) { - /* short preamble */ - capability |= BSS_CAP_SHORT_PREAMBLE; - } - capability &= ~(BSS_CAP_PBCC); /* pbcc not support */ - if (priv->reg.phy_type != D_11B_ONLY_MODE) { - capability |= BSS_CAP_SHORT_SLOT_TIME; /* ShortSlotTime support */ - capability &= ~(BSS_CAP_DSSS_OFDM); /* DSSS OFDM not support */ - } - pp->capability = cpu_to_le16((uint16_t)capability); + pp->capability = ks_wlan_cap(priv); pp->channel_list.body[0] = priv->reg.channel; pp->channel_list.size = 1; -- 2.30.2