cregit-Linux how code gets into the kernel

Release 4.11 drivers/staging/rtl8188eu/os_dep/mon.c

/*
 * RTL8188EU monitor interface
 *
 * Copyright (C) 2015 Jakub Sitnicki
 *
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU General Public License version 2 as published by the
 * Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
 * details.
 */

#include <linux/ieee80211.h>
#include <linux/netdevice.h>
#include <net/cfg80211.h>

#include <drv_types.h>
#include <rtw_recv.h>
#include <rtw_xmit.h>
#include <mon.h>

/**
 * unprotect_frame() - unset Protected flag and strip off IV and ICV/MIC
 */

static void unprotect_frame(struct sk_buff *skb, int iv_len, int icv_len) { struct ieee80211_hdr *hdr; int hdr_len; hdr = (struct ieee80211_hdr *)skb->data; hdr_len = ieee80211_hdrlen(hdr->frame_control); if (skb->len < hdr_len + iv_len + icv_len) return; if (!ieee80211_has_protected(hdr->frame_control)) return; hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_PROTECTED); memmove(skb->data + iv_len, skb->data, hdr_len); skb_pull(skb, iv_len); skb_trim(skb, skb->len - icv_len); }

Contributors

PersonTokensPropCommitsCommitProp
Jakub Sitnicki112100.00%1100.00%
Total112100.00%1100.00%


static void mon_recv_decrypted(struct net_device *dev, const u8 *data, int data_len, int iv_len, int icv_len) { struct sk_buff *skb; skb = netdev_alloc_skb(dev, data_len); if (!skb) return; memcpy(skb_put(skb, data_len), data, data_len); /* * Frame data is not encrypted. Strip off protection so * userspace doesn't think that it is. */ unprotect_frame(skb, iv_len, icv_len); skb->ip_summed = CHECKSUM_UNNECESSARY; skb->protocol = eth_type_trans(skb, dev); netif_rx(skb); }

Contributors

PersonTokensPropCommitsCommitProp
Jakub Sitnicki91100.00%1100.00%
Total91100.00%1100.00%


static void mon_recv_encrypted(struct net_device *dev, const u8 *data, int data_len) { if (net_ratelimit()) netdev_info(dev, "Encrypted packets are not supported"); }

Contributors

PersonTokensPropCommitsCommitProp
Jakub Sitnicki31100.00%1100.00%
Total31100.00%1100.00%

/** * rtl88eu_mon_recv_hook() - forward received frame to the monitor interface * * Assumes that the frame contains an IV and an ICV/MIC, and that * encrypt field in frame->attrib have been set accordingly. */
void rtl88eu_mon_recv_hook(struct net_device *dev, struct recv_frame *frame) { struct rx_pkt_attrib *attr; int iv_len, icv_len; int data_len; u8 *data; if (!dev || !frame) return; if (!netif_running(dev)) return; attr = &frame->attrib; data = frame->pkt->data; data_len = frame->pkt->len; /* Broadcast and multicast frames don't have attr->{iv,icv}_len set */ SET_ICE_IV_LEN(iv_len, icv_len, attr->encrypt); if (attr->bdecrypted) mon_recv_decrypted(dev, data, data_len, iv_len, icv_len); else mon_recv_encrypted(dev, data, data_len); }

Contributors

PersonTokensPropCommitsCommitProp
Jakub Sitnicki10995.61%150.00%
Ivan Safonov54.39%150.00%
Total114100.00%2100.00%

/** * rtl88eu_mon_xmit_hook() - forward trasmitted frame to the monitor interface * * Assumes that: * - frame header contains an IV and frame->attrib.iv_len is set accordingly, * - data is not encrypted and ICV/MIC has not been appended yet. */
void rtl88eu_mon_xmit_hook(struct net_device *dev, struct xmit_frame *frame, uint frag_len) { struct pkt_attrib *attr; u8 *data; int i, offset; if (!dev || !frame) return; if (!netif_running(dev)) return; attr = &frame->attrib; offset = TXDESC_SIZE + frame->pkt_offset * PACKET_OFFSET_SZ; data = frame->buf_addr + offset; for (i = 0; i < attr->nr_frags - 1; i++) { mon_recv_decrypted(dev, data, frag_len, attr->iv_len, 0); data += frag_len; data = (u8 *)round_up((size_t)data, 4); } /* Last fragment has different length */ mon_recv_decrypted(dev, data, attr->last_txcmdsz, attr->iv_len, 0); }

Contributors

PersonTokensPropCommitsCommitProp
Jakub Sitnicki147100.00%1100.00%
Total147100.00%1100.00%


static netdev_tx_t mon_xmit(struct sk_buff *skb, struct net_device *dev) { dev_kfree_skb(skb); return NETDEV_TX_OK; }

Contributors

PersonTokensPropCommitsCommitProp
Jakub Sitnicki24100.00%1100.00%
Total24100.00%1100.00%

static const struct net_device_ops mon_netdev_ops = { .ndo_start_xmit = mon_xmit, .ndo_set_mac_address = eth_mac_addr, .ndo_validate_addr = eth_validate_addr, };
static void mon_setup(struct net_device *dev) { dev->netdev_ops = &mon_netdev_ops; dev->destructor = free_netdev; ether_setup(dev); dev->priv_flags |= IFF_NO_QUEUE; dev->type = ARPHRD_IEEE80211; /* * Use a locally administered address (IEEE 802) * XXX: Copied from mac80211_hwsim driver. Revisit. */ eth_zero_addr(dev->dev_addr); dev->dev_addr[0] = 0x12; }

Contributors

PersonTokensPropCommitsCommitProp
Jakub Sitnicki5594.83%150.00%
Phil Sutter35.17%150.00%
Total58100.00%2100.00%


struct net_device *rtl88eu_mon_init(void) { struct net_device *dev; int err; dev = alloc_netdev(0, "mon%d", NET_NAME_UNKNOWN, mon_setup); if (!dev) goto fail; err = register_netdev(dev); if (err < 0) goto fail_free_dev; return dev; fail_free_dev: free_netdev(dev); fail: return NULL; }

Contributors

PersonTokensPropCommitsCommitProp
Jakub Sitnicki69100.00%1100.00%
Total69100.00%1100.00%


void rtl88eu_mon_deinit(struct net_device *dev) { if (!dev) return; unregister_netdev(dev); }

Contributors

PersonTokensPropCommitsCommitProp
Jakub Sitnicki21100.00%1100.00%
Total21100.00%1100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Jakub Sitnicki70498.46%125.00%
Ivan Safonov50.70%125.00%
Larry Finger30.42%125.00%
Phil Sutter30.42%125.00%
Total715100.00%4100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.