1
0
Files
Greg Kroah-Hartman 3fdf221337 Merge 4.9.257 into android-4.9-q
Changes in 4.9.257
	net: dsa: bcm_sf2: put device node before return
	ibmvnic: Ensure that CRQ entry read are correctly ordered
	net_sched: reject silly cell_log in qdisc_get_rtab()
	futex,rt_mutex: Provide futex specific rt_mutex API
	futex: Remove rt_mutex_deadlock_account_*()
	futex: Rework inconsistent rt_mutex/futex_q state
	futex: Avoid violating the 10th rule of futex
	futex: Replace pointless printk in fixup_owner()
	futex: Provide and use pi_state_update_owner()
	rtmutex: Remove unused argument from rt_mutex_proxy_unlock()
	futex: Use pi_state_update_owner() in put_pi_state()
	futex: Simplify fixup_pi_state_owner()
	futex: Handle faults correctly for PI futexes
	scsi: libfc: Avoid invoking response handler twice if ep is already completed
	mac80211: fix fast-rx encryption check
	scsi: ibmvfc: Set default timeout to avoid crash during migration
	objtool: Don't fail on missing symbol table
	stable: clamp SUBLEVEL in 4.4 and 4.9
	USB: serial: cp210x: add pid/vid for WSDA-200-USB
	USB: serial: cp210x: add new VID/PID for supporting Teraoka AD2000
	USB: serial: option: Adding support for Cinterion MV31
	Input: i8042 - unbreak Pegatron C15B
	net: lapb: Copy the skb before sending a packet
	elfcore: fix building with clang
	USB: gadget: legacy: fix an error code in eth_bind()
	USB: usblp: don't call usb_set_interface if there's a single alt
	usb: dwc2: Fix endpoint direction check in ep_from_windex
	mac80211: fix station rate table updates on assoc
	kretprobe: Avoid re-registration of the same kretprobe earlier
	xhci: fix bounce buffer usage for non-sg list case
	cifs: report error instead of invalid when revalidating a dentry fails
	mmc: core: Limit retries when analyse of SDIO tuples fails
	ARM: footbridge: fix dc21285 PCI configuration accessors
	mm: hugetlbfs: fix cannot migrate the fallocated HugeTLB page
	mm: hugetlb: fix a race between isolating and freeing page
	mm: hugetlb: remove VM_BUG_ON_PAGE from page_huge_active
	mm: thp: fix MADV_REMOVE deadlock on shmem THP
	x86/build: Disable CET instrumentation in the kernel
	x86/apic: Add extra serialization for non-serializing MSRs
	Input: xpad - sync supported devices with fork on GitHub
	ACPI: thermal: Do not call acpi_thermal_check() directly
	iommu/vt-d: Do not use flush-queue when caching-mode is on
	ALSA: hda/realtek - Fix typo of pincfg for Dell quirk
	Linux 4.9.257

Signed-off-by: Greg Kroah-Hartman <gregkh@google.com>
Change-Id: I0c0cef0706decd8fd5c8da6b276e83bdcc7ea066
2021-02-11 23:37:19 +03:00

211 lines
4.9 KiB
C

/*
* LAPB release 002
*
* This code REQUIRES 2.1.15 or higher/ NET3.038
*
* This module:
* This module is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version
* 2 of the License, or (at your option) any later version.
*
* History
* LAPB 001 Jonathan Naylor Started Coding
* LAPB 002 Jonathan Naylor New timer architecture.
*/
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/socket.h>
#include <linux/in.h>
#include <linux/kernel.h>
#include <linux/timer.h>
#include <linux/string.h>
#include <linux/sockios.h>
#include <linux/net.h>
#include <linux/inet.h>
#include <linux/skbuff.h>
#include <linux/slab.h>
#include <net/sock.h>
#include <asm/uaccess.h>
#include <linux/fcntl.h>
#include <linux/mm.h>
#include <linux/interrupt.h>
#include <net/lapb.h>
/*
* This procedure is passed a buffer descriptor for an iframe. It builds
* the rest of the control part of the frame and then writes it out.
*/
static void lapb_send_iframe(struct lapb_cb *lapb, struct sk_buff *skb, int poll_bit)
{
unsigned char *frame;
if (!skb)
return;
if (lapb->mode & LAPB_EXTENDED) {
frame = skb_push(skb, 2);
frame[0] = LAPB_I;
frame[0] |= lapb->vs << 1;
frame[1] = poll_bit ? LAPB_EPF : 0;
frame[1] |= lapb->vr << 1;
} else {
frame = skb_push(skb, 1);
*frame = LAPB_I;
*frame |= poll_bit ? LAPB_SPF : 0;
*frame |= lapb->vr << 5;
*frame |= lapb->vs << 1;
}
lapb_dbg(1, "(%p) S%d TX I(%d) S%d R%d\n",
lapb->dev, lapb->state, poll_bit, lapb->vs, lapb->vr);
lapb_transmit_buffer(lapb, skb, LAPB_COMMAND);
}
void lapb_kick(struct lapb_cb *lapb)
{
struct sk_buff *skb, *skbn;
unsigned short modulus, start, end;
modulus = (lapb->mode & LAPB_EXTENDED) ? LAPB_EMODULUS : LAPB_SMODULUS;
start = !skb_peek(&lapb->ack_queue) ? lapb->va : lapb->vs;
end = (lapb->va + lapb->window) % modulus;
if (!(lapb->condition & LAPB_PEER_RX_BUSY_CONDITION) &&
start != end && skb_peek(&lapb->write_queue)) {
lapb->vs = start;
/*
* Dequeue the frame and copy it.
*/
skb = skb_dequeue(&lapb->write_queue);
do {
skbn = skb_copy(skb, GFP_ATOMIC);
if (!skbn) {
skb_queue_head(&lapb->write_queue, skb);
break;
}
if (skb->sk)
skb_set_owner_w(skbn, skb->sk);
/*
* Transmit the frame copy.
*/
lapb_send_iframe(lapb, skbn, LAPB_POLLOFF);
lapb->vs = (lapb->vs + 1) % modulus;
/*
* Requeue the original data frame.
*/
skb_queue_tail(&lapb->ack_queue, skb);
} while (lapb->vs != end && (skb = skb_dequeue(&lapb->write_queue)) != NULL);
lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
if (!lapb_t1timer_running(lapb))
lapb_start_t1timer(lapb);
}
}
void lapb_transmit_buffer(struct lapb_cb *lapb, struct sk_buff *skb, int type)
{
unsigned char *ptr;
ptr = skb_push(skb, 1);
if (lapb->mode & LAPB_MLP) {
if (lapb->mode & LAPB_DCE) {
if (type == LAPB_COMMAND)
*ptr = LAPB_ADDR_C;
if (type == LAPB_RESPONSE)
*ptr = LAPB_ADDR_D;
} else {
if (type == LAPB_COMMAND)
*ptr = LAPB_ADDR_D;
if (type == LAPB_RESPONSE)
*ptr = LAPB_ADDR_C;
}
} else {
if (lapb->mode & LAPB_DCE) {
if (type == LAPB_COMMAND)
*ptr = LAPB_ADDR_A;
if (type == LAPB_RESPONSE)
*ptr = LAPB_ADDR_B;
} else {
if (type == LAPB_COMMAND)
*ptr = LAPB_ADDR_B;
if (type == LAPB_RESPONSE)
*ptr = LAPB_ADDR_A;
}
}
lapb_dbg(2, "(%p) S%d TX %3ph\n", lapb->dev, lapb->state, skb->data);
if (!lapb_data_transmit(lapb, skb))
kfree_skb(skb);
}
void lapb_establish_data_link(struct lapb_cb *lapb)
{
lapb->condition = 0x00;
lapb->n2count = 0;
if (lapb->mode & LAPB_EXTENDED) {
lapb_dbg(1, "(%p) S%d TX SABME(1)\n", lapb->dev, lapb->state);
lapb_send_control(lapb, LAPB_SABME, LAPB_POLLON, LAPB_COMMAND);
} else {
lapb_dbg(1, "(%p) S%d TX SABM(1)\n", lapb->dev, lapb->state);
lapb_send_control(lapb, LAPB_SABM, LAPB_POLLON, LAPB_COMMAND);
}
lapb_start_t1timer(lapb);
lapb_stop_t2timer(lapb);
}
void lapb_enquiry_response(struct lapb_cb *lapb)
{
lapb_dbg(1, "(%p) S%d TX RR(1) R%d\n",
lapb->dev, lapb->state, lapb->vr);
lapb_send_control(lapb, LAPB_RR, LAPB_POLLON, LAPB_RESPONSE);
lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
}
void lapb_timeout_response(struct lapb_cb *lapb)
{
lapb_dbg(1, "(%p) S%d TX RR(0) R%d\n",
lapb->dev, lapb->state, lapb->vr);
lapb_send_control(lapb, LAPB_RR, LAPB_POLLOFF, LAPB_RESPONSE);
lapb->condition &= ~LAPB_ACK_PENDING_CONDITION;
}
void lapb_check_iframes_acked(struct lapb_cb *lapb, unsigned short nr)
{
if (lapb->vs == nr) {
lapb_frames_acked(lapb, nr);
lapb_stop_t1timer(lapb);
lapb->n2count = 0;
} else if (lapb->va != nr) {
lapb_frames_acked(lapb, nr);
lapb_start_t1timer(lapb);
}
}
void lapb_check_need_response(struct lapb_cb *lapb, int type, int pf)
{
if (type == LAPB_COMMAND && pf)
lapb_enquiry_response(lapb);
}