diff options
author | 2023-02-21 18:24:12 -0800 | |
---|---|---|
committer | 2023-02-21 18:24:12 -0800 | |
commit | 5b7c4cabbb65f5c469464da6c5f614cbd7f730f2 (patch) | |
tree | cc5c2d0a898769fd59549594fedb3ee6f84e59a0 /drivers/staging/wlan-ng/cfg80211.c | |
download | linux-5b7c4cabbb65f5c469464da6c5f614cbd7f730f2.tar.gz linux-5b7c4cabbb65f5c469464da6c5f614cbd7f730f2.zip |
Merge tag 'net-next-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-nextgrafted
Pull networking updates from Jakub Kicinski:
"Core:
- Add dedicated kmem_cache for typical/small skb->head, avoid having
to access struct page at kfree time, and improve memory use.
- Introduce sysctl to set default RPS configuration for new netdevs.
- Define Netlink protocol specification format which can be used to
describe messages used by each family and auto-generate parsers.
Add tools for generating kernel data structures and uAPI headers.
- Expose all net/core sysctls inside netns.
- Remove 4s sleep in netpoll if carrier is instantly detected on
boot.
- Add configurable limit of MDB entries per port, and port-vlan.
- Continue populating drop reasons throughout the stack.
- Retire a handful of legacy Qdiscs and classifiers.
Protocols:
- Support IPv4 big TCP (TSO frames larger than 64kB).
- Add IP_LOCAL_PORT_RANGE socket option, to control local port range
on socket by socket basis.
- Track and report in procfs number of MPTCP sockets used.
- Support mixing IPv4 and IPv6 flows in the in-kernel MPTCP path
manager.
- IPv6: don't check net.ipv6.route.max_size and rely on garbage
collection to free memory (similarly to IPv4).
- Support Penultimate Segment Pop (PSP) flavor in SRv6 (RFC8986).
- ICMP: add per-rate limit counters.
- Add support for user scanning requests in ieee802154.
- Remove static WEP support.
- Support minimal Wi-Fi 7 Extremely High Throughput (EHT) rate
reporting.
- WiFi 7 EHT channel puncturing support (client & AP).
BPF:
- Add a rbtree data structure following the "next-gen data structure"
precedent set by recently added linked list, that is, by using
kfunc + kptr instead of adding a new BPF map type.
- Expose XDP hints via kfuncs with initial support for RX hash and
timestamp metadata.
- Add BPF_F_NO_TUNNEL_KEY extension to bpf_skb_set_tunnel_key to
better support decap on GRE tunnel devices not operating in collect
metadata.
- Improve x86 JIT's codegen for PROBE_MEM runtime error checks.
- Remove the need for trace_printk_lock for bpf_trace_printk and
bpf_trace_vprintk helpers.
- Extend libbpf's bpf_tracing.h support for tracing arguments of
kprobes/uprobes and syscall as a special case.
- Significantly reduce the search time for module symbols by
livepatch and BPF.
- Enable cpumasks to be used as kptrs, which is useful for tracing
programs tracking which tasks end up running on which CPUs in
different time intervals.
- Add support for BPF trampoline on s390x and riscv64.
- Add capability to export the XDP features supported by the NIC.
- Add __bpf_kfunc tag for marking kernel functions as kfuncs.
- Add cgroup.memory=nobpf kernel parameter option to disable BPF
memory accounting for container environments.
Netfilter:
- Remove the CLUSTERIP target. It has been marked as obsolete for
years, and we still have WARN splats wrt races of the out-of-band
/proc interface installed by this target.
- Add 'destroy' commands to nf_tables. They are identical to the
existing 'delete' commands, but do not return an error if the
referenced object (set, chain, rule...) did not exist.
Driver API:
- Improve cpumask_local_spread() locality to help NICs set the right
IRQ affinity on AMD platforms.
- Separate C22 and C45 MDIO bus transactions more clearly.
- Introduce new DCB table to control DSCP rewrite on egress.
- Support configuration of Physical Layer Collision Avoidance (PLCA)
Reconciliation Sublayer (RS) (802.3cg-2019). Modern version of
shared medium Ethernet.
- Support for MAC Merge layer (IEEE 802.3-2018 clause 99). Allowing
preemption of low priority frames by high priority frames.
- Add support for controlling MACSec offload using netlink SET.
- Rework devlink instance refcounts to allow registration and
de-registration under the instance lock. Split the code into
multiple files, drop some of the unnecessarily granular locks and
factor out common parts of netlink operation handling.
- Add TX frame aggregation parameters (for USB drivers).
- Add a new attr TCA_EXT_WARN_MSG to report TC (offload) warning
messages with notifications for debug.
- Allow offloading of UDP NEW connections via act_ct.
- Add support for per action HW stats in TC.
- Support hardware miss to TC action (continue processing in SW from
a specific point in the action chain).
- Warn if old Wireless Extension user space interface is used with
modern cfg80211/mac80211 drivers. Do not support Wireless
Extensions for Wi-Fi 7 devices at all. Everyone should switch to
using nl80211 interface instead.
- Improve the CAN bit timing configuration. Use extack to return
error messages directly to user space, update the SJW handling,
including the definition of a new default value that will benefit
CAN-FD controllers, by increasing their oscillator tolerance.
New hardware / drivers:
- Ethernet:
- nVidia BlueField-3 support (control traffic driver)
- Ethernet support for imx93 SoCs
- Motorcomm yt8531 gigabit Ethernet PHY
- onsemi NCN26000 10BASE-T1S PHY (with support for PLCA)
- Microchip LAN8841 PHY (incl. cable diagnostics and PTP)
- Amlogic gxl MDIO mux
- WiFi:
- RealTek RTL8188EU (rtl8xxxu)
- Qualcomm Wi-Fi 7 devices (ath12k)
- CAN:
- Renesas R-Car V4H
Drivers:
- Bluetooth:
- Set Per Platform Antenna Gain (PPAG) for Intel controllers.
- Ethernet NICs:
- Intel (1G, igc):
- support TSN / Qbv / packet scheduling features of i226 model
- Intel (100G, ice):
- use GNSS subsystem instead of TTY
- multi-buffer XDP support
- extend support for GPIO pins to E823 devices
- nVidia/Mellanox:
- update the shared buffer configuration on PFC commands
- implement PTP adjphase function for HW offset control
- TC support for Geneve and GRE with VF tunnel offload
- more efficient crypto key management method
- multi-port eswitch support
- Netronome/Corigine:
- add DCB IEEE support
- support IPsec offloading for NFP3800
- Freescale/NXP (enetc):
- support XDP_REDIRECT for XDP non-linear buffers
- improve reconfig, avoid link flap and waiting for idle
- support MAC Merge layer
- Other NICs:
- sfc/ef100: add basic devlink support for ef100
- ionic: rx_push mode operation (writing descriptors via MMIO)
- bnxt: use the auxiliary bus abstraction for RDMA
- r8169: disable ASPM and reset bus in case of tx timeout
- cpsw: support QSGMII mode for J721e CPSW9G
- cpts: support pulse-per-second output
- ngbe: add an mdio bus driver
- usbnet: optimize usbnet_bh() by avoiding unnecessary queuing
- r8152: handle devices with FW with NCM support
- amd-xgbe: support 10Mbps, 2.5GbE speeds and rx-adaptation
- virtio-net: support multi buffer XDP
- virtio/vsock: replace virtio_vsock_pkt with sk_buff
- tsnep: XDP support
- Ethernet high-speed switches:
- nVidia/Mellanox (mlxsw):
- add support for latency TLV (in FW control messages)
- Microchip (sparx5):
- separate explicit and implicit traffic forwarding rules, make
the implicit rules always active
- add support for egress DSCP rewrite
- IS0 VCAP support (Ingress Classification)
- IS2 VCAP filters (protos, L3 addrs, L4 ports, flags, ToS
etc.)
- ES2 VCAP support (Egress Access Control)
- support for Per-Stream Filtering and Policing (802.1Q,
8.6.5.1)
- Ethernet embedded switches:
- Marvell (mv88e6xxx):
- add MAB (port auth) offload support
- enable PTP receive for mv88e6390
- NXP (ocelot):
- support MAC Merge layer
- support for the the vsc7512 internal copper phys
- Microchip:
- lan9303: convert to PHYLINK
- lan966x: support TC flower filter statistics
- lan937x: PTP support for KSZ9563/KSZ8563 and LAN937x
- lan937x: support Credit Based Shaper configuration
- ksz9477: support Energy Efficient Ethernet
- other:
- qca8k: convert to regmap read/write API, use bulk operations
- rswitch: Improve TX timestamp accuracy
- Intel WiFi (iwlwifi):
- EHT (Wi-Fi 7) rate reporting
- STEP equalizer support: transfer some STEP (connection to radio
on platforms with integrated wifi) related parameters from the
BIOS to the firmware.
- Qualcomm 802.11ax WiFi (ath11k):
- IPQ5018 support
- Fine Timing Measurement (FTM) responder role support
- channel 177 support
- MediaTek WiFi (mt76):
- per-PHY LED support
- mt7996: EHT (Wi-Fi 7) support
- Wireless Ethernet Dispatch (WED) reset support
- switch to using page pool allocator
- RealTek WiFi (rtw89):
- support new version of Bluetooth co-existance
- Mobile:
- rmnet: support TX aggregation"
* tag 'net-next-6.3' of git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net-next: (1872 commits)
page_pool: add a comment explaining the fragment counter usage
net: ethtool: fix __ethtool_dev_mm_supported() implementation
ethtool: pse-pd: Fix double word in comments
xsk: add linux/vmalloc.h to xsk.c
sefltests: netdevsim: wait for devlink instance after netns removal
selftest: fib_tests: Always cleanup before exit
net/mlx5e: Align IPsec ASO result memory to be as required by hardware
net/mlx5e: TC, Set CT miss to the specific ct action instance
net/mlx5e: Rename CHAIN_TO_REG to MAPPED_OBJ_TO_REG
net/mlx5: Refactor tc miss handling to a single function
net/mlx5: Kconfig: Make tc offload depend on tc skb extension
net/sched: flower: Support hardware miss to tc action
net/sched: flower: Move filter handle initialization earlier
net/sched: cls_api: Support hardware miss to tc action
net/sched: Rename user cookie and act cookie
sfc: fix builds without CONFIG_RTC_LIB
sfc: clean up some inconsistent indentings
net/mlx4_en: Introduce flexible array to silence overflow warning
net: lan966x: Fix possible deadlock inside PTP
net/ulp: Remove redundant ->clone() test in inet_clone_ulp().
...
Diffstat (limited to 'drivers/staging/wlan-ng/cfg80211.c')
-rw-r--r-- | drivers/staging/wlan-ng/cfg80211.c | 718 |
1 files changed, 718 insertions, 0 deletions
diff --git a/drivers/staging/wlan-ng/cfg80211.c b/drivers/staging/wlan-ng/cfg80211.c new file mode 100644 index 000000000..471bb3101 --- /dev/null +++ b/drivers/staging/wlan-ng/cfg80211.c @@ -0,0 +1,718 @@ +// SPDX-License-Identifier: GPL-2.0 +/* cfg80211 Interface for prism2_usb module */ +#include "hfa384x.h" +#include "prism2mgmt.h" + +/* Prism2 channel/frequency/bitrate declarations */ +static const struct ieee80211_channel prism2_channels[] = { + { .center_freq = 2412 }, + { .center_freq = 2417 }, + { .center_freq = 2422 }, + { .center_freq = 2427 }, + { .center_freq = 2432 }, + { .center_freq = 2437 }, + { .center_freq = 2442 }, + { .center_freq = 2447 }, + { .center_freq = 2452 }, + { .center_freq = 2457 }, + { .center_freq = 2462 }, + { .center_freq = 2467 }, + { .center_freq = 2472 }, + { .center_freq = 2484 }, +}; + +static const struct ieee80211_rate prism2_rates[] = { + { .bitrate = 10 }, + { .bitrate = 20 }, + { .bitrate = 55 }, + { .bitrate = 110 } +}; + +#define PRISM2_NUM_CIPHER_SUITES 2 +static const u32 prism2_cipher_suites[PRISM2_NUM_CIPHER_SUITES] = { + WLAN_CIPHER_SUITE_WEP40, + WLAN_CIPHER_SUITE_WEP104 +}; + +/* prism2 device private data */ +struct prism2_wiphy_private { + struct wlandevice *wlandev; + + struct ieee80211_supported_band band; + struct ieee80211_channel channels[ARRAY_SIZE(prism2_channels)]; + struct ieee80211_rate rates[ARRAY_SIZE(prism2_rates)]; + + struct cfg80211_scan_request *scan_request; +}; + +static const void * const prism2_wiphy_privid = &prism2_wiphy_privid; + +/* Helper Functions */ +static int prism2_result2err(int prism2_result) +{ + int err = 0; + + switch (prism2_result) { + case P80211ENUM_resultcode_invalid_parameters: + err = -EINVAL; + break; + case P80211ENUM_resultcode_implementation_failure: + err = -EIO; + break; + case P80211ENUM_resultcode_not_supported: + err = -EOPNOTSUPP; + break; + default: + err = 0; + break; + } + + return err; +} + +static int prism2_domibset_uint32(struct wlandevice *wlandev, + u32 did, u32 data) +{ + struct p80211msg_dot11req_mibset msg; + struct p80211item_uint32 *mibitem = + (struct p80211item_uint32 *)&msg.mibattribute.data; + + msg.msgcode = DIDMSG_DOT11REQ_MIBSET; + mibitem->did = did; + mibitem->data = data; + + return p80211req_dorequest(wlandev, (u8 *)&msg); +} + +static int prism2_domibset_pstr32(struct wlandevice *wlandev, + u32 did, u8 len, const u8 *data) +{ + struct p80211msg_dot11req_mibset msg; + struct p80211item_pstr32 *mibitem = + (struct p80211item_pstr32 *)&msg.mibattribute.data; + + msg.msgcode = DIDMSG_DOT11REQ_MIBSET; + mibitem->did = did; + mibitem->data.len = len; + memcpy(mibitem->data.data, data, len); + + return p80211req_dorequest(wlandev, (u8 *)&msg); +} + +/* The interface functions, called by the cfg80211 layer */ +static int prism2_change_virtual_intf(struct wiphy *wiphy, + struct net_device *dev, + enum nl80211_iftype type, + struct vif_params *params) +{ + struct wlandevice *wlandev = dev->ml_priv; + u32 data; + int result; + int err = 0; + + switch (type) { + case NL80211_IFTYPE_ADHOC: + if (wlandev->macmode == WLAN_MACMODE_IBSS_STA) + goto exit; + wlandev->macmode = WLAN_MACMODE_IBSS_STA; + data = 0; + break; + case NL80211_IFTYPE_STATION: + if (wlandev->macmode == WLAN_MACMODE_ESS_STA) + goto exit; + wlandev->macmode = WLAN_MACMODE_ESS_STA; + data = 1; + break; + default: + netdev_warn(dev, "Operation mode: %d not support\n", type); + return -EOPNOTSUPP; + } + + /* Set Operation mode to the PORT TYPE RID */ + result = prism2_domibset_uint32(wlandev, + DIDMIB_P2_STATIC_CNFPORTTYPE, + data); + + if (result) + err = -EFAULT; + + dev->ieee80211_ptr->iftype = type; + +exit: + return err; +} + +static int prism2_add_key(struct wiphy *wiphy, struct net_device *dev, + int link_id, u8 key_index, bool pairwise, + const u8 *mac_addr, struct key_params *params) +{ + struct wlandevice *wlandev = dev->ml_priv; + u32 did; + + if (key_index >= NUM_WEPKEYS) + return -EINVAL; + + if (params->cipher != WLAN_CIPHER_SUITE_WEP40 && + params->cipher != WLAN_CIPHER_SUITE_WEP104) { + pr_debug("Unsupported cipher suite\n"); + return -EFAULT; + } + + if (prism2_domibset_uint32(wlandev, + DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID, + key_index)) + return -EFAULT; + + /* send key to driver */ + did = didmib_dot11smt_wepdefaultkeystable_key(key_index + 1); + + if (prism2_domibset_pstr32(wlandev, did, params->key_len, params->key)) + return -EFAULT; + return 0; +} + +static int prism2_get_key(struct wiphy *wiphy, struct net_device *dev, + int link_id, u8 key_index, bool pairwise, + const u8 *mac_addr, void *cookie, + void (*callback)(void *cookie, struct key_params*)) +{ + struct wlandevice *wlandev = dev->ml_priv; + struct key_params params; + int len; + + if (key_index >= NUM_WEPKEYS) + return -EINVAL; + + len = wlandev->wep_keylens[key_index]; + memset(¶ms, 0, sizeof(params)); + + if (len == 13) + params.cipher = WLAN_CIPHER_SUITE_WEP104; + else if (len == 5) + params.cipher = WLAN_CIPHER_SUITE_WEP104; + else + return -ENOENT; + params.key_len = len; + params.key = wlandev->wep_keys[key_index]; + params.seq_len = 0; + + callback(cookie, ¶ms); + + return 0; +} + +static int prism2_del_key(struct wiphy *wiphy, struct net_device *dev, + int link_id, u8 key_index, bool pairwise, + const u8 *mac_addr) +{ + struct wlandevice *wlandev = dev->ml_priv; + u32 did; + int err = 0; + int result = 0; + + /* There is no direct way in the hardware (AFAIK) of removing + * a key, so we will cheat by setting the key to a bogus value + */ + + if (key_index >= NUM_WEPKEYS) + return -EINVAL; + + /* send key to driver */ + did = didmib_dot11smt_wepdefaultkeystable_key(key_index + 1); + result = prism2_domibset_pstr32(wlandev, did, 13, "0000000000000"); + + if (result) + err = -EFAULT; + + return err; +} + +static int prism2_set_default_key(struct wiphy *wiphy, struct net_device *dev, + int link_id, u8 key_index, bool unicast, + bool multicast) +{ + struct wlandevice *wlandev = dev->ml_priv; + + return prism2_domibset_uint32(wlandev, + DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID, + key_index); +} + +static int prism2_get_station(struct wiphy *wiphy, struct net_device *dev, + const u8 *mac, struct station_info *sinfo) +{ + struct wlandevice *wlandev = dev->ml_priv; + struct p80211msg_lnxreq_commsquality quality; + int result; + + memset(sinfo, 0, sizeof(*sinfo)); + + if (!wlandev || (wlandev->msdstate != WLAN_MSD_RUNNING)) + return -EOPNOTSUPP; + + /* build request message */ + quality.msgcode = DIDMSG_LNXREQ_COMMSQUALITY; + quality.dbm.data = P80211ENUM_truth_true; + quality.dbm.status = P80211ENUM_msgitem_status_data_ok; + + /* send message to nsd */ + if (!wlandev->mlmerequest) + return -EOPNOTSUPP; + + result = wlandev->mlmerequest(wlandev, (struct p80211msg *)&quality); + + if (result == 0) { + sinfo->txrate.legacy = quality.txrate.data; + sinfo->filled |= BIT_ULL(NL80211_STA_INFO_TX_BITRATE); + sinfo->signal = quality.level.data; + sinfo->filled |= BIT_ULL(NL80211_STA_INFO_SIGNAL); + } + + return result; +} + +static int prism2_scan(struct wiphy *wiphy, + struct cfg80211_scan_request *request) +{ + struct net_device *dev; + struct prism2_wiphy_private *priv = wiphy_priv(wiphy); + struct wlandevice *wlandev; + struct p80211msg_dot11req_scan msg1; + struct p80211msg_dot11req_scan_results *msg2; + struct cfg80211_bss *bss; + struct cfg80211_scan_info info = {}; + + int result; + int err = 0; + int numbss = 0; + int i = 0; + u8 ie_buf[46]; + int ie_len; + + if (!request) + return -EINVAL; + + dev = request->wdev->netdev; + wlandev = dev->ml_priv; + + if (priv->scan_request && priv->scan_request != request) + return -EBUSY; + + if (wlandev->macmode == WLAN_MACMODE_ESS_AP) { + netdev_err(dev, "Can't scan in AP mode\n"); + return -EOPNOTSUPP; + } + + msg2 = kzalloc(sizeof(*msg2), GFP_KERNEL); + if (!msg2) + return -ENOMEM; + + priv->scan_request = request; + + memset(&msg1, 0x00, sizeof(msg1)); + msg1.msgcode = DIDMSG_DOT11REQ_SCAN; + msg1.bsstype.data = P80211ENUM_bsstype_any; + + memset(&msg1.bssid.data.data, 0xFF, sizeof(msg1.bssid.data.data)); + msg1.bssid.data.len = 6; + + if (request->n_ssids > 0) { + msg1.scantype.data = P80211ENUM_scantype_active; + msg1.ssid.data.len = request->ssids->ssid_len; + memcpy(msg1.ssid.data.data, + request->ssids->ssid, request->ssids->ssid_len); + } else { + msg1.scantype.data = 0; + } + msg1.probedelay.data = 0; + + for (i = 0; + (i < request->n_channels) && i < ARRAY_SIZE(prism2_channels); + i++) + msg1.channellist.data.data[i] = + ieee80211_frequency_to_channel(request->channels[i]->center_freq); + msg1.channellist.data.len = request->n_channels; + + msg1.maxchanneltime.data = 250; + msg1.minchanneltime.data = 200; + + result = p80211req_dorequest(wlandev, (u8 *)&msg1); + if (result) { + err = prism2_result2err(msg1.resultcode.data); + goto exit; + } + /* Now retrieve scan results */ + numbss = msg1.numbss.data; + + for (i = 0; i < numbss; i++) { + int freq; + + msg2->msgcode = DIDMSG_DOT11REQ_SCAN_RESULTS; + msg2->bssindex.data = i; + + result = p80211req_dorequest(wlandev, (u8 *)&msg2); + if ((result != 0) || + (msg2->resultcode.data != P80211ENUM_resultcode_success)) { + break; + } + + ie_buf[0] = WLAN_EID_SSID; + ie_buf[1] = msg2->ssid.data.len; + ie_len = ie_buf[1] + 2; + memcpy(&ie_buf[2], &msg2->ssid.data.data, msg2->ssid.data.len); + freq = ieee80211_channel_to_frequency(msg2->dschannel.data, + NL80211_BAND_2GHZ); + bss = cfg80211_inform_bss(wiphy, + ieee80211_get_channel(wiphy, freq), + CFG80211_BSS_FTYPE_UNKNOWN, + (const u8 *)&msg2->bssid.data.data, + msg2->timestamp.data, msg2->capinfo.data, + msg2->beaconperiod.data, + ie_buf, + ie_len, + (msg2->signal.data - 65536) * 100, /* Conversion to signed type */ + GFP_KERNEL); + + if (!bss) { + err = -ENOMEM; + goto exit; + } + + cfg80211_put_bss(wiphy, bss); + } + + if (result) + err = prism2_result2err(msg2->resultcode.data); + +exit: + info.aborted = !!(err); + cfg80211_scan_done(request, &info); + priv->scan_request = NULL; + kfree(msg2); + return err; +} + +static int prism2_set_wiphy_params(struct wiphy *wiphy, u32 changed) +{ + struct prism2_wiphy_private *priv = wiphy_priv(wiphy); + struct wlandevice *wlandev = priv->wlandev; + u32 data; + int result; + int err = 0; + + if (changed & WIPHY_PARAM_RTS_THRESHOLD) { + if (wiphy->rts_threshold == -1) + data = 2347; + else + data = wiphy->rts_threshold; + + result = prism2_domibset_uint32(wlandev, + DIDMIB_DOT11MAC_OPERATIONTABLE_RTSTHRESHOLD, + data); + if (result) { + err = -EFAULT; + goto exit; + } + } + + if (changed & WIPHY_PARAM_FRAG_THRESHOLD) { + if (wiphy->frag_threshold == -1) + data = 2346; + else + data = wiphy->frag_threshold; + + result = prism2_domibset_uint32(wlandev, + DIDMIB_DOT11MAC_OPERATIONTABLE_FRAGMENTATIONTHRESHOLD, + data); + if (result) { + err = -EFAULT; + goto exit; + } + } + +exit: + return err; +} + +static int prism2_connect(struct wiphy *wiphy, struct net_device *dev, + struct cfg80211_connect_params *sme) +{ + struct wlandevice *wlandev = dev->ml_priv; + struct ieee80211_channel *channel = sme->channel; + struct p80211msg_lnxreq_autojoin msg_join; + u32 did; + int length = sme->ssid_len; + int chan = -1; + int is_wep = (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP40) || + (sme->crypto.cipher_group == WLAN_CIPHER_SUITE_WEP104); + int result; + int err = 0; + + /* Set the channel */ + if (channel) { + chan = ieee80211_frequency_to_channel(channel->center_freq); + result = prism2_domibset_uint32(wlandev, + DIDMIB_DOT11PHY_DSSSTABLE_CURRENTCHANNEL, + chan); + if (result) + goto exit; + } + + /* Set the authorization */ + if ((sme->auth_type == NL80211_AUTHTYPE_OPEN_SYSTEM) || + ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && !is_wep)) + msg_join.authtype.data = P80211ENUM_authalg_opensystem; + else if ((sme->auth_type == NL80211_AUTHTYPE_SHARED_KEY) || + ((sme->auth_type == NL80211_AUTHTYPE_AUTOMATIC) && is_wep)) + msg_join.authtype.data = P80211ENUM_authalg_sharedkey; + else + netdev_warn(dev, + "Unhandled authorisation type for connect (%d)\n", + sme->auth_type); + + /* Set the encryption - we only support wep */ + if (is_wep) { + if (sme->key) { + if (sme->key_idx >= NUM_WEPKEYS) + return -EINVAL; + + result = prism2_domibset_uint32(wlandev, + DIDMIB_DOT11SMT_PRIVACYTABLE_WEPDEFAULTKEYID, + sme->key_idx); + if (result) + goto exit; + + /* send key to driver */ + did = didmib_dot11smt_wepdefaultkeystable_key(sme->key_idx + 1); + result = prism2_domibset_pstr32(wlandev, + did, sme->key_len, + (u8 *)sme->key); + if (result) + goto exit; + } + + /* Assume we should set privacy invoked and exclude unencrypted + * We could possible use sme->privacy here, but the assumption + * seems reasonable anyways + */ + result = prism2_domibset_uint32(wlandev, + DIDMIB_DOT11SMT_PRIVACYTABLE_PRIVACYINVOKED, + P80211ENUM_truth_true); + if (result) + goto exit; + + result = prism2_domibset_uint32(wlandev, + DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED, + P80211ENUM_truth_true); + if (result) + goto exit; + + } else { + /* Assume we should unset privacy invoked + * and exclude unencrypted + */ + result = prism2_domibset_uint32(wlandev, + DIDMIB_DOT11SMT_PRIVACYTABLE_PRIVACYINVOKED, + P80211ENUM_truth_false); + if (result) + goto exit; + + result = prism2_domibset_uint32(wlandev, + DIDMIB_DOT11SMT_PRIVACYTABLE_EXCLUDEUNENCRYPTED, + P80211ENUM_truth_false); + if (result) + goto exit; + } + + /* Now do the actual join. Note there is no way that I can + * see to request a specific bssid + */ + msg_join.msgcode = DIDMSG_LNXREQ_AUTOJOIN; + + memcpy(msg_join.ssid.data.data, sme->ssid, length); + msg_join.ssid.data.len = length; + + result = p80211req_dorequest(wlandev, (u8 *)&msg_join); + +exit: + if (result) + err = -EFAULT; + + return err; +} + +static int prism2_disconnect(struct wiphy *wiphy, struct net_device *dev, + u16 reason_code) +{ + struct wlandevice *wlandev = dev->ml_priv; + struct p80211msg_lnxreq_autojoin msg_join; + int result; + int err = 0; + + /* Do a join, with a bogus ssid. Thats the only way I can think of */ + msg_join.msgcode = DIDMSG_LNXREQ_AUTOJOIN; + + memcpy(msg_join.ssid.data.data, "---", 3); + msg_join.ssid.data.len = 3; + + result = p80211req_dorequest(wlandev, (u8 *)&msg_join); + + if (result) + err = -EFAULT; + + return err; +} + +static int prism2_join_ibss(struct wiphy *wiphy, struct net_device *dev, + struct cfg80211_ibss_params *params) +{ + return -EOPNOTSUPP; +} + +static int prism2_leave_ibss(struct wiphy *wiphy, struct net_device *dev) +{ + return -EOPNOTSUPP; +} + +static int prism2_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev, + enum nl80211_tx_power_setting type, int mbm) +{ + struct prism2_wiphy_private *priv = wiphy_priv(wiphy); + struct wlandevice *wlandev = priv->wlandev; + u32 data; + int result; + int err = 0; + + if (type == NL80211_TX_POWER_AUTOMATIC) + data = 30; + else + data = MBM_TO_DBM(mbm); + + result = prism2_domibset_uint32(wlandev, + DIDMIB_DOT11PHY_TXPOWERTABLE_CURRENTTXPOWERLEVEL, + data); + + if (result) { + err = -EFAULT; + goto exit; + } + +exit: + return err; +} + +static int prism2_get_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev, + int *dbm) +{ + struct prism2_wiphy_private *priv = wiphy_priv(wiphy); + struct wlandevice *wlandev = priv->wlandev; + struct p80211msg_dot11req_mibget msg; + struct p80211item_uint32 *mibitem; + int result; + int err = 0; + + mibitem = (struct p80211item_uint32 *)&msg.mibattribute.data; + msg.msgcode = DIDMSG_DOT11REQ_MIBGET; + mibitem->did = DIDMIB_DOT11PHY_TXPOWERTABLE_CURRENTTXPOWERLEVEL; + + result = p80211req_dorequest(wlandev, (u8 *)&msg); + + if (result) { + err = -EFAULT; + goto exit; + } + + *dbm = mibitem->data; + +exit: + return err; +} + +/* Interface callback functions, passing data back up to the cfg80211 layer */ +void prism2_connect_result(struct wlandevice *wlandev, u8 failed) +{ + u16 status = failed ? + WLAN_STATUS_UNSPECIFIED_FAILURE : WLAN_STATUS_SUCCESS; + + cfg80211_connect_result(wlandev->netdev, wlandev->bssid, + NULL, 0, NULL, 0, status, GFP_KERNEL); +} + +void prism2_disconnected(struct wlandevice *wlandev) +{ + cfg80211_disconnected(wlandev->netdev, 0, NULL, + 0, false, GFP_KERNEL); +} + +void prism2_roamed(struct wlandevice *wlandev) +{ + struct cfg80211_roam_info roam_info = { + .links[0].bssid = wlandev->bssid, + }; + + cfg80211_roamed(wlandev->netdev, &roam_info, GFP_KERNEL); +} + +/* Structures for declaring wiphy interface */ +static const struct cfg80211_ops prism2_usb_cfg_ops = { + .change_virtual_intf = prism2_change_virtual_intf, + .add_key = prism2_add_key, + .get_key = prism2_get_key, + .del_key = prism2_del_key, + .set_default_key = prism2_set_default_key, + .get_station = prism2_get_station, + .scan = prism2_scan, + .set_wiphy_params = prism2_set_wiphy_params, + .connect = prism2_connect, + .disconnect = prism2_disconnect, + .join_ibss = prism2_join_ibss, + .leave_ibss = prism2_leave_ibss, + .set_tx_power = prism2_set_tx_power, + .get_tx_power = prism2_get_tx_power, +}; + +/* Functions to create/free wiphy interface */ +static struct wiphy *wlan_create_wiphy(struct device *dev, + struct wlandevice *wlandev) +{ + struct wiphy *wiphy; + struct prism2_wiphy_private *priv; + + wiphy = wiphy_new(&prism2_usb_cfg_ops, sizeof(*priv)); + if (!wiphy) + return NULL; + + priv = wiphy_priv(wiphy); + priv->wlandev = wlandev; + memcpy(priv->channels, prism2_channels, sizeof(prism2_channels)); + memcpy(priv->rates, prism2_rates, sizeof(prism2_rates)); + priv->band.channels = priv->channels; + priv->band.n_channels = ARRAY_SIZE(prism2_channels); + priv->band.bitrates = priv->rates; + priv->band.n_bitrates = ARRAY_SIZE(prism2_rates); + priv->band.band = NL80211_BAND_2GHZ; + priv->band.ht_cap.ht_supported = false; + wiphy->bands[NL80211_BAND_2GHZ] = &priv->band; + + set_wiphy_dev(wiphy, dev); + wiphy->privid = prism2_wiphy_privid; + wiphy->max_scan_ssids = 1; + wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) + | BIT(NL80211_IFTYPE_ADHOC); + wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM; + wiphy->n_cipher_suites = PRISM2_NUM_CIPHER_SUITES; + wiphy->cipher_suites = prism2_cipher_suites; + + if (wiphy_register(wiphy) < 0) { + wiphy_free(wiphy); + return NULL; + } + + return wiphy; +} + +static void wlan_free_wiphy(struct wiphy *wiphy) +{ + wiphy_unregister(wiphy); + wiphy_free(wiphy); +} |