mirror of
https://github.com/AetherDroid/android_kernel_samsung_on5xelte.git
synced 2025-09-08 01:08:03 -04:00
Fixed MTP to work with TWRP
This commit is contained in:
commit
f6dfaef42e
50820 changed files with 20846062 additions and 0 deletions
19
net/netlink/Kconfig
Normal file
19
net/netlink/Kconfig
Normal file
|
@ -0,0 +1,19 @@
|
|||
#
|
||||
# Netlink Sockets
|
||||
#
|
||||
|
||||
config NETLINK_MMAP
|
||||
bool "NETLINK: mmaped IO"
|
||||
---help---
|
||||
This option enables support for memory mapped netlink IO. This
|
||||
reduces overhead by avoiding copying data between kernel- and
|
||||
userspace.
|
||||
|
||||
If unsure, say N.
|
||||
|
||||
config NETLINK_DIAG
|
||||
tristate "NETLINK: socket monitoring interface"
|
||||
default n
|
||||
---help---
|
||||
Support for NETLINK socket monitoring interface used by the ss tool.
|
||||
If unsure, say Y.
|
8
net/netlink/Makefile
Normal file
8
net/netlink/Makefile
Normal file
|
@ -0,0 +1,8 @@
|
|||
#
|
||||
# Makefile for the netlink driver.
|
||||
#
|
||||
|
||||
obj-y := af_netlink.o genetlink.o
|
||||
|
||||
obj-$(CONFIG_NETLINK_DIAG) += netlink_diag.o
|
||||
netlink_diag-y := diag.o
|
3150
net/netlink/af_netlink.c
Normal file
3150
net/netlink/af_netlink.c
Normal file
File diff suppressed because it is too large
Load diff
78
net/netlink/af_netlink.h
Normal file
78
net/netlink/af_netlink.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
#ifndef _AF_NETLINK_H
|
||||
#define _AF_NETLINK_H
|
||||
|
||||
#include <linux/rhashtable.h>
|
||||
#include <net/sock.h>
|
||||
|
||||
#define NLGRPSZ(x) (ALIGN(x, sizeof(unsigned long) * 8) / 8)
|
||||
#define NLGRPLONGS(x) (NLGRPSZ(x)/sizeof(unsigned long))
|
||||
|
||||
struct netlink_ring {
|
||||
void **pg_vec;
|
||||
unsigned int head;
|
||||
unsigned int frames_per_block;
|
||||
unsigned int frame_size;
|
||||
unsigned int frame_max;
|
||||
|
||||
unsigned int pg_vec_order;
|
||||
unsigned int pg_vec_pages;
|
||||
unsigned int pg_vec_len;
|
||||
|
||||
atomic_t pending;
|
||||
};
|
||||
|
||||
struct netlink_sock {
|
||||
/* struct sock has to be the first member of netlink_sock */
|
||||
struct sock sk;
|
||||
u32 portid;
|
||||
u32 dst_portid;
|
||||
u32 dst_group;
|
||||
u32 flags;
|
||||
u32 subscriptions;
|
||||
u32 ngroups;
|
||||
unsigned long *groups;
|
||||
unsigned long state;
|
||||
size_t max_recvmsg_len;
|
||||
wait_queue_head_t wait;
|
||||
bool cb_running;
|
||||
struct netlink_callback cb;
|
||||
struct mutex *cb_mutex;
|
||||
struct mutex cb_def_mutex;
|
||||
void (*netlink_rcv)(struct sk_buff *skb);
|
||||
int (*netlink_bind)(int group);
|
||||
void (*netlink_unbind)(int group);
|
||||
struct module *module;
|
||||
#ifdef CONFIG_NETLINK_MMAP
|
||||
struct mutex pg_vec_lock;
|
||||
struct netlink_ring rx_ring;
|
||||
struct netlink_ring tx_ring;
|
||||
atomic_t mapped;
|
||||
#endif /* CONFIG_NETLINK_MMAP */
|
||||
|
||||
struct rhash_head node;
|
||||
};
|
||||
|
||||
static inline struct netlink_sock *nlk_sk(struct sock *sk)
|
||||
{
|
||||
return container_of(sk, struct netlink_sock, sk);
|
||||
}
|
||||
|
||||
struct netlink_table {
|
||||
struct rhashtable hash;
|
||||
struct hlist_head mc_list;
|
||||
struct listeners __rcu *listeners;
|
||||
unsigned int flags;
|
||||
unsigned int groups;
|
||||
struct mutex *cb_mutex;
|
||||
struct module *module;
|
||||
int (*bind)(int group);
|
||||
void (*unbind)(int group);
|
||||
bool (*compare)(struct net *net, struct sock *sock);
|
||||
int registered;
|
||||
};
|
||||
|
||||
extern struct netlink_table *nl_table;
|
||||
extern rwlock_t nl_table_lock;
|
||||
extern struct mutex nl_sk_hash_lock;
|
||||
|
||||
#endif
|
235
net/netlink/diag.c
Normal file
235
net/netlink/diag.c
Normal file
|
@ -0,0 +1,235 @@
|
|||
#include <linux/module.h>
|
||||
|
||||
#include <net/sock.h>
|
||||
#include <linux/netlink.h>
|
||||
#include <linux/sock_diag.h>
|
||||
#include <linux/netlink_diag.h>
|
||||
#include <linux/rhashtable.h>
|
||||
|
||||
#include "af_netlink.h"
|
||||
|
||||
#ifdef CONFIG_NETLINK_MMAP
|
||||
static int sk_diag_put_ring(struct netlink_ring *ring, int nl_type,
|
||||
struct sk_buff *nlskb)
|
||||
{
|
||||
struct netlink_diag_ring ndr;
|
||||
|
||||
ndr.ndr_block_size = ring->pg_vec_pages << PAGE_SHIFT;
|
||||
ndr.ndr_block_nr = ring->pg_vec_len;
|
||||
ndr.ndr_frame_size = ring->frame_size;
|
||||
ndr.ndr_frame_nr = ring->frame_max + 1;
|
||||
|
||||
return nla_put(nlskb, nl_type, sizeof(ndr), &ndr);
|
||||
}
|
||||
|
||||
static int sk_diag_put_rings_cfg(struct sock *sk, struct sk_buff *nlskb)
|
||||
{
|
||||
struct netlink_sock *nlk = nlk_sk(sk);
|
||||
int ret;
|
||||
|
||||
mutex_lock(&nlk->pg_vec_lock);
|
||||
ret = sk_diag_put_ring(&nlk->rx_ring, NETLINK_DIAG_RX_RING, nlskb);
|
||||
if (!ret)
|
||||
ret = sk_diag_put_ring(&nlk->tx_ring, NETLINK_DIAG_TX_RING,
|
||||
nlskb);
|
||||
mutex_unlock(&nlk->pg_vec_lock);
|
||||
|
||||
return ret;
|
||||
}
|
||||
#else
|
||||
static int sk_diag_put_rings_cfg(struct sock *sk, struct sk_buff *nlskb)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
static int sk_diag_dump_groups(struct sock *sk, struct sk_buff *nlskb)
|
||||
{
|
||||
struct netlink_sock *nlk = nlk_sk(sk);
|
||||
|
||||
if (nlk->groups == NULL)
|
||||
return 0;
|
||||
|
||||
return nla_put(nlskb, NETLINK_DIAG_GROUPS, NLGRPSZ(nlk->ngroups),
|
||||
nlk->groups);
|
||||
}
|
||||
|
||||
static int sk_diag_fill(struct sock *sk, struct sk_buff *skb,
|
||||
struct netlink_diag_req *req,
|
||||
u32 portid, u32 seq, u32 flags, int sk_ino)
|
||||
{
|
||||
struct nlmsghdr *nlh;
|
||||
struct netlink_diag_msg *rep;
|
||||
struct netlink_sock *nlk = nlk_sk(sk);
|
||||
|
||||
nlh = nlmsg_put(skb, portid, seq, SOCK_DIAG_BY_FAMILY, sizeof(*rep),
|
||||
flags);
|
||||
if (!nlh)
|
||||
return -EMSGSIZE;
|
||||
|
||||
rep = nlmsg_data(nlh);
|
||||
rep->ndiag_family = AF_NETLINK;
|
||||
rep->ndiag_type = sk->sk_type;
|
||||
rep->ndiag_protocol = sk->sk_protocol;
|
||||
rep->ndiag_state = sk->sk_state;
|
||||
|
||||
rep->ndiag_ino = sk_ino;
|
||||
rep->ndiag_portid = nlk->portid;
|
||||
rep->ndiag_dst_portid = nlk->dst_portid;
|
||||
rep->ndiag_dst_group = nlk->dst_group;
|
||||
sock_diag_save_cookie(sk, rep->ndiag_cookie);
|
||||
|
||||
if ((req->ndiag_show & NDIAG_SHOW_GROUPS) &&
|
||||
sk_diag_dump_groups(sk, skb))
|
||||
goto out_nlmsg_trim;
|
||||
|
||||
if ((req->ndiag_show & NDIAG_SHOW_MEMINFO) &&
|
||||
sock_diag_put_meminfo(sk, skb, NETLINK_DIAG_MEMINFO))
|
||||
goto out_nlmsg_trim;
|
||||
|
||||
if ((req->ndiag_show & NDIAG_SHOW_RING_CFG) &&
|
||||
sk_diag_put_rings_cfg(sk, skb))
|
||||
goto out_nlmsg_trim;
|
||||
|
||||
return nlmsg_end(skb, nlh);
|
||||
|
||||
out_nlmsg_trim:
|
||||
nlmsg_cancel(skb, nlh);
|
||||
return -EMSGSIZE;
|
||||
}
|
||||
|
||||
static int __netlink_diag_dump(struct sk_buff *skb, struct netlink_callback *cb,
|
||||
int protocol, int s_num)
|
||||
{
|
||||
struct netlink_table *tbl = &nl_table[protocol];
|
||||
struct rhashtable *ht = &tbl->hash;
|
||||
const struct bucket_table *htbl = rht_dereference(ht->tbl, ht);
|
||||
struct net *net = sock_net(skb->sk);
|
||||
struct netlink_diag_req *req;
|
||||
struct netlink_sock *nlsk;
|
||||
struct sock *sk;
|
||||
int ret = 0, num = 0, i;
|
||||
|
||||
req = nlmsg_data(cb->nlh);
|
||||
|
||||
for (i = 0; i < htbl->size; i++) {
|
||||
rht_for_each_entry(nlsk, htbl->buckets[i], ht, node) {
|
||||
sk = (struct sock *)nlsk;
|
||||
|
||||
if (!net_eq(sock_net(sk), net))
|
||||
continue;
|
||||
if (num < s_num) {
|
||||
num++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sk_diag_fill(sk, skb, req,
|
||||
NETLINK_CB(cb->skb).portid,
|
||||
cb->nlh->nlmsg_seq,
|
||||
NLM_F_MULTI,
|
||||
sock_i_ino(sk)) < 0) {
|
||||
ret = 1;
|
||||
goto done;
|
||||
}
|
||||
|
||||
num++;
|
||||
}
|
||||
}
|
||||
|
||||
sk_for_each_bound(sk, &tbl->mc_list) {
|
||||
if (sk_hashed(sk))
|
||||
continue;
|
||||
if (!net_eq(sock_net(sk), net))
|
||||
continue;
|
||||
if (num < s_num) {
|
||||
num++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (sk_diag_fill(sk, skb, req,
|
||||
NETLINK_CB(cb->skb).portid,
|
||||
cb->nlh->nlmsg_seq,
|
||||
NLM_F_MULTI,
|
||||
sock_i_ino(sk)) < 0) {
|
||||
ret = 1;
|
||||
goto done;
|
||||
}
|
||||
num++;
|
||||
}
|
||||
done:
|
||||
cb->args[0] = num;
|
||||
cb->args[1] = protocol;
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int netlink_diag_dump(struct sk_buff *skb, struct netlink_callback *cb)
|
||||
{
|
||||
struct netlink_diag_req *req;
|
||||
int s_num = cb->args[0];
|
||||
|
||||
req = nlmsg_data(cb->nlh);
|
||||
|
||||
mutex_lock(&nl_sk_hash_lock);
|
||||
read_lock(&nl_table_lock);
|
||||
|
||||
if (req->sdiag_protocol == NDIAG_PROTO_ALL) {
|
||||
int i;
|
||||
|
||||
for (i = cb->args[1]; i < MAX_LINKS; i++) {
|
||||
if (__netlink_diag_dump(skb, cb, i, s_num))
|
||||
break;
|
||||
s_num = 0;
|
||||
}
|
||||
} else {
|
||||
if (req->sdiag_protocol >= MAX_LINKS) {
|
||||
read_unlock(&nl_table_lock);
|
||||
mutex_unlock(&nl_sk_hash_lock);
|
||||
return -ENOENT;
|
||||
}
|
||||
|
||||
__netlink_diag_dump(skb, cb, req->sdiag_protocol, s_num);
|
||||
}
|
||||
|
||||
read_unlock(&nl_table_lock);
|
||||
mutex_unlock(&nl_sk_hash_lock);
|
||||
|
||||
return skb->len;
|
||||
}
|
||||
|
||||
static int netlink_diag_handler_dump(struct sk_buff *skb, struct nlmsghdr *h)
|
||||
{
|
||||
int hdrlen = sizeof(struct netlink_diag_req);
|
||||
struct net *net = sock_net(skb->sk);
|
||||
|
||||
if (nlmsg_len(h) < hdrlen)
|
||||
return -EINVAL;
|
||||
|
||||
if (h->nlmsg_flags & NLM_F_DUMP) {
|
||||
struct netlink_dump_control c = {
|
||||
.dump = netlink_diag_dump,
|
||||
};
|
||||
return netlink_dump_start(net->diag_nlsk, skb, h, &c);
|
||||
} else
|
||||
return -EOPNOTSUPP;
|
||||
}
|
||||
|
||||
static const struct sock_diag_handler netlink_diag_handler = {
|
||||
.family = AF_NETLINK,
|
||||
.dump = netlink_diag_handler_dump,
|
||||
};
|
||||
|
||||
static int __init netlink_diag_init(void)
|
||||
{
|
||||
return sock_diag_register(&netlink_diag_handler);
|
||||
}
|
||||
|
||||
static void __exit netlink_diag_exit(void)
|
||||
{
|
||||
sock_diag_unregister(&netlink_diag_handler);
|
||||
}
|
||||
|
||||
module_init(netlink_diag_init);
|
||||
module_exit(netlink_diag_exit);
|
||||
MODULE_LICENSE("GPL");
|
||||
MODULE_ALIAS_NET_PF_PROTO_TYPE(PF_NETLINK, NETLINK_SOCK_DIAG, 16 /* AF_NETLINK */);
|
1094
net/netlink/genetlink.c
Normal file
1094
net/netlink/genetlink.c
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue