GitHub/exynos8895/android_kernel_samsung_universal8895.git
8 years agousb: gadget: Move gadget functions code
Badhri Jagan Sridharan [Fri, 27 Mar 2015 21:49:55 +0000 (14:49 -0700)]
usb: gadget: Move gadget functions code

3.18 kernel has reorganized drivers/usb/gadget
directory. Moving gadget functions drivers from
drivers/usb/gadget to drivers/usb/gadget/function

Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
Change-Id: I1eab0190f8d42e3be1b4e91ad3bc3a2dc853b0ef

8 years agousb:gadget:audio_source: Move to USB_FUNCTION API
Badhri Jagan Sridharan [Sun, 23 Nov 2014 21:51:28 +0000 (13:51 -0800)]
usb:gadget:audio_source: Move to USB_FUNCTION API

This patch adds support to use audio_source
gadget function through DECLARE_USB_FUNCTION_INIT
interface.

Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
Change-Id: I1fc6c9ea07105ae4eb785eebd3bb925bfdd8bc6b

8 years agousb: gadget: Add function devices to the parent
Badhri Jagan Sridharan [Fri, 27 Mar 2015 21:15:19 +0000 (14:15 -0700)]
usb: gadget: Add function devices to the parent

Added create_function_device to create child
function devices for USB gadget functions.
Android UsbDeviceManager relies on communicating
to the devices created by the gadget functions
to implement functions such as audio_source.

Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
Change-Id: I0df9ad86ac32d8cdacdea164e9fed49891b45fc2

8 years agousb: gadget: f_audio_source:replace deprecated API
Badhri Jagan Sridharan [Wed, 25 Mar 2015 21:37:23 +0000 (14:37 -0700)]
usb: gadget: f_audio_source:replace deprecated API

Replace snd_card_create with snd_card_new.
snd_card_create depcrecated starting form v3.15

Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
Change-Id: I76f7d753812963d595055bce7d3e6518163482f5

8 years agousb: gadget: check for accessory device before disconnecting HIDs
Amit Pundir [Fri, 16 Jan 2015 00:11:10 +0000 (05:41 +0530)]
usb: gadget: check for accessory device before disconnecting HIDs

While disabling ConfigFS Android gadget, android_disconnect() calls
kill_all_hid_devices(), if CONFIG_USB_CONFIGFS_F_ACC is enabled, to free
the registered HIDs without checking whether the USB accessory device
really exist or not. If USB accessory device doesn't exist then we run into
following kernel panic:
----8<----
[  136.724761] Unable to handle kernel NULL pointer dereference at virtual address 00000064
[  136.724809] pgd = c0204000
[  136.731924] [00000064] *pgd=00000000
[  136.737830] Internal error: Oops: 5 [#1] SMP ARM
[  136.738108] CPU: 0 PID: 0 Comm: swapper/0 Not tainted 3.18.0-rc4-00400-gf75300e-dirty #76
[  136.742788] task: c0fb19d8 ti: c0fa4000 task.ti: c0fa4000
[  136.750890] PC is at _raw_spin_lock_irqsave+0x24/0x60
[  136.756246] LR is at kill_all_hid_devices+0x24/0x114
---->8----

This patch adds a test to check if USB Accessory device exists before freeing HIDs.

Change-Id: Ie229feaf0de3f4f7a151fcaa9a994e34e15ff73b
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
8 years agousb: u_ether: Fix compile errors
Praneeth Bajjuri [Thu, 22 Jan 2015 22:38:56 +0000 (16:38 -0600)]
usb: u_ether: Fix compile errors

commit f1a1823ff24fa4e3412b5078f20021cf40834946
usb: gadget: u_ether: convert into module

changes qlen function definition. and this has to be fixed
accordingly in current u_ether driver.

This patch fixes following compile error in u_ether caused by commit.

drivers/usb/gadget/u_ether.c: In function 'rx_fill':
drivers/usb/gadget/u_ether.c:416:3: error: too few arguments to function 'qlen'
   if (++req_cnt > qlen(dev->gadget))
   ^

drivers/usb/gadget/u_ether.c: In function 'eth_start_xmit':
drivers/usb/gadget/u_ether.c:738:24: error: 'qmult' undeclared (first use in this function)
   if (dev->tx_qlen == (qmult/2)) {

which was caused by commits
commit 79467317949e1621240f632acfb7453783bec2e7
USB: gadget: u_ether: Fix data stall issue in RNDIS tethering mode

commit 68b91e8c54f5c091986c5719631893b10eab760a
usb: u_ether: Add workqueue as bottom half handler for rx data path

Change-Id: Ic4e5a1e08cb688e5a606c7c1895f869d8f887b9f
Signed-off-by: Praneeth Bajjuri <praneeth@ti.com>
8 years agousb: gadget: Add Uevent to notify userspace
Badhri Jagan Sridharan [Mon, 15 Dec 2014 18:44:47 +0000 (10:44 -0800)]
usb: gadget: Add Uevent to notify userspace

Android userspace UsbDeviceManager relies on the
uevents generated by the composition driver to
generate user notifications. This CL adds uevents
to be generated whenever USB changes its state
i.e. connected, disconnected, configured.

This CL also intercepts the setup requests from
the usb_core anb routes it to the specific
usb function if required.

Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
Change-Id: Ib3d3a78255a532f7449dac286f776c2966caf8c1

8 years agousb: gadget: configfs: Add usb_function ptr to fi struct
Badhri Jagan Sridharan [Tue, 16 Dec 2014 00:42:27 +0000 (16:42 -0800)]
usb: gadget: configfs: Add usb_function ptr to fi struct

Add a pointer to the usb_function inside the
usb_function_instance structure to service
functions specific setup requests even before
the function gets added to the usb_gadget

Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
Change-Id: I6f457006f6c5516cc6986ec2acdf5b1ecf259d0c

8 years agousb: gadget: mtp/ptp: Migrate functions to the USB_FUNCTION interface
Badhri Jagan Sridharan [Tue, 18 Nov 2014 05:11:23 +0000 (21:11 -0800)]
usb: gadget: mtp/ptp: Migrate functions to the USB_FUNCTION interface

This patch adds support to use mtp/ptp gadget functions
through the DECLARE_USB_FUNCTION_INIT interface.

enabling USB_CONFIGFS_F_MTP config compiles f_mtp.c
thereby providing support for MTP gadget

enabling USB_CONFIGFS_F_PTP config compiles f_ptp.c
thereby providing support for PTP gadget

Signed-off-by: Badhri Jagan Sridharan <badhri@google.com>
Change-Id: I38d7b570e8886d155ef10cd2c839b2232dcb3158

8 years agoUSB: gadget: rndis: Add module parameter for DL max packets per xfer
xerox_lin [Thu, 4 Sep 2014 08:01:59 +0000 (16:01 +0800)]
USB: gadget: rndis: Add module parameter for DL max packets per xfer

Currently DL aggregation is supported in RNDIS driver and is set to
3 by default. And there is no support to change downlink maximum
packets per transfer at runtime through module parameter. Hence add
module parameter for DL maximum packets per transfer to change it at
runtime.

echo 6 > /sys/module/g_android/parameters/rndis_dl_max_pkt_per_xfer

To disable DL aggregation during runtime,

echo 1 > /sys/module/g_android/parameters/rndis_dl_max_pkt_per_xfer

Change-Id: I3a1d0bc97358e2b6f233df7ae8725fb507de50db
Signed-off-by: Xerox Lin <xerox_lin@htc.com>
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
8 years agondis: Add debug support to disable RNDIS Multipacket Feature
Badhri Jagan Sridharan [Thu, 18 Sep 2014 17:48:48 +0000 (10:48 -0700)]
ndis: Add debug support to disable RNDIS Multipacket Feature

This change adds module param which allows to disable RNDIS
Multi-packet Feature (Aggregation support in Downlink path)
as this feature is enabled by default.

To disable use this param before moving to RNDIS Composition:
echo 1 > /sys/module/g_android/parameters/rndis_multipacket_dl_disable

Also counts errors as Rx errors if received RNDIS packets are
not following RNDIS message format as those packets are being
discarded.

Change-Id: I764430da78f2204af92e14bb279c11b24c7e4c67
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
8 years agoRNDIS: Add Data aggregation (multi packet) support
Badhri Jagan Sridharan [Thu, 18 Sep 2014 17:46:08 +0000 (10:46 -0700)]
RNDIS: Add Data aggregation (multi packet) support

Add data aggregation support using RNDIS Multi Packet feature
to achieve better UDP Downlink throughput. Max 3 RNDIS Packets
aggregated into one RNDIS Packet with this implementation.

With this change, seeing UDP Downlink throughput increase
from 90 Mbps to above 100 Mbps when using Iperf and sending
data more than 100 Mbps.

Change-Id: I21c39482718944bb1b1068bdd02f626531e58f08
Signed-off-by: Mayank Rana <mrana@codeaurora.org>
Signed-off-by: Rajkumar Raghupathy <raghup@codeaurora.org>
8 years agoUSB: gadget: u_ether: Fix data stall issue in RNDIS tethering mode
Badhri Jagan Sridharan [Thu, 18 Sep 2014 17:42:41 +0000 (10:42 -0700)]
USB: gadget: u_ether: Fix data stall issue in RNDIS tethering mode

For dual speed gadget, with current no. of request(10), there is
possibility of corner case occurence where all 10 reuqests are queued
to HW without setting IOC bit, which could lead to data stall in
RNDIS tethering and RNDIS local networking.

With this patch, counter will be incremented before queueing request to
HW and sets IOC bit for every nth request due to which the corner case
of all requests queued to HW without IOC bit set will be avoided.

Change-Id: I26515bfd9bbc8f7af38be7835692143f7093118a
Signed-off-by: Vijayavardhan Vennapusa <vvreddy@codeaurora.org>
8 years agousb: gadget: prevent change of Host MAC address of 'usb0' interface
taeju.park [Fri, 14 Sep 2012 05:09:03 +0000 (14:09 +0900)]
usb: gadget: prevent change of Host MAC address of 'usb0' interface

On windows 7 platform, previously allocated ip address is maintained.
However, Host MAC address of 'usb0' interface is changed when the
tethering driver re-enumerated. Thus, the tethering network driver
can't be allocated ip address from dhcp. It causes connection delay
between host and phone for usb tethering.

This patch prevents from changing Host MAC address of 'usb0' interface.
In other words, this patch maintains the Host MAC address allocated when
first tethering driver although the driver is re-enumerated. However,
after reboot, the Host MAC address can be changed.

Change-Id: I43add9925e9d6d90c56cffbd3ed999104448f818
Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
8 years agousb: u_ether: Add workqueue as bottom half handler for rx data path
Badhri Jagan Sridharan [Thu, 25 Sep 2014 01:58:23 +0000 (18:58 -0700)]
usb: u_ether: Add workqueue as bottom half handler for rx data path

u_ether driver passes rx data to network layer and resubmits the
request back to usb hardware in interrupt context. Network layer
processes rx data by scheduling tasklet. For high throughput
scenarios on rx data path driver is spending lot of time in interrupt
context due to rx data processing by tasklet and continuous completion
and re-submission of the usb requests which results in watchdog bark.
Hence move the rx data processing and usb request submission to a
workqueue bottom half handler.

Change-Id: I316de8e267997137ac189a8b7b2846fa325f4a5a
Signed-off-by: Badhri Jagan Sridharan <Badhri@google.com>
8 years agousb: Add support for rndis uplink aggregation
xerox_lin [Thu, 14 Aug 2014 06:48:44 +0000 (14:48 +0800)]
usb: Add support for rndis uplink aggregation

RNDIS protocol supports data aggregation on uplink and can help
reduce mips by reducing number of interrupts on device. Throughput
also improved by 20-30%. Aggregation is disabled by setting
aggregation packet size to 1. To help better UL throughput, set
as ul aggregation support to 3 rndis packets by default. It can be
configured via module parameter: rndis_ul_max_pkt_per_xfer.

Change-Id: I0b62a21a5c3ceb6b04933d0d6da33301dbafe493
Signed-off-by: Vamsi Krishna <vskrishn@codeaurora.org>
Signed-off-by: Xerox Lin <xerox_lin@htc.com>
8 years agoUSB: rndis: Free the rndis response queue during REMOTE_NDIS_RESET_MSG
xerox_lin [Mon, 18 Aug 2014 13:54:23 +0000 (21:54 +0800)]
USB: rndis: Free the rndis response queue during REMOTE_NDIS_RESET_MSG

When rndis data transfer is in progress, some Windows7 Host PC is not
sending the GET_ENCAPSULATED_RESPONSE command for receiving the response
for the previous SEND_ENCAPSULATED_COMMAND processed.

The rndis function driver appends each response for the
SEND_ENCAPSULATED_COMMAND in a queue. As the above process got corrupted,
the Host sends a REMOTE_NDIS_RESET_MSG command to do a soft-reset.
As the rndis response queue is not freed, the previous response is sent
as a part of this REMOTE_NDIS_RESET_MSG's reset response and the Host
blocks any more Rndis transfers.

Hence free the rndis response queue as a part of this soft-reset so that
the current response for REMOTE_NDIS_RESET_MSG is sent properly during the
response command.

Change-Id: I8eff3849db452fe01b7d1fe4140ef1f1ad3f4fd4
Signed-off-by: Rajkumar Raghupathy <raghup@codeaurora.org>
Signed-off-by: Xerox Lin <xerox_lin@htc.com>
8 years agousb: gadget: f_audio_source: Fixed USB Audio Class Interface Descriptor
Anson Jacob [Mon, 23 Jun 2014 11:14:01 +0000 (19:14 +0800)]
usb: gadget: f_audio_source: Fixed USB Audio Class Interface Descriptor

Fixed Android Issue #56549.

When both Vendor Class and Audio Class are activated for AOA 2.0,
the baInterfaceNr of the AudioControl Interface Descriptor points
to wrong interface numbers. They should be pointing to
Audio Control Device and Audio Streaming interfaces.

Replaced baInterfaceNr with the correct value.

Change-Id: Iaa083f3d97c1f0fc9481bf87852b2b51278a6351
Signed-off-by: Anson Jacob <ansonkuzhumbil@gmail.com>
8 years agousb: gadget: f_audio_source: change max ISO packet size
Anson Jacob [Tue, 1 Jul 2014 10:17:20 +0000 (18:17 +0800)]
usb: gadget: f_audio_source: change max ISO packet size

Re-applying from
https://gitorious.org/shr/linux/commit/eb4c9d2db894c3492c0a848581bd4f6790f93d5f

Most USB-AUDIO devices are limited to 256 byte for max iso buffer size.
If a IN_EP_MAX_PACKET_SIZE is bigger than a USB-AUDIO device's max iso
buffer size, it will cause noise. This patch will prevent this case as
possibe by reducing packet size. When using 44.1khz, 2ch, 16bit audio
data, if max packet size is bigger than 176 bytes, it's no problem.

Credits to: Iliyan Malchev <malchev@google.com>

Change-Id: Ic2a1c19ea65d5fb42bf12926b51b255b465d7215
Signed-off-by: Anson Jacob <ansonkuzhumbil@gmail.com>
8 years agousb: gadget: f_accessory: Enabled Zero Length Packet (ZLP) for acc_write
Anson Jacob [Mon, 23 Jun 2014 11:07:44 +0000 (19:07 +0800)]
usb: gadget: f_accessory: Enabled Zero Length Packet (ZLP) for acc_write

Accessory connected to Android Device requires
Zero Length Packet (ZLP) to be written when data
transferred out from the Android device are multiples
of wMaxPacketSize (64bytes (Full-Speed) / 512bytes (High-Speed))
to end the transfer.

Change-Id: Ib2c2c0ab98ef9afa10e74a720142deca5c0ed476
Signed-off-by: Anson Jacob <ansonkuzhumbil@gmail.com>
8 years agodrivers: usb: gadget: 64-bit related type fixes
Greg Hackmann [Mon, 24 Feb 2014 18:19:13 +0000 (10:19 -0800)]
drivers: usb: gadget: 64-bit related type fixes

Change-Id: I2f9b12e1e0cdfe64ffe20db78d319a6221821184
Signed-off-by: Greg Hackmann <ghackmann@google.com>
8 years agousb: gadget: f_accessory: move userspace interface to uapi
Colin Cross [Thu, 7 Nov 2013 21:08:39 +0000 (13:08 -0800)]
usb: gadget: f_accessory: move userspace interface to uapi

Move the entire contents of linux/usb/f_accessory.h header to uapi,
it only contains a userspace interface.

Change-Id: Ieb5547da449588ae554988a201c0e6b4e3afc531
Signed-off-by: Colin Cross <ccross@android.com>
8 years agousb: gadget: f_mtp: move userspace interface to uapi
Colin Cross [Thu, 7 Nov 2013 21:08:15 +0000 (13:08 -0800)]
usb: gadget: f_mtp: move userspace interface to uapi

Move the most of linux/usb/f_mtp.h header to uapi.  Move the only
remaining structure definition into f_mtp.c, the only place that
uses it.

Change-Id: I952c1a9dc15c36bf295a0eb4d74b6b1ad912ed03
Signed-off-by: Colin Cross <ccross@android.com>
8 years agoUSB: remove duplicate out endpoint creation in MTP mode
Peter Oh [Thu, 12 Sep 2013 01:42:18 +0000 (01:42 +0000)]
USB: remove duplicate out endpoint creation in MTP mode

Android MTP gadget uses 3 endpoints which are 1 in endpoint,
1 out endpoint, and 1 interrupt endpoint. However when MTP
gadget creates its endpoints, it creates the out endpoint twice
and overwrites the first created out endpoint with the second one,
so that it causes a leak of endpoint resources.

Change-Id: Iba82950095610b26b362f4b10a67cedfb1fee366
Signed-off-by: Peter Oh <poh@broadcom.com>
Reviewed-on: http://mps-gerrit.broadcom.com/37744
Reviewed-by: Graham Williams <gwilli@broadcom.com>
Reviewed-by: John Garry <jgarry@broadcom.com>
Branch-Open: Branch Status <branch_status_noreply@broadcom.com>
Reviewed-by: Checkpatch Status <checkpatch_status_noreply@broadcom.com>
Reviewed-by: Joyjit Nath <joyjit@broadcom.com>
Tested-by: AutoSubmit Status <autosubmit_status_noreply@broadcom.com>
8 years agousb: gadget: Fix android gadget driver build
Benoit Goby [Tue, 6 Nov 2012 02:47:08 +0000 (18:47 -0800)]
usb: gadget: Fix android gadget driver build

Removed obsolete f_adb function

Change-Id: Idfb4110429bc0ea63f493c68ad667f49ca471987
Signed-off-by: Benoit Goby <benoit@android.com>
8 years agousb: gadget: android: Fixes and hacks to make android usb gadget compile on 3.8
Arve Hjønnevåg [Wed, 28 Nov 2012 03:29:04 +0000 (19:29 -0800)]
usb: gadget: android: Fixes and hacks to make android usb gadget compile on 3.8

Change-Id: I332a6802dbd49b4018b9318b8621d26ed94c955d
Signed-off-by: Arve Hjønnevåg <arve@android.com>
8 years agousb: otg: otg-wakelock: Fix build for 3.7
Arve Hjønnevåg [Tue, 27 Nov 2012 00:09:13 +0000 (16:09 -0800)]
usb: otg: otg-wakelock: Fix build for 3.7

Signed-off-by: Arve Hjønnevåg <arve@android.com>
8 years agousb: gadget: accessory: Fix section mismatch (again)
Todd Poynor [Wed, 28 Nov 2012 21:03:40 +0000 (13:03 -0800)]
usb: gadget: accessory: Fix section mismatch (again)

create_bulk_endpoints should not be __init since it is called when
accessory is enabled.

Change-Id: Iac6e9f29d53c93760e926efd8e7603432632acb4
Signed-off-by: Todd Poynor <toddpoynor@google.com>
8 years agoUSB: gadget: f_audio_source: New gadget driver for audio output
Mike Lockwood [Fri, 11 May 2012 16:01:08 +0000 (09:01 -0700)]
USB: gadget: f_audio_source: New gadget driver for audio output

This driver presents a standard USB audio class interface to the host
and an ALSA PCM device to userspace

Change-Id: If16b14a5ff27045f9cb2daaf1ae9195c5eeab7d0
Signed-off-by: Mike Lockwood <lockwood@google.com>
8 years agoUSB: gadget: f_accessory: Add support for HID input devices
Mike Lockwood [Mon, 26 Mar 2012 18:03:55 +0000 (11:03 -0700)]
USB: gadget: f_accessory: Add support for HID input devices

Change-Id: I4f1452db32508382df52acdc47c0eb395ae328c7
Signed-off-by: Mike Lockwood <lockwood@google.com>
8 years agoUSB: gadget: Add ACCESSORY_SET_AUDIO_MODE control request and ioctl
Mike Lockwood [Fri, 11 May 2012 16:00:40 +0000 (09:00 -0700)]
USB: gadget: Add ACCESSORY_SET_AUDIO_MODE control request and ioctl

The control request will be used by the host to enable/disable USB audio
and the ioctl will be used by userspace to read the audio mode

Change-Id: I81c38611b588451e80eacdccc417ca6e11c60cab
Signed-off-by: Mike Lockwood <lockwood@google.com>
8 years agousb: gadget: accessory: Fix section mismatch
Benoit Goby [Sat, 23 Jun 2012 01:17:10 +0000 (18:17 -0700)]
usb: gadget: accessory: Fix section mismatch

create_bulk_endpoints should not be __init since it is called when
accessory is enabled

Change-Id: If827a4531f0f6c15af938345163923186368e2a5
Signed-off-by: Benoit Goby <benoit@android.com>
8 years agousb: otg: otg-wakelock: Fix build for 3.4
Benoit Goby [Thu, 10 May 2012 23:41:40 +0000 (16:41 -0700)]
usb: otg: otg-wakelock: Fix build for 3.4

Change-Id: I97e21e9e6645bf18522675039e512f85fe836794
Signed-off-by: Benoit Goby <benoit@android.com>
8 years agousb: gadget: adb: Only enable the gadget when adbd is ready
Benoit Goby [Tue, 20 Mar 2012 01:56:52 +0000 (18:56 -0700)]
usb: gadget: adb: Only enable the gadget when adbd is ready

When adb is enabled, only connect the gadget when adbd is ready. If adbd
dies or is restarted (e.g. "adb root"), the gadget is disconnected when
the adb device is close, and it is re-connected once adb re-open the
device.

- Add callbacks to adb, similar to FunctionFs callbacks, to notify the
  gadget when the daemon is ready or closed.
- Refcount calls to android_enable/android_disable to enable the gadget
  only once all the function daemons are ready.
- Add enable/disble to android_usb_function to notify the function when
  it is added/removed from the list of enabled functions.

Change-Id: Id54ff85aec9cf8715c94b4f9bd6137a79ad58bfc
Signed-off-by: Benoit Goby <benoit@android.com>
8 years agousb: gadget: adb: do not set error flag when dequeuing req
Colin Cross [Fri, 9 Mar 2012 01:57:51 +0000 (17:57 -0800)]
usb: gadget: adb: do not set error flag when dequeuing req

When an ep_out req is dequeued because of userspace freezing,
don't set the error flag.

Change-Id: I680f1a1059b8ac2244aaa069e7d42dc44abf98e9
Signed-off-by: Colin Cross <ccross@android.com>
8 years agousb: gadget: adb: allow freezing in adb_read
Colin Cross [Mon, 5 Mar 2012 21:29:45 +0000 (13:29 -0800)]
usb: gadget: adb: allow freezing in adb_read

wait_event_interruptible in adb_read might return -ERESTARTSYS if
userspace is frozen during adb_read or another signal is delivered
to adb.  If so, don't set dev->error to avoid resetting the adb
connection.

Change-Id: I5a7baa013a9a3a3b5305de7e6a0d18546a560018
Signed-off-by: Colin Cross <ccross@android.com>
8 years agousb: gadget: accessory: Add Android Accessory function
Benoit Goby [Mon, 19 Dec 2011 22:39:37 +0000 (14:39 -0800)]
usb: gadget: accessory: Add Android Accessory function

USB accessory mode allows users to connect USB host hardware
specifically designed for Android-powered devices. The accessories
must adhere to the Android accessory protocol outlined in the
http://accessories.android.com documentation. This allows
Android devices that cannot act as a USB host to still interact with
USB hardware. When an Android device is in USB accessory mode, the
attached Android USB accessory acts as the host, provides power
to the USB bus, and enumerates connected devices.

Change-Id: I67964b50d278f3c0471d47efbb7b0973a3502681
Signed-off-by: Mike Lockwood <lockwood@android.com>
8 years agousb: gadget: adb: Add ADB function
Benoit Goby [Mon, 19 Dec 2011 22:38:41 +0000 (14:38 -0800)]
usb: gadget: adb: Add ADB function

Android Debug Bridge (adb) is a command line tool that lets
users communicate with a Android-powered device. It is used
mainly to debug applications and tranfer files. f_adb implements
the transport layer between the ADB Server (on the host) and the
ADBD daemon (on the device).

Change-Id: Ib11672fa3439dcb3a6588774b132b5a85e03e8ba
Signed-off-by: Mike Lockwood <lockwood@android.com>
8 years agousb: gadget: mtp: Add MTP/PTP function
Benoit Goby [Mon, 19 Dec 2011 22:37:50 +0000 (14:37 -0800)]
usb: gadget: mtp: Add MTP/PTP function

USB gadget function driver used by the Android framework to
implement the MTP and PTP protocols. It creates a character device
that provides an interface for fast transfer of files and
supports transferring files greater than 4GB.

Change-Id: I2d8f2c37029fb37d8deb791d04eb7346f94f5adb
Signed-off-by: Mike Lockwood <lockwood@android.com>
8 years agousb: otg: otg-wakelock: fix build for 3.3
Colin Cross [Wed, 1 Feb 2012 22:23:15 +0000 (14:23 -0800)]
usb: otg: otg-wakelock: fix build for 3.3

Add missing module.h include

Change-Id: Ib0538ca569c9e0713ceefcd1f91c6bc089d2f2ba
Signed-off-by: Colin Cross <ccross@android.com>
8 years agousb: otg: Temporarily grab wakelock on charger and disconnect events
Todd Poynor [Tue, 27 Sep 2011 03:35:30 +0000 (20:35 -0700)]
usb: otg: Temporarily grab wakelock on charger and disconnect events

Change-Id: If995d4af4adcb08e8369009483f2956ad9627267
Signed-off-by: Todd Poynor <toddpoynor@google.com>
8 years agoUSB: OTG: Take wakelock when VBUS present
Todd Poynor [Sat, 2 Jul 2011 00:19:56 +0000 (17:19 -0700)]
USB: OTG: Take wakelock when VBUS present

Enabled by default, can disable with:
   echo N > /sys/module/otg_wakelock/parameters/enabled

Change-Id: I34974624c52ae23490852b44c270d2f326cf6116
Signed-off-by: Todd Poynor <toddpoynor@google.com>
8 years agowlan: Add get_wake_irq functionality
Dmitry Shmidt [Mon, 12 Jan 2015 21:42:05 +0000 (13:42 -0800)]
wlan: Add get_wake_irq functionality

Change-Id: Ic41f06c509b2e625dc9ec4131903db6920c5fd4e
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
8 years agoAdd flags parameter to get_country_code template
Dmitry Shmidt [Fri, 22 Aug 2014 21:40:18 +0000 (14:40 -0700)]
Add flags parameter to get_country_code template

Change-Id: Ic3f173db144a301ea104f544fc8ec723241c1d59
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
8 years agonet: wireless: Add get_country_code functionality to platform
Dmitry Shmidt [Tue, 15 Feb 2011 00:58:48 +0000 (16:58 -0800)]
net: wireless: Add get_country_code functionality to platform

Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
8 years agonetwork: wireless: Add get_mac_addr functionality to platform
Dmitry Shmidt [Thu, 3 Jun 2010 17:55:33 +0000 (10:55 -0700)]
network: wireless: Add get_mac_addr functionality to platform

Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
8 years agowlan: Create generic wlan platform data header
Dmitry Shmidt [Thu, 18 Mar 2010 23:04:18 +0000 (16:04 -0700)]
wlan: Create generic wlan platform data header

Change-Id: I233559218cc40acb28b57315ea25c08a9c866725
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
8 years agonet: wireless: Decrease scan entry expiration to avoid stall results
Dmitry Shmidt [Tue, 24 Jun 2014 16:36:50 +0000 (09:36 -0700)]
net: wireless: Decrease scan entry expiration to avoid stall results

Change-Id: I0e23ce45d78d7c17633670973f49943a5ed6032d
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
8 years agobridge: Have tx_bytes count headers like rx_bytes.
Ashish Sharma [Sat, 8 Oct 2011 00:54:16 +0000 (17:54 -0700)]
bridge: Have tx_bytes count headers like rx_bytes.

Since rx_bytes accounting does not include Ethernet Headers in
br_input.c, excluding ETH_HLEN on the transmit path for consistent
measurement of packet length on both the Tx and Rx chains.

The clean way would be for Rx to include the eth header, but the
skb len has already been adjusted by the time the br code sees the skb.
This is only a temporary workaround until we can completely ignore or
cleanly fix the skb->len handling.

Change-Id: I910de95a4686b2119da7f1f326e2154ef31f9972
Signed-off-by: Ashish Sharma <ashishsharma@google.com>
8 years agorfkill: Introduce CONFIG_RFKILL_PM and use instead of CONFIG_PM to power down
Nick Pelly [Fri, 5 Dec 2008 01:37:05 +0000 (17:37 -0800)]
rfkill: Introduce CONFIG_RFKILL_PM and use instead of CONFIG_PM to power down

Some platforms do not want to power down rfkill devices on suspend.

Change-Id: I62a11630521c636d54a4a02ab9037a43435925f5
Signed-off-by: Nick Pelly <npelly@google.com>
8 years agotcp: Fix IPV6 module build errors
Tushar Behera [Wed, 26 Mar 2014 09:57:05 +0000 (15:27 +0530)]
tcp: Fix IPV6 module build errors

If CONFIG_IPV6=m is selected, we are getting following build errors.

net/built-in.o: In function `tcp_is_local6':
net/ipv4/tcp.c:3261: undefined reference to `rt6_lookup'

Making the code conditional upon only CONFIG_IPV6=y fixes this issue.

Also export tcp_nuke_addr to build IPv6 modules. Otherwise
we run into following build error:

  CC [M]  lib/zlib_deflate/deftree.o
  CC [M]  lib/zlib_deflate/deflate_syms.o
  LD [M]  lib/zlib_deflate/zlib_deflate.o
  Building modules, stage 2.
  MODPOST 46 modules
ERROR: "tcp_nuke_addr" [net/ipv6/ipv6.ko] undefined!
make[2]: *** [__modpost] Error 1

Signed-off-by: Tushar Behera <tushar.behera@linaro.org>
CC: John Stultz <john.stultz@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
8 years agonet: ipv6: fix virtual tunneling build
Amit Pundir [Wed, 15 Apr 2015 14:59:09 +0000 (20:29 +0530)]
net: ipv6: fix virtual tunneling build

IPv6 PMTUD has been updated to support UID-based routing.

Pass INVALID_UID as the socket UID to ip6_update_pmtu(),
otherwise we run into following build error:
----------------
  CC      net/ipv6/ip6_vti.o
net/ipv6/ip6_vti.c: In function ‘vti6_err’:
net/ipv6/ip6_vti.c:559:3: error: too few arguments to function ‘ip6_update_pmtu’
In file included from include/net/ip_tunnels.h:19:0,
                 from net/ipv6/ip6_vti.c:44:
include/net/ip6_route.h:110:6: note: declared here
make[2]: *** [net/ipv6/ip6_vti.o] Error 1
----------------

Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
8 years agoDon't kill IPv4 sockets when killing IPv6 sockets was requested.
Lorenzo Colitti [Wed, 28 Oct 2015 06:56:59 +0000 (15:56 +0900)]
Don't kill IPv4 sockets when killing IPv6 sockets was requested.

c7c3ec4903d32c60423ee013d96e94602f66042c cherry-picked the
tcp_nuke_addr ioctl, but omitted a check that ensures that a
socket is an IPv6 socket. This makes it so that if we issue a
SIOCKILLADDR on ::, it kills IPv4 sockets as well.

This is because every IPv4 socket has an IPv6 source address
(sk_v6_rcv_saddr) of ::. Thus, when we iterate over an IPv4
socket, and compare the source address of the socket to the
source address in the ioctl, it matches the :: that was passed
in, and we kill the socket.

Change-Id: I736431a898e6ec91536536d352936a210aa10100

8 years agotcp: fix tcp_default_init_rwnd() for 4.1
Dmitry Shmidt [Wed, 28 Oct 2015 01:09:40 +0000 (18:09 -0700)]
tcp: fix tcp_default_init_rwnd() for 4.1

Change-Id: If3ecf5f59acf379ffcc468f28434830a92b0383d
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
8 years agonet: support marking accepting TCP sockets
Lorenzo Colitti [Wed, 26 Mar 2014 04:03:12 +0000 (13:03 +0900)]
net: support marking accepting TCP sockets

When using mark-based routing, sockets returned from accept()
may need to be marked differently depending on the incoming
connection request.

This is the case, for example, if different socket marks identify
different networks: a listening socket may want to accept
connections from all networks, but each connection should be
marked with the network that the request came in on, so that
subsequent packets are sent on the correct network.

This patch adds a sysctl to mark TCP sockets based on the fwmark
of the incoming SYN packet. If enabled, and an unmarked socket
receives a SYN, then the SYN packet's fwmark is written to the
connection's inet_request_sock, and later written back to the
accepted socket when the connection is established.  If the
socket already has a nonzero mark, then the behaviour is the same
as it is today, i.e., the listening socket's fwmark is used.

Black-box tested using user-mode linux:

- IPv4/IPv6 SYN+ACK, FIN, etc. packets are routed based on the
  mark of the incoming SYN packet.
- The socket returned by accept() is marked with the mark of the
  incoming SYN packet.
- Tested with syncookies=1 and syncookies=2.

Change-Id: I26bc1eceefd2c588d73b921865ab70e4645ade57
Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
8 years agotcp: add a sysctl to config the tcp_default_init_rwnd
JP Abgrall [Sat, 8 Feb 2014 02:40:10 +0000 (18:40 -0800)]
tcp: add a sysctl to config the tcp_default_init_rwnd

The default initial rwnd is hardcoded to 10.

Now we allow it to be controlled via
  /proc/sys/net/ipv4/tcp_default_init_rwnd
which limits the values from 3 to 100

This is somewhat needed because ipv6 routes are
autoconfigured by the kernel.

See "An Argument for Increasing TCP's Initial Congestion Window"
in https://developers.google.com/speed/articles/tcp_initcwnd_paper.pdf

Change-Id: I386b2a9d62de0ebe05c1ebe1b4bd91b314af5c54
Signed-off-by: JP Abgrall <jpa@google.com>
Conflicts:
net/ipv4/sysctl_net_ipv4.c
net/ipv4/tcp_input.c

8 years agonet: activity_stats: Stop using obsolete create_proc_read_entry api
Arve Hjønnevåg [Tue, 14 May 2013 03:39:30 +0000 (20:39 -0700)]
net: activity_stats: Stop using obsolete create_proc_read_entry api

Convert to use seq_read

Signed-off-by: Arve Hjønnevåg <arve@android.com>
8 years agonet: activity_stats: Add statistics for network transmission activity
Mike Chan [Fri, 28 May 2010 21:32:19 +0000 (14:32 -0700)]
net: activity_stats: Add statistics for network transmission activity

When enabled, tracks the frequency of network transmissions
(inbound and outbound) and buckets them accordingly.
Buckets are determined by time between network activity.

Each bucket represents the number of network transmisions that were
N sec or longer apart. Where N is defined as 1 << bucket index.

This network pattern tracking is particularly useful for wireless
networks (ie: 3G) where batching network activity closely together
is more power efficient than far apart.

New file: /proc/net/stat/activity

output:

Min Bucket(sec) Count
              1 7
              2 0
              4 1
              8 0
             16 0
             32 2
             64 1
            128 0

Change-Id: I4c4cd8627b872a55f326b1715c51bc3bdd6e8d92
Signed-off-by: Mike Chan <mike@android.com>
8 years agoxt_qtaguid: fix a race condition in if_tag_stat_update
liping.zhang [Mon, 11 Jan 2016 05:31:01 +0000 (13:31 +0800)]
xt_qtaguid: fix a race condition in if_tag_stat_update

Miss a lock protection in if_tag_stat_update while doing get_iface_entry. So if
one CPU is doing iface_stat_create while another CPU is doing if_tag_stat_update,
race will happened.

Change-Id: Ib8d98e542f4e385685499f5b7bb7354f08654a75
Signed-off-by: Liping Zhang <liping.zhang@spreadtrum.com>
8 years agonetfilter: xt_qtaguid/socket: build fixes for 4.4
Amit Pundir [Fri, 20 Nov 2015 09:15:40 +0000 (14:45 +0530)]
netfilter: xt_qtaguid/socket: build fixes for 4.4

Update xt_socket_lookup_slow_v* usage in aosp patches, to
align with changes from mainline commit 686c9b50809d
"netfilter: x_tables: Use par->net instead of computing
from the passed net devices".

Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
8 years agonetfilter: xt_qtaguid: xt_socket: build fixes
Amit Pundir [Mon, 6 Jul 2015 18:58:49 +0000 (00:28 +0530)]
netfilter: xt_qtaguid: xt_socket: build fixes

Add missing header <linux/miscdevice.h> and use
xt_socket_lookup_slow_v* instead of xt_socket_get*_sk
in xt_qtaguid.c.

Fix xt_socket_lookup_slow_v* functions in xt_socket.c
and declare them in xt_socket.h

Change-Id: I55819b2d4ffa82a2be20995c87d28fb5cc77b5ba
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
8 years agonet: xt_qtaguid/xt_socket: fix refcount underflow and crash
Dmitry Torokhov [Thu, 3 Sep 2015 21:48:52 +0000 (14:48 -0700)]
net: xt_qtaguid/xt_socket: fix refcount underflow and crash

xt_socket_get[4|6]_sk() do not always increment sock refcount, which
causes confusion in xt_qtaguid module which is not aware of this fact
and drops the reference whether it should have or not. Fix it by
changing xt_socket_get[4|6]_sk() to always increment recount of returned
sock.

This should fix the following crash:

[  111.319523] BUG: failure at
/mnt/host/source/src/third_party/kernel/v3.18/net/ipv4/inet_timewait_sock.c:90/__inet_twsk_kill()!
[  111.331192] Kernel panic - not syncing: BUG!
[  111.335468] CPU: 0 PID: 0 Comm: swapper/0 Tainted: G     U  W
3.18.0-06867-g268df91 #1
[  111.343810] Hardware name: Google Tegra210 Smaug Rev 1+ (DT)
[  111.349463] Call trace:
[  111.351917] [<ffffffc000207288>] dump_backtrace+0x0/0x10c
[  111.357314] [<ffffffc0002073a4>] show_stack+0x10/0x1c
[  111.362367] [<ffffffc000a82d1c>] dump_stack+0x74/0x94
[  111.367414] [<ffffffc000a81824>] panic+0xec/0x238
[  111.372116] [<ffffffc000981648>] __inet_twsk_kill+0xd0/0xf8
[  111.377684] [<ffffffc0009817b0>] inet_twdr_do_twkill_work+0x64/0xd0
[  111.383946] [<ffffffc000981a5c>] inet_twdr_hangman+0x2c/0xa4
[  111.389602] [<ffffffc000271cf0>] call_timer_fn+0xac/0x160
[  111.394995] [<ffffffc00027250c>] run_timer_softirq+0x23c/0x274
[  111.400824] [<ffffffc000220a68>] __do_softirq+0x1a4/0x330
[  111.406218] [<ffffffc000220e94>] irq_exit+0x70/0xd0
[  111.411093] [<ffffffc000264e00>] __handle_domain_irq+0x84/0xa8
[  111.416922] [<ffffffc0002003ec>] gic_handle_irq+0x4c/0x80

b/22476945

Originally reviewed at:
https://chromium-review.googlesource.com/#/c/297414/

Change-Id: I51fa94a9d92a84a0bd3b58466d711e46a6892a79
Signed-off-by: Dmitry Torokhov <dtor@google.com>
[jstultz: Cherry-picked and added missing local var definition]
Signed-off-by: John Stultz <john.stultz@linaro.org>
8 years agoxt_qtaguid: use sock_gen_put() instead of xt_socket_put_sk()
Amit Pundir [Wed, 28 Jan 2015 19:46:23 +0000 (01:16 +0530)]
xt_qtaguid: use sock_gen_put() instead of xt_socket_put_sk()

Removing obsolete xt_socket_put_sk() and using sock_gen_put() instead.
xt_socket_put_sk() was reintroduced for xt_qtaguid in one of the patches,
but it turned out sock_gen_put() supersedes xt_socket_put_sk(). So we
don't need xt_socket_put_sk() any more.

This patch is based on commit 1a8bf6eeef9f (netfilter: xt_socket: use sock_gen_put())

Change-Id: I976d5f7f7eded0f3cc91b596acfeb35e4c2057e5
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
(cherry picked from commit 551780fc28cb7480dbc4f585ef80ca02c2922ec1)
Signed-off-by: John Stultz <john.stultz@linaro.org>
8 years agoxt_qtaguid: Use sk_callback_lock read locks before reading sk->sk_socket
Mohamad Ayyash [Wed, 14 Jan 2015 03:20:44 +0000 (19:20 -0800)]
xt_qtaguid: Use sk_callback_lock read locks before reading sk->sk_socket

It prevents a kernel panic when accessing sk->sk_socket fields due to NULLing sk->sk_socket when sock_orphan is called through
sk_common_release.

Change-Id: I4aa46b4e2d8600e4d4ef8dcdd363aa4e6e5f8433
Signed-off-by: Mohamad Ayyash <mkayyash@google.com>
(cherry picked from commit cdea0ebcb8bcfe57688f6cb692b49e550ebd9796)
Signed-off-by: John Stultz <john.stultz@linaro.org>
8 years agoxt_qtaguid: fix broken uid/gid range check
Amit Pundir [Tue, 20 Jan 2015 10:43:08 +0000 (16:13 +0530)]
xt_qtaguid: fix broken uid/gid range check

The existing test to check if current uid/gid is within
valid range is broken due to missing parenthesis.

Change-Id: I889ebbd0e2ea6a9426cb1509a2975e7107666407
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: John Stultz <john.stultz@linaro.org>
8 years agonetfilter: Build fixups - kuid/kguid changes & xt_socket_get/put_sk
John Stultz [Fri, 28 Mar 2014 23:23:48 +0000 (16:23 -0700)]
netfilter: Build fixups - kuid/kguid changes & xt_socket_get/put_sk

Fix up build kuid/kguid build issues in netfilter code.

Also re-add the xt_socket_get/put_sk interfaces needed by xt_qtaguid.

Change-Id: I7027fb840e109785bddffe8ea717b8d018b26d82
Signed-off-by: John Stultz <john.stultz@linaro.org>
8 years agonet: core: Handle 'sk' being NULL in UID-based routing
Sreeram Ramachandran [Tue, 8 Jul 2014 18:57:14 +0000 (11:57 -0700)]
net: core: Handle 'sk' being NULL in UID-based routing

It has Amit Pundir <amit.pundir@linaro.org> fix:
net: core: fix UID-based routing build

Bug: 15413527
Change-Id: Iab1fae9da6053b284591628ef1de878761b137b1
Signed-off-by: Sreeram Ramachandran <sreeram@google.com>
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
8 years agonet: core: Support UID-based routing.
Lorenzo Colitti [Mon, 31 Mar 2014 07:23:51 +0000 (16:23 +0900)]
net: core: Support UID-based routing.

This contains the following commits:

1. cc2f522 net: core: Add a UID range to fib rules.
2. d7ed2bd net: core: Use the socket UID in routing lookups.
3. 2f9306a net: core: Add a RTA_UID attribute to routes.
    This is so that userspace can do per-UID route lookups.
4. 8e46efb net: ipv6: Use the UID in IPv6 PMTUD
    IPv4 PMTUD already does this because ipv4_sk_update_pmtu
    uses __build_flow_key, which includes the UID.

Bug: 15413527
Change-Id: Iae3d4ca3979d252b6cec989bdc1a6875f811f03a
Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
8 years agonet: ipv6: fix build failure if IPV6_ROUTE_INFO config is enabled
Amit Pundir [Tue, 24 Mar 2015 22:59:14 +0000 (04:29 +0530)]
net: ipv6: fix build failure if IPV6_ROUTE_INFO config is enabled

Pass correct arguments to rt6_get_route_info() function, otherwise
we run into following Kernel build failure:
----------
  CC      net/ipv6/route.o
net/ipv6/route.c: In function ‘rt6_route_rcv’:
net/ipv6/route.c:746:27: error: ‘net’ undeclared (first use in this function)
net/ipv6/route.c:746:27: note: each undeclared identifier is reported only once for each function it appears in
make[2]: *** [net/ipv6/route.o] Error 1
make[1]: *** [net/ipv6] Error 2
make: *** [net] Error 2
----------

Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
8 years agonet: ipv6: autoconf routes into per-device tables
Lorenzo Colitti [Wed, 26 Mar 2014 10:35:41 +0000 (19:35 +0900)]
net: ipv6: autoconf routes into per-device tables

Currently, IPv6 router discovery always puts routes into
RT6_TABLE_MAIN. This causes problems for connection managers
that want to support multiple simultaneous network connections
and want control over which one is used by default (e.g., wifi
and wired).

To work around this connection managers typically take the routes
they prefer and copy them to static routes with low metrics in
the main table. This puts the burden on the connection manager
to watch netlink to see if the routes have changed, delete the
routes when their lifetime expires, etc.

Instead, this patch adds a per-interface sysctl to have the
kernel put autoconf routes into different tables. This allows
each interface to have its own autoconf table, and choosing the
default interface (or using different interfaces at the same
time for different types of traffic) can be done using
appropriate ip rules.

The sysctl behaves as follows:

- = 0: default. Put routes into RT6_TABLE_MAIN as before.
- > 0: manual. Put routes into the specified table.
- < 0: automatic. Add the absolute value of the sysctl to the
       device's ifindex, and use that table.

The automatic mode is most useful in conjunction with
net.ipv6.conf.default.accept_ra_rt_table. A connection manager
or distribution could set it to, say, -100 on boot, and
thereafter just use IP rules.

Change-Id: I82d16e3737d9cdfa6489e649e247894d0d60cbb1
Signed-off-by: Lorenzo Colitti <lorenzo@google.com>
8 years agonf: IDLETIMER: Fix broken uid field in the msg
Amit Pundir [Mon, 11 May 2015 09:09:59 +0000 (14:39 +0530)]
nf: IDLETIMER: Fix broken uid field in the msg

Create uid from kuid to fix the broken uid field
in the message notifications introduced in
Change-Id: I18fc73eada512e370d7ab24fc9f890845037b729,
Otherwise we run into following build error:
---------------
  CC      net/netfilter/xt_IDLETIMER.o
net/netfilter/xt_IDLETIMER.c: In function ‘reset_timer’:
net/netfilter/xt_IDLETIMER.c:360:16: error: incompatible types when assigning to type ‘uid_t’ from type ‘kuid_t’
make[2]: *** [net/netfilter/xt_IDLETIMER.o] Error 1
---------------

Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
(cherry picked from commit 706060ba3e1dee9ec3c4a4a1480d663b6cd71cad)

Change-Id: Ifd66df45a58d1a5a60c3816c373ee3008292eee8

8 years agonf: IDLETIMER: Adds the uid field in the msg
Ruchi Kandoi [Thu, 23 Apr 2015 19:09:09 +0000 (12:09 -0700)]
nf: IDLETIMER: Adds the uid field in the msg

Message notifications contains an additional uid field. This field
represents the uid that was responsible for waking the radio. And hence
it is present only in notifications stating that the radio is now
active.

Change-Id: I18fc73eada512e370d7ab24fc9f890845037b729
Signed-off-by: Ruchi Kandoi <kandoiruchi@google.com>
Bug: 20264396

8 years agonetfilter: fix seq_printf type mismatch warning
Sherman Yin [Thu, 12 Jun 2014 21:35:38 +0000 (14:35 -0700)]
netfilter: fix seq_printf type mismatch warning

The return type of atomic64_read() varies depending on arch.  The
arm64 version is being changed from long long to long in the mainline
for v3.16, causing a seq_printf type mismatch (%llu) in
guid_ctrl_proc_show().

This commit fixes the type mismatch by casting atomic64_read() to u64.

Change-Id: Iae0a6bd4314f5686a9f4fecbe6203e94ec0870de
Signed-off-by: Sherman Yin <shermanyin@gmail.com>
8 years agonf: Remove compilation error caused by e8430cbed3ef15fdb1ac26cfd020e010aa5f1c35
Ruchi Kandoi [Thu, 24 Apr 2014 21:07:53 +0000 (14:07 -0700)]
nf: Remove compilation error caused by e8430cbed3ef15fdb1ac26cfd020e010aa5f1c35

Signed-off-by: Ruchi Kandoi <kandoiruchi@google.com>
8 years agonf: IDLETIMER: time-stamp and suspend/resume handling.
Ruchi Kandoi [Tue, 25 Mar 2014 23:43:28 +0000 (16:43 -0700)]
nf: IDLETIMER: time-stamp and suspend/resume handling.

Message notifications contains an additional timestamp field in nano seconds.
The expiry time for the timers are modified during suspend/resume.
If timer was supposed to expire while the system is suspended then a
notification is sent when it resumes with the timestamp of the scheduled expiry.

Removes the race condition for multiple work scheduled.

Bug: 13247811

Change-Id: I752c5b00225fe7085482819f975cc0eb5af89bff
Signed-off-by: Ruchi Kandoi <kandoiruchi@google.com>
8 years agoxt_qtaguid: Fix boot panic
Jon Medhurst (Tixy) [Tue, 15 Apr 2014 04:20:49 +0000 (21:20 -0700)]
xt_qtaguid: Fix boot panic

We need the change below because of mainline commit 351638e7de (net: pass
info struct via netdevice notifier). Otherwise we panic.

Change-Id: I7daf7513a733933fdcbaeebea7f8191f8b6a0432
Signed-off-by: John Stultz <john.stultz@linaro.org>
8 years agonet: kuid/kguid build fixes
John Stultz [Fri, 28 Mar 2014 19:19:27 +0000 (12:19 -0700)]
net: kuid/kguid build fixes

Small build fixes for xt_quota2 and ipv4 changes

Change-Id: Ib098768040c8875887b2081c3165a6c83b37e180
Signed-off-by: John Stultz <john.stultz@linaro.org>
8 years agonetfilter: ipv6: fix crash caused by ipv6_find_hdr()
JP Abgrall [Thu, 29 Sep 2011 22:36:49 +0000 (15:36 -0700)]
netfilter: ipv6: fix crash caused by ipv6_find_hdr()

When calling:
    ipv6_find_hdr(skb, &thoff, -1, NULL)
on a fragmented packet, thoff would be left with a random
value causing callers to read random memory offsets with:
    skb_header_pointer(skb, thoff, ...)

Now we force ipv6_find_hdr() to return a failure in this case.
Calling:
  ipv6_find_hdr(skb, &thoff, -1, &fragoff)
will set fragoff as expected, and not return a failure.

Change-Id: Ib474e8a4267dd2b300feca325811330329684a88
Signed-off-by: JP Abgrall <jpa@google.com>
8 years agonetfilter: xt_qtaguid: 64-bit warning fixes
Greg Hackmann [Mon, 24 Feb 2014 17:39:46 +0000 (09:39 -0800)]
netfilter: xt_qtaguid: 64-bit warning fixes

Change-Id: I2adc517c0c51050ed601992fa0ea4de8f1449414
Signed-off-by: Greg Hackmann <ghackmann@google.com>
8 years agonetfilter: xt_qtaguid: fix memory leak in seq_file handlers
Greg Hackmann [Thu, 5 Dec 2013 01:39:27 +0000 (17:39 -0800)]
netfilter: xt_qtaguid: fix memory leak in seq_file handlers

Change-Id: I15b21230d52479d008a00d9e2191dda020f00925
Signed-off-by: Greg Hackmann <ghackmann@google.com>
8 years agonetfilter: xt_qtaguid: fix bad tcp_time_wait sock handling
JP Abgrall [Thu, 21 Feb 2013 00:38:34 +0000 (16:38 -0800)]
netfilter: xt_qtaguid: fix bad tcp_time_wait sock handling

Since (41063e9 ipv4: Early TCP socket demux), skb's can have an sk which
is not a struct sock but the smaller struct inet_timewait_sock without an
sk->sk_socket. Now we bypass sk_state == TCP_TIME_WAIT

Signed-off-by: JP Abgrall <jpa@google.com>
8 years agonetfilter: xt_qtaguid: 3.10 fixes
Arve Hjønnevåg [Tue, 14 May 2013 03:45:02 +0000 (20:45 -0700)]
netfilter: xt_qtaguid: 3.10 fixes

Stop using obsolete procfs api.

Signed-off-by: Arve Hjønnevåg <arve@android.com>
8 years agonetfilter: xt_quota2: 3.10 fixes.
Arve Hjønnevåg [Tue, 14 May 2013 03:42:46 +0000 (20:42 -0700)]
netfilter: xt_quota2: 3.10 fixes.

- Stop using obsolete create_proc_entry api.
- Use proc_set_user instead of directly accessing the private structure.

Signed-off-by: Arve Hjønnevåg <arve@android.com>
8 years agonetfilter: qtaguid: rate limit some of the printks
JP Abgrall [Mon, 8 Apr 2013 22:09:26 +0000 (15:09 -0700)]
netfilter: qtaguid: rate limit some of the printks

Some of the printks are in the packet handling path.
We now ratelimit the very unlikely errors to avoid
kmsg spamming.

Signed-off-by: JP Abgrall <jpa@google.com>
8 years agonetfilter: xt_qtaguid: Allow tracking loopback
JP Abgrall [Thu, 7 Feb 2013 01:40:07 +0000 (17:40 -0800)]
netfilter: xt_qtaguid: Allow tracking loopback

In the past it would always ignore interfaces with loopback addresses.
Now we just treat them like any other.
This also helps with writing tests that check for the presence
of the qtaguid module.

Signed-off-by: JP Abgrall <jpa@google.com>
8 years agonetfilter: xt_qtaguid: extend iface stat to report protocols
JP Abgrall [Tue, 29 Jan 2013 00:50:44 +0000 (16:50 -0800)]
netfilter: xt_qtaguid: extend iface stat to report protocols

In the past the iface_stat_fmt would only show global bytes/packets
for the skb-based numbers.
For stall detection in userspace, distinguishing tcp vs other protocols
makes it easier.
Now we report
  ifname total_skb_rx_bytes total_skb_rx_packets total_skb_tx_bytes
  total_skb_tx_packets {rx,tx}_{tcp,udp,ohter}_{bytes,packets}

Bug: 6818637
Signed-off-by: JP Abgrall <jpa@google.com>
8 years agonetfilter: xt_qtaguid: remove AID_* dependency for access control
JP Abgrall [Sat, 5 Jan 2013 02:18:36 +0000 (18:18 -0800)]
netfilter: xt_qtaguid: remove AID_* dependency for access control

qtaguid limits what can be done with /ctrl and /stats based on group
membership.
This changes removes AID_NET_BW_STATS and AID_NET_BW_ACCT, and picks
up the groups from the gid of the matching proc entry files.

Signed-off-by: JP Abgrall <jpa@google.com>
Change-Id: I42e477adde78a12ed5eb58fbc0b277cdaadb6f94

8 years agonetfilter: qtaguid: Don't BUG_ON if create_if_tag_stat fails
Pontus Fuchs [Mon, 19 Nov 2012 19:44:51 +0000 (11:44 -0800)]
netfilter: qtaguid: Don't BUG_ON if create_if_tag_stat fails

If create_if_tag_stat fails to allocate memory (GFP_ATOMIC) the
following will happen:

qtaguid: iface_stat: tag stat alloc failed
...
kernel BUG at xt_qtaguid.c:1482!

Signed-off-by: Pontus Fuchs <pontus.fuchs@gmail.com>
8 years agonetfilter: xt_qtaguid: fix error exit that would keep a spinlock.
JP Abgrall [Wed, 10 Oct 2012 03:38:21 +0000 (20:38 -0700)]
netfilter: xt_qtaguid: fix error exit that would keep a spinlock.

qtudev_open() could return with a uid_tag_data_tree_lock held
when an kzalloc(..., GFP_ATOMIC) would fail.
Very unlikely to get triggered AND survive the mayhem of running out of mem.

Signed-off-by: JP Abgrall <jpa@google.com>
8 years agonetfilter: xt_qtaguid: report only uid tags to non-privileged processes
JP Abgrall [Tue, 28 Aug 2012 23:53:32 +0000 (16:53 -0700)]
netfilter: xt_qtaguid: report only uid tags to non-privileged processes

In the past, a process could only see its own stats (uid-based summary,
and details).
Now we allow any process to see other UIDs uid-based stats, but still
hide the detailed stats.

Change-Id: I7666961ed244ac1d9359c339b048799e5db9facc
Signed-off-by: JP Abgrall <jpa@google.com>
8 years agonetfilter: xt_qtaguid: start tracking iface rx/tx at low level
JP Abgrall [Fri, 27 Apr 2012 19:57:39 +0000 (12:57 -0700)]
netfilter: xt_qtaguid: start tracking iface rx/tx at low level

qtaguid tracks the device stats by monitoring when it goes up and down,
then it gets the dev_stats().
But devs don't correctly report stats (either they don't count headers
symmetrically between rx/tx, or they count internal control messages).

Now qtaguid counts the rx/tx bytes/packets during raw:prerouting and
mangle:postrouting (nat is not available in ipv6).

The results are in
  /proc/net/xt_qtaguid/iface_stat_fmt
which outputs a format line (bash expansion):
  ifname  total_skb_{rx,tx}_{bytes,packets}

Added event counters for pre/post handling.
Added extra ctrl_*() pid/uid debugging.

Change-Id: Id84345d544ad1dd5f63e3842cab229e71d339297
Signed-off-by: JP Abgrall <jpa@google.com>
8 years agonetfilter: xt_IDLETIMER: Add new netlink msg type
JP Abgrall [Fri, 27 Apr 2012 06:28:35 +0000 (23:28 -0700)]
netfilter: xt_IDLETIMER: Add new netlink msg type

Send notifications when the label becomes active after an idle period.
Send netlink message notifications in addition to sysfs notifications.
Using a uevent with
  subsystem=xt_idletimer
  INTERFACE=...
  STATE={active,inactive}

This is backport from common android-3.0
commit: beb914e987cbbd368988d2b94a6661cb907c4d5a
with uevent support instead of a new netlink message type.

Change-Id: I31677ef00c94b5f82c8457e5bf9e5e584c23c523
Signed-off-by: Ashish Sharma <ashishsharma@google.com>
Signed-off-by: JP Abgrall <jpa@google.com>
8 years agonetfilter: xt_qtaguid: fix ipv6 protocol lookup
JP Abgrall [Tue, 17 Apr 2012 23:00:07 +0000 (16:00 -0700)]
netfilter: xt_qtaguid: fix ipv6 protocol lookup

When updating the stats for a given uid it would incorrectly assume
IPV4 and pick up the wrong protocol when IPV6.

Change-Id: Iea4a635012b4123bf7aa93809011b7b2040bb3d5
Signed-off-by: JP Abgrall <jpa@google.com>
8 years agonetfilter: qtaguid: initialize a local var to keep compiler happy.
JP Abgrall [Sat, 14 Apr 2012 02:22:35 +0000 (19:22 -0700)]
netfilter: qtaguid: initialize a local var to keep compiler happy.

There was a case that might have seemed like new_tag_stat was not
initialized and actually used.
Added comment explaining why it was impossible, and a BUG()
in case the logic gets changed.

Change-Id: I1eddd1b6f754c08a3bf89f7e9427e5dce1dfb081
Signed-off-by: JP Abgrall <jpa@google.com>
8 years agonetfilter: fixup the quota2, and enable.
JP Abgrall [Tue, 12 Jul 2011 19:02:59 +0000 (12:02 -0700)]
netfilter: fixup the quota2, and enable.

The xt_quota2 came from
  http://sourceforge.net/projects/xtables-addons/develop

It needed tweaking for it to compile within the kernel tree.
Fixed kmalloc() and create_proc_entry() invocations within
 a non-interruptible context.
Removed useless copying of current quota back to the iptable's
struct matchinfo:
  - those are per CPU: they will change randomly based on which
    cpu gets to update the value.
  - they prevent matching a rule: e.g.
      -A chain -m quota2 --name q1 --quota 123
     can't be followed by
      -D chain -m quota2 --name q1 --quota 123
    as the 123 will be compared to the struct matchinfo's quota member.
Use the NETLINK NETLINK_NFLOG family to log a single message
when the quota limit is reached.
It uses the same packet type as ipt_ULOG, but
 - never copies skb data,
 - uses 112 as the event number (ULOG's +1)
It doesn't log if the module param "event_num" is 0.

Change-Id: I021d3b743db3b22158cc49acb5c94d905b501492
Signed-off-by: JP Abgrall <jpa@google.com>
8 years agonetfilter: adding the original quota2 from xtables-addons
JP Abgrall [Tue, 21 Jun 2011 18:14:49 +0000 (11:14 -0700)]
netfilter: adding the original quota2 from xtables-addons

The original xt_quota in the kernel is plain broken:
  - counts quota at a per CPU level
    (was written back when ubiquitous SMP was just a dream)
  - provides no way to count across IPV4/IPV6.

This patch is the original unaltered code from:
  http://sourceforge.net/projects/xtables-addons

  at commit e84391ce665cef046967f796dd91026851d6bbf3

Change-Id: I19d49858840effee9ecf6cff03c23b45a97efdeb
Signed-off-by: JP Abgrall <jpa@google.com>
8 years agonetfilter: add xt_qtaguid matching module
JP Abgrall [Mon, 20 Jun 2011 19:41:46 +0000 (12:41 -0700)]
netfilter: add xt_qtaguid matching module

This module allows tracking stats at the socket level for given UIDs.
It replaces xt_owner.
If the --uid-owner is not specified, it will just count stats based on
who the skb belongs to. This will even happen on incoming skbs as it
looks into the skb via xt_socket magic to see who owns it.
If an skb is lost, it will be assigned to uid=0.

To control what sockets of what UIDs are tagged by what, one uses:
  echo t $sock_fd $accounting_tag $the_billed_uid \
     > /proc/net/xt_qtaguid/ctrl
 So whenever an skb belongs to a sock_fd, it will be accounted against
   $the_billed_uid
  and matching stats will show up under the uid with the given
   $accounting_tag.

Because the number of allocations for the stats structs is not that big:
  ~500 apps * 32 per app
we'll just do it atomic. This avoids walking lists many times, and
the fancy worker thread handling. Slabs will grow when needed later.

It use netdevice and inetaddr notifications instead of hooks in the core dev
code to track when a device comes and goes. This removes the need for
exposed iface_stat.h.

Put procfs dirs in /proc/net/xt_qtaguid/
  ctrl
  stats
  iface_stat/<iface>/...
The uid stats are obtainable in ./stats.

Change-Id: I01af4fd91c8de651668d3decb76d9bdc1e343919
Signed-off-by: JP Abgrall <jpa@google.com>
8 years agonet: PPPoPNS and PPPoLAC build fixes for 4.4
Amit Pundir [Tue, 8 Dec 2015 07:17:01 +0000 (12:47 +0530)]
net: PPPoPNS and PPPoLAC build fixes for 4.4

Fix couple of sk_alloc() calls to align with mainline commit
11aa9c28b420 "net: Pass kern from net_proto_family.create to sk_alloc".

Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
8 years agoHack: net: PPPoPNS and PPPoLAC build fixes for 4.1
Amit Pundir [Tue, 8 Dec 2015 12:58:40 +0000 (18:28 +0530)]
Hack: net: PPPoPNS and PPPoLAC build fixes for 4.1

Upstream commit c0371da6047a "put iov_iter into msghdr",
added iov_iter and removed direct access to scatter/gather
array elements in msghdr. It broke PPPoLAC and PPPoPNS.

Lets restore the direct access to scatter/gather array in
msghdr for the time being. Otherwise we run into following
build failure:
----------
drivers/net/ppp/pppolac.c: In function ‘pppolac_xmit_core’:
drivers/net/ppp/pppolac.c:210:4: error: unknown field ‘msg_iov’ specified in initializer
    .msg_iov = (struct iovec *)&iov,
    ^
drivers/net/ppp/pppolac.c:211:4: error: unknown field ‘msg_iovlen’ specified in initializer
    .msg_iovlen = 1,
    ^
make[3]: *** [drivers/net/ppp/pppolac.o] Error 1
----------

Change-Id: I2a1245a156da6d93b49f5cfd10506381b0eff005
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>
8 years agonet: pppopns: pppolac: fix sendmsg function calls
Amit Pundir [Tue, 8 Dec 2015 12:56:39 +0000 (18:26 +0530)]
net: pppopns: pppolac: fix sendmsg function calls

Fix couple of sendmsg() calls to align with changes
from upstream commit 1b784140474e "net: Remove iocb
argument from sendmsg and recvmsg".

Change-Id: I85bc46130af8decfa37abe65aec33053ed39f1b1
Signed-off-by: Amit Pundir <amit.pundir@linaro.org>
Signed-off-by: Dmitry Shmidt <dimitrysh@google.com>