Skip to content

Align with recent cfg80211 header #63

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 4 commits into from
May 21, 2024
Merged
Changes from 1 commit
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
44 changes: 41 additions & 3 deletions vwifi.c
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,9 @@ static void inform_bss(struct vwifi_vif *vif)
struct cfg80211_inform_bss data = {
/* the only channel */
.chan = &ap->wdev.wiphy->bands[NL80211_BAND_2GHZ]->channels[0],
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 7, 0)
.scan_width = NL80211_BSS_CHAN_WIDTH_20,
#endif
.signal = DBM_TO_MBM(rand_int_smooth(-100, -30, jiffies)),
};
int capability = WLAN_CAPABILITY_ESS;
Expand Down Expand Up @@ -529,7 +531,7 @@ static enum hrtimer_restart vwifi_beacon(struct hrtimer *timer)
.boottime_ns = ktime_get_boottime_ns(),
.chan = vif->channel,
};

#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 7, 0)
switch (vif->bw) {
case NL80211_CHAN_WIDTH_5:
bss_meta.scan_width = NL80211_BSS_CHAN_WIDTH_5;
Expand All @@ -541,7 +543,7 @@ static enum hrtimer_restart vwifi_beacon(struct hrtimer *timer)
bss_meta.scan_width = NL80211_BSS_CHAN_WIDTH_20;
break;
}

#endif
int capability = WLAN_CAPABILITY_ESS;

if (vif->privacy)
Expand Down Expand Up @@ -1577,7 +1579,7 @@ static int vwifi_stop_ap(struct wiphy *wiphy, struct net_device *ndev)

return 0;
}

#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 7, 0)
static int vwifi_change_beacon(struct wiphy *wiphy,
struct net_device *ndev,
struct cfg80211_beacon_data *info)
Expand Down Expand Up @@ -1611,7 +1613,41 @@ static int vwifi_change_beacon(struct wiphy *wiphy,

return 0;
}
#else
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my opinion, surrounding the changed lines with the #if directives is better since there are only a few lines changed.

That is:

static int vwifi_change_beacon(struct wiphy *wiphy,
                               struct net_device *ndev,
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 7, 0)
                               struct cfg80211_beacon_data *info
#else
                               struct cfg80211_ap_update *info)
#endif

Copy link
Collaborator Author

@jychen0611 jychen0611 May 20, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

However, due to the changes within this function, the frequency of using #if will significantly increase.
Is this acceptable? If so, I will proceed with the modification immediately.

static int vwifi_change_beacon(struct wiphy *wiphy,
struct net_device *ndev,
struct cfg80211_ap_update *info)
{
struct vwifi_vif *vif = ndev_get_vwifi_vif(ndev);
int ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN;
int head_ie_len, tail_ie_len;

/* cfg80211 and some user-space programs treat IEs as two-part:
* 1. head: 802.11 beacon frame header + beacon IEs before TIM IE
* 2. tail: beacon IEs after TIM IE
* We combine them and store them in vif->beacon_ie.
*/
head_ie_len = info->beacon.head_len - ie_offset;
tail_ie_len = info->beacon.tail_len;

if (likely(head_ie_len + tail_ie_len <= IE_MAX_LEN)) {
vif->beacon_ie_len = head_ie_len + tail_ie_len;
memset(vif->beacon_ie, 0, IE_MAX_LEN);
memcpy(vif->beacon_ie, &info->beacon.head[ie_offset], head_ie_len);
memcpy(vif->beacon_ie + head_ie_len, info->beacon.tail, tail_ie_len);

pr_info(
"%s: head_ie_len (before TIM IE) = %d, tail_ie_len = "
"%d",
__func__, head_ie_len, tail_ie_len);
} else {
pr_info("%s: IE exceed %d bytes!\n", __func__, IE_MAX_LEN);
return 1;
}

return 0;
}
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(6, 1, 0)
static int vwifi_add_key(struct wiphy *wiphy,
struct net_device *ndev,
Expand Down Expand Up @@ -2550,7 +2586,9 @@ static void vwifi_virtio_mgmt_rx_scan_response(
};
struct cfg80211_inform_bss data = {
.chan = &rx_channel,
#if LINUX_VERSION_CODE < KERNEL_VERSION(6, 7, 0)
.scan_width = NL80211_BSS_CHAN_WIDTH_20,
#endif
.signal = DBM_TO_MBM(rand_int_smooth(-100, -30, jiffies)),
};

Expand Down