cregit-Linux how code gets into the kernel

Release 4.11 drivers/staging/gdm724x/gdm_lte.c

/*
 * Copyright (c) 2012 GCT Semiconductor, Inc. All rights reserved.
 *
 * This software is licensed under the terms of the GNU General Public
 * License version 2, as published by the Free Software Foundation, and
 * may be copied, distributed, and modified under those terms.
 *
 * 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.
 */


#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt

#include <linux/etherdevice.h>
#include <linux/ip.h>
#include <linux/ipv6.h>
#include <linux/udp.h>
#include <linux/in.h>
#include <linux/if_arp.h>
#include <linux/if_ether.h>
#include <linux/if_vlan.h>
#include <linux/in6.h>
#include <linux/tcp.h>
#include <linux/icmp.h>
#include <linux/icmpv6.h>
#include <linux/uaccess.h>
#include <net/ndisc.h>

#include "gdm_lte.h"
#include "netlink_k.h"
#include "hci.h"
#include "hci_packet.h"
#include "gdm_endian.h"

/*
 * Netlink protocol number
 */

#define NETLINK_LTE 30

/*
 * Default MTU Size
 */

#define DEFAULT_MTU_SIZE 1500


#define IP_VERSION_4	4

#define IP_VERSION_6	6

static struct {
	
int ref_cnt;
	
struct sock *sock;
} 
lte_event;


static struct device_type wwan_type = {
	.name   = "wwan",
};


static int gdm_lte_open(struct net_device *dev) { netif_start_queue(dev); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang19100.00%1100.00%
Total19100.00%1100.00%


static int gdm_lte_close(struct net_device *dev) { netif_stop_queue(dev); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang19100.00%1100.00%
Total19100.00%1100.00%


static int gdm_lte_set_config(struct net_device *dev, struct ifmap *map) { if (dev->flags & IFF_UP) return -EBUSY; return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang31100.00%1100.00%
Total31100.00%1100.00%


static void tx_complete(void *arg) { struct nic *nic = arg; if (netif_queue_stopped(nic->netdev)) netif_wake_queue(nic->netdev); }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang33100.00%1100.00%
Total33100.00%1100.00%


static int gdm_lte_rx(struct sk_buff *skb, struct nic *nic, int nic_type) { int ret; ret = netif_rx_ni(skb); if (ret == NET_RX_DROP) { nic->stats.rx_dropped++; } else { nic->stats.rx_packets++; nic->stats.rx_bytes += skb->len + ETH_HLEN; } return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang69100.00%1100.00%
Total69100.00%1100.00%


static int gdm_lte_emulate_arp(struct sk_buff *skb_in, u32 nic_type) { struct nic *nic = netdev_priv(skb_in->dev); struct sk_buff *skb_out; struct ethhdr eth; struct vlan_ethhdr vlan_eth; struct arphdr *arp_in; struct arphdr *arp_out; struct arpdata { u8 ar_sha[ETH_ALEN]; u8 ar_sip[4]; u8 ar_tha[ETH_ALEN]; u8 ar_tip[4]; }; struct arpdata *arp_data_in; struct arpdata *arp_data_out; u8 arp_temp[60]; void *mac_header_data; u32 mac_header_len; /* Format the mac header so that it can be put to skb */ if (ntohs(((struct ethhdr *)skb_in->data)->h_proto) == ETH_P_8021Q) { memcpy(&vlan_eth, skb_in->data, sizeof(struct vlan_ethhdr)); mac_header_data = &vlan_eth; mac_header_len = VLAN_ETH_HLEN; } else { memcpy(&eth, skb_in->data, sizeof(struct ethhdr)); mac_header_data = &eth; mac_header_len = ETH_HLEN; } /* Get the pointer of the original request */ arp_in = (struct arphdr *)(skb_in->data + mac_header_len); arp_data_in = (struct arpdata *)(skb_in->data + mac_header_len + sizeof(struct arphdr)); /* Get the pointer of the outgoing response */ arp_out = (struct arphdr *)arp_temp; arp_data_out = (struct arpdata *)(arp_temp + sizeof(struct arphdr)); /* Copy the arp header */ memcpy(arp_out, arp_in, sizeof(struct arphdr)); arp_out->ar_op = htons(ARPOP_REPLY); /* Copy the arp payload: based on 2 bytes of mac and fill the IP */ arp_data_out->ar_sha[0] = arp_data_in->ar_sha[0]; arp_data_out->ar_sha[1] = arp_data_in->ar_sha[1]; memcpy(&arp_data_out->ar_sha[2], &arp_data_in->ar_tip[0], 4); memcpy(&arp_data_out->ar_sip[0], &arp_data_in->ar_tip[0], 4); memcpy(&arp_data_out->ar_tha[0], &arp_data_in->ar_sha[0], 6); memcpy(&arp_data_out->ar_tip[0], &arp_data_in->ar_sip[0], 4); /* Fill the destination mac with source mac of the received packet */ memcpy(mac_header_data, mac_header_data + ETH_ALEN, ETH_ALEN); /* Fill the source mac with nic's source mac */ memcpy(mac_header_data + ETH_ALEN, nic->src_mac_addr, ETH_ALEN); /* Alloc skb and reserve align */ skb_out = dev_alloc_skb(skb_in->len); if (!skb_out) return -ENOMEM; skb_reserve(skb_out, NET_IP_ALIGN); memcpy(skb_put(skb_out, mac_header_len), mac_header_data, mac_header_len); memcpy(skb_put(skb_out, sizeof(struct arphdr)), arp_out, sizeof(struct arphdr)); memcpy(skb_put(skb_out, sizeof(struct arpdata)), arp_data_out, sizeof(struct arpdata)); skb_out->protocol = ((struct ethhdr *)mac_header_data)->h_proto; skb_out->dev = skb_in->dev; skb_reset_mac_header(skb_out); skb_pull(skb_out, ETH_HLEN); gdm_lte_rx(skb_out, nic, nic_type); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang53399.81%150.00%
Valentina Manea10.19%150.00%
Total534100.00%2100.00%


static int icmp6_checksum(struct ipv6hdr *ipv6, u16 *ptr, int len) { unsigned short *w = ptr; int sum = 0; int i; union { struct { u8 ph_src[16]; u8 ph_dst[16]; u32 ph_len; u8 ph_zero[3]; u8 ph_nxt; } ph __packed; u16 pa[20]; } pseudo_header; memset(&pseudo_header, 0, sizeof(pseudo_header)); memcpy(&pseudo_header.ph.ph_src, &ipv6->saddr.in6_u.u6_addr8, 16); memcpy(&pseudo_header.ph.ph_dst, &ipv6->daddr.in6_u.u6_addr8, 16); pseudo_header.ph.ph_len = be16_to_cpu(ipv6->payload_len); pseudo_header.ph.ph_nxt = ipv6->nexthdr; w = (u16 *)&pseudo_header; for (i = 0; i < ARRAY_SIZE(pseudo_header.pa); i++) sum += pseudo_header.pa[i]; w = ptr; while (len > 1) { sum += *w++; len -= 2; } sum = (sum >> 16) + (sum & 0xFFFF); sum += (sum >> 16); sum = ~sum & 0xffff; return sum; }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang23797.93%125.00%
Javier Rodriguez31.24%125.00%
Valentina Manea10.41%125.00%
Gulsah Kose10.41%125.00%
Total242100.00%4100.00%


static int gdm_lte_emulate_ndp(struct sk_buff *skb_in, u32 nic_type) { struct nic *nic = netdev_priv(skb_in->dev); struct sk_buff *skb_out; struct ethhdr eth; struct vlan_ethhdr vlan_eth; struct neighbour_advertisement { u8 target_address[16]; u8 type; u8 length; u8 link_layer_address[6]; }; struct neighbour_advertisement na; struct neighbour_solicitation { u8 target_address[16]; }; struct neighbour_solicitation *ns; struct ipv6hdr *ipv6_in; struct ipv6hdr ipv6_out; struct icmp6hdr *icmp6_in; struct icmp6hdr icmp6_out; void *mac_header_data; u32 mac_header_len; /* Format the mac header so that it can be put to skb */ if (ntohs(((struct ethhdr *)skb_in->data)->h_proto) == ETH_P_8021Q) { memcpy(&vlan_eth, skb_in->data, sizeof(struct vlan_ethhdr)); if (ntohs(vlan_eth.h_vlan_encapsulated_proto) != ETH_P_IPV6) return -1; mac_header_data = &vlan_eth; mac_header_len = VLAN_ETH_HLEN; } else { memcpy(&eth, skb_in->data, sizeof(struct ethhdr)); if (ntohs(eth.h_proto) != ETH_P_IPV6) return -1; mac_header_data = &eth; mac_header_len = ETH_HLEN; } /* Check if this is IPv6 ICMP packet */ ipv6_in = (struct ipv6hdr *)(skb_in->data + mac_header_len); if (ipv6_in->version != 6 || ipv6_in->nexthdr != IPPROTO_ICMPV6) return -1; /* Check if this is NDP packet */ icmp6_in = (struct icmp6hdr *)(skb_in->data + mac_header_len + sizeof(struct ipv6hdr)); if (icmp6_in->icmp6_type == NDISC_ROUTER_SOLICITATION) { /* Check RS */ return -1; } else if (icmp6_in->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) { /* Check NS */ u8 icmp_na[sizeof(struct icmp6hdr) + sizeof(struct neighbour_advertisement)]; u8 zero_addr8[16] = {0,}; if (memcmp(ipv6_in->saddr.in6_u.u6_addr8, zero_addr8, 16) == 0) /* Duplicate Address Detection: Source IP is all zero */ return 0; icmp6_out.icmp6_type = NDISC_NEIGHBOUR_ADVERTISEMENT; icmp6_out.icmp6_code = 0; icmp6_out.icmp6_cksum = 0; /* R=0, S=1, O=1 */ icmp6_out.icmp6_dataun.un_data32[0] = htonl(0x60000000); ns = (struct neighbour_solicitation *) (skb_in->data + mac_header_len + sizeof(struct ipv6hdr) + sizeof(struct icmp6hdr)); memcpy(&na.target_address, ns->target_address, 16); na.type = 0x02; na.length = 1; na.link_layer_address[0] = 0x00; na.link_layer_address[1] = 0x0a; na.link_layer_address[2] = 0x3b; na.link_layer_address[3] = 0xaf; na.link_layer_address[4] = 0x63; na.link_layer_address[5] = 0xc7; memcpy(&ipv6_out, ipv6_in, sizeof(struct ipv6hdr)); memcpy(ipv6_out.saddr.in6_u.u6_addr8, &na.target_address, 16); memcpy(ipv6_out.daddr.in6_u.u6_addr8, ipv6_in->saddr.in6_u.u6_addr8, 16); ipv6_out.payload_len = htons(sizeof(struct icmp6hdr) + sizeof(struct neighbour_advertisement)); memcpy(icmp_na, &icmp6_out, sizeof(struct icmp6hdr)); memcpy(icmp_na + sizeof(struct icmp6hdr), &na, sizeof(struct neighbour_advertisement)); icmp6_out.icmp6_cksum = icmp6_checksum(&ipv6_out, (u16 *)icmp_na, sizeof(icmp_na)); } else { return -1; } /* Fill the destination mac with source mac of the received packet */ memcpy(mac_header_data, mac_header_data + ETH_ALEN, ETH_ALEN); /* Fill the source mac with nic's source mac */ memcpy(mac_header_data + ETH_ALEN, nic->src_mac_addr, ETH_ALEN); /* Alloc skb and reserve align */ skb_out = dev_alloc_skb(skb_in->len); if (!skb_out) return -ENOMEM; skb_reserve(skb_out, NET_IP_ALIGN); memcpy(skb_put(skb_out, mac_header_len), mac_header_data, mac_header_len); memcpy(skb_put(skb_out, sizeof(struct ipv6hdr)), &ipv6_out, sizeof(struct ipv6hdr)); memcpy(skb_put(skb_out, sizeof(struct icmp6hdr)), &icmp6_out, sizeof(struct icmp6hdr)); memcpy(skb_put(skb_out, sizeof(struct neighbour_advertisement)), &na, sizeof(struct neighbour_advertisement)); skb_out->protocol = ((struct ethhdr *)mac_header_data)->h_proto; skb_out->dev = skb_in->dev; skb_reset_mac_header(skb_out); skb_pull(skb_out, ETH_HLEN); gdm_lte_rx(skb_out, nic, nic_type); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang79999.75%133.33%
Valentina Manea10.12%133.33%
Ning Zhou10.12%133.33%
Total801100.00%3100.00%


static s32 gdm_lte_tx_nic_type(struct net_device *dev, struct sk_buff *skb) { struct nic *nic = netdev_priv(dev); struct ethhdr *eth; struct vlan_ethhdr *vlan_eth; struct iphdr *ip; struct ipv6hdr *ipv6; int mac_proto; void *network_data; u32 nic_type = 0; /* NIC TYPE is based on the nic_id of this net_device */ nic_type = 0x00000010 | nic->nic_id; /* Get ethernet protocol */ eth = (struct ethhdr *)skb->data; if (ntohs(eth->h_proto) == ETH_P_8021Q) { vlan_eth = (struct vlan_ethhdr *)skb->data; mac_proto = ntohs(vlan_eth->h_vlan_encapsulated_proto); network_data = skb->data + VLAN_ETH_HLEN; nic_type |= NIC_TYPE_F_VLAN; } else { mac_proto = ntohs(eth->h_proto); network_data = skb->data + ETH_HLEN; } /* Process packet for nic type */ switch (mac_proto) { case ETH_P_ARP: nic_type |= NIC_TYPE_ARP; break; case ETH_P_IP: nic_type |= NIC_TYPE_F_IPV4; ip = network_data; /* Check DHCPv4 */ if (ip->protocol == IPPROTO_UDP) { struct udphdr *udp = network_data + sizeof(struct iphdr); if (ntohs(udp->dest) == 67 || ntohs(udp->dest) == 68) nic_type |= NIC_TYPE_F_DHCP; } break; case ETH_P_IPV6: nic_type |= NIC_TYPE_F_IPV6; ipv6 = network_data; if (ipv6->nexthdr == IPPROTO_ICMPV6) /* Check NDP request */ { struct icmp6hdr *icmp6 = network_data + sizeof(struct ipv6hdr); if (icmp6->icmp6_type == NDISC_NEIGHBOUR_SOLICITATION) nic_type |= NIC_TYPE_ICMPV6; } else if (ipv6->nexthdr == IPPROTO_UDP) /* Check DHCPv6 */ { struct udphdr *udp = network_data + sizeof(struct ipv6hdr); if (ntohs(udp->dest) == 546 || ntohs(udp->dest) == 547) nic_type |= NIC_TYPE_F_DHCP; } break; default: break; } return nic_type; }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang321100.00%1100.00%
Total321100.00%1100.00%


static int gdm_lte_tx(struct sk_buff *skb, struct net_device *dev) { struct nic *nic = netdev_priv(dev); u32 nic_type; void *data_buf; int data_len; int idx; int ret = 0; nic_type = gdm_lte_tx_nic_type(dev, skb); if (nic_type == 0) { netdev_err(dev, "tx - invalid nic_type\n"); return -1; } if (nic_type & NIC_TYPE_ARP) { if (gdm_lte_emulate_arp(skb, nic_type) == 0) { dev_kfree_skb(skb); return 0; } } if (nic_type & NIC_TYPE_ICMPV6) { if (gdm_lte_emulate_ndp(skb, nic_type) == 0) { dev_kfree_skb(skb); return 0; } } /* * Need byte shift (that is, remove VLAN tag) if there is one * For the case of ARP, this breaks the offset as vlan_ethhdr+4 * is treated as ethhdr However, it shouldn't be a problem as * the response starts from arp_hdr and ethhdr is created by this * driver based on the NIC mac */ if (nic_type & NIC_TYPE_F_VLAN) { struct vlan_ethhdr *vlan_eth = (struct vlan_ethhdr *)skb->data; nic->vlan_id = ntohs(vlan_eth->h_vlan_TCI) & VLAN_VID_MASK; data_buf = skb->data + (VLAN_ETH_HLEN - ETH_HLEN); data_len = skb->len - (VLAN_ETH_HLEN - ETH_HLEN); } else { nic->vlan_id = 0; data_buf = skb->data; data_len = skb->len; } /* If it is a ICMPV6 packet, clear all the other bits : * for backward compatibility with the firmware */ if (nic_type & NIC_TYPE_ICMPV6) nic_type = NIC_TYPE_ICMPV6; /* If it is not a dhcp packet, clear all the flag bits : * original NIC, otherwise the special flag (IPVX | DHCP) */ if (!(nic_type & NIC_TYPE_F_DHCP)) nic_type &= NIC_TYPE_MASK; ret = sscanf(dev->name, "lte%d", &idx); if (ret != 1) { dev_kfree_skb(skb); return -EINVAL; } ret = nic->phy_dev->send_sdu_func(nic->phy_dev->priv_dev, data_buf, data_len, nic->pdn_table.dft_eps_id, 0, tx_complete, nic, idx, nic_type); if (ret == TX_NO_BUFFER || ret == TX_NO_SPC) { netif_stop_queue(dev); if (ret == TX_NO_BUFFER) ret = 0; else ret = -ENOSPC; } else if (ret == TX_NO_DEV) { ret = -ENODEV; } /* Updates tx stats */ if (ret) { nic->stats.tx_dropped++; } else { nic->stats.tx_packets++; nic->stats.tx_bytes += data_len; } dev_kfree_skb(skb); return 0; }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang34688.95%120.00%
Monam Agarwal194.88%120.00%
Rashika Kheria174.37%120.00%
Joe Perches41.03%120.00%
Gulsah Kose30.77%120.00%
Total389100.00%5100.00%


static struct net_device_stats *gdm_lte_stats(struct net_device *dev) { struct nic *nic = netdev_priv(dev); return &nic->stats; }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang29100.00%1100.00%
Total29100.00%1100.00%


static int gdm_lte_event_send(struct net_device *dev, char *buf, int len) { struct nic *nic = netdev_priv(dev); struct hci_packet *hci = (struct hci_packet *)buf; int idx; int ret; ret = sscanf(dev->name, "lte%d", &idx); if (ret != 1) return -EINVAL; return netlink_send(lte_event.sock, idx, 0, buf, gdm_dev16_to_cpu( nic->phy_dev->get_endian( nic->phy_dev->priv_dev), hci->len) + HCI_HEADER_SIZE); }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang8277.36%133.33%
Monam Agarwal1514.15%133.33%
Rashika Kheria98.49%133.33%
Total106100.00%3100.00%


static void gdm_lte_event_rcv(struct net_device *dev, u16 type, void *msg, int len) { struct nic *nic = netdev_priv(dev); nic->phy_dev->send_hci_func(nic->phy_dev->priv_dev, msg, len, NULL, NULL); }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang3975.00%150.00%
Rashika Kheria1325.00%150.00%
Total52100.00%2100.00%


int gdm_lte_event_init(void) { if (lte_event.ref_cnt == 0) lte_event.sock = netlink_init(NETLINK_LTE, gdm_lte_event_rcv); if (lte_event.sock) { lte_event.ref_cnt++; return 0; } pr_err("event init failed\n"); return -1; }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang4996.08%150.00%
Joe Perches23.92%150.00%
Total51100.00%2100.00%


void gdm_lte_event_exit(void) { if (lte_event.sock && --lte_event.ref_cnt == 0) { sock_release(lte_event.sock->sk_socket); lte_event.sock = NULL; } }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang3491.89%150.00%
Amitoj Kaur Chawla38.11%150.00%
Total37100.00%2100.00%


static int find_dev_index(u32 nic_type) { u8 index; index = (u8)(nic_type & 0x0000000f); if (index >= MAX_NIC_TYPE) return -EINVAL; return index; }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang3083.33%150.00%
Dan Carpenter616.67%150.00%
Total36100.00%2100.00%


static void gdm_lte_netif_rx(struct net_device *dev, char *buf, int len, int flagged_nic_type) { u32 nic_type; struct nic *nic; struct sk_buff *skb; struct ethhdr eth; struct vlan_ethhdr vlan_eth; void *mac_header_data; u32 mac_header_len; char ip_version = 0; nic_type = flagged_nic_type & NIC_TYPE_MASK; nic = netdev_priv(dev); if (flagged_nic_type & NIC_TYPE_F_DHCP) { /* Change the destination mac address * with the one requested the IP */ if (flagged_nic_type & NIC_TYPE_F_IPV4) { struct dhcp_packet { u8 op; /* BOOTREQUEST or BOOTREPLY */ u8 htype; /* hardware address type. * 1 = 10mb ethernet */ u8 hlen; /* hardware address length */ u8 hops; /* used by relay agents only */ u32 xid; /* unique id */ u16 secs; /* elapsed since client began * acquisition/renewal */ u16 flags; /* only one flag so far: */ #define BROADCAST_FLAG 0x8000 /* "I need broadcast replies" */ u32 ciaddr; /* client IP (if client is in * BOUND, RENEW or REBINDING state) */ u32 yiaddr; /* 'your' (client) IP address */ /* IP address of next server to use in * bootstrap, returned in DHCPOFFER, * DHCPACK by server */ u32 siaddr_nip; u32 gateway_nip; /* relay agent IP address */ u8 chaddr[16]; /* link-layer client hardware * address (MAC) */ u8 sname[64]; /* server host name (ASCIZ) */ u8 file[128]; /* boot file name (ASCIZ) */ u32 cookie; /* fixed first four option * bytes (99,130,83,99 dec) */ } __packed; void *addr = buf + sizeof(struct iphdr) + sizeof(struct udphdr) + offsetof(struct dhcp_packet, chaddr); ether_addr_copy(nic->dest_mac_addr, addr); } } if (nic->vlan_id > 0) { mac_header_data = (void *)&vlan_eth; mac_header_len = VLAN_ETH_HLEN; } else { mac_header_data = (void *)&eth; mac_header_len = ETH_HLEN; } /* Format the data so that it can be put to skb */ ether_addr_copy(mac_header_data, nic->dest_mac_addr); memcpy(mac_header_data + ETH_ALEN, nic->src_mac_addr, ETH_ALEN); vlan_eth.h_vlan_TCI = htons(nic->vlan_id); vlan_eth.h_vlan_proto = htons(ETH_P_8021Q); if (nic_type == NIC_TYPE_ARP) { /* Should be response: Only happens because * there was a request from the host */ eth.h_proto = htons(ETH_P_ARP); vlan_eth.h_vlan_encapsulated_proto = htons(ETH_P_ARP); } else { ip_version = buf[0] >> 4; if (ip_version == IP_VERSION_4) { eth.h_proto = htons(ETH_P_IP); vlan_eth.h_vlan_encapsulated_proto = htons(ETH_P_IP); } else if (ip_version == IP_VERSION_6) { eth.h_proto = htons(ETH_P_IPV6); vlan_eth.h_vlan_encapsulated_proto = htons(ETH_P_IPV6); } else { netdev_err(dev, "Unknown IP version %d\n", ip_version); return; } } /* Alloc skb and reserve align */ skb = dev_alloc_skb(len + mac_header_len + NET_IP_ALIGN); if (!skb) return; skb_reserve(skb, NET_IP_ALIGN); memcpy(skb_put(skb, mac_header_len), mac_header_data, mac_header_len); memcpy(skb_put(skb, len), buf, len); skb->protocol = ((struct ethhdr *)mac_header_data)->h_proto; skb->dev = dev; skb_reset_mac_header(skb); skb_pull(skb, ETH_HLEN); gdm_lte_rx(skb, nic, nic_type); }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang46797.09%125.00%
Gulsah Kose81.66%125.00%
Joe Perches40.83%125.00%
Dilek Uzulmez20.42%125.00%
Total481100.00%4100.00%


static void gdm_lte_multi_sdu_pkt(struct phy_dev *phy_dev, char *buf, int len) { struct net_device *dev; struct multi_sdu *multi_sdu = (struct multi_sdu *)buf; struct sdu *sdu = NULL; struct gdm_endian *endian = phy_dev->get_endian(phy_dev->priv_dev); u8 *data = (u8 *)multi_sdu->data; u16 i = 0; u16 num_packet; u16 hci_len; u16 cmd_evt; u32 nic_type; int index; hci_len = gdm_dev16_to_cpu(endian, multi_sdu->len); num_packet = gdm_dev16_to_cpu(endian, multi_sdu->num_packet); for (i = 0; i < num_packet; i++) { sdu = (struct sdu *)data; cmd_evt = gdm_dev16_to_cpu(endian, sdu->cmd_evt); hci_len = gdm_dev16_to_cpu(endian, sdu->len); nic_type = gdm_dev32_to_cpu(endian, sdu->nic_type); if (cmd_evt != LTE_RX_SDU) { pr_err("rx sdu wrong hci %04x\n", cmd_evt); return; } if (hci_len < 12) { pr_err("rx sdu invalid len %d\n", hci_len); return; } index = find_dev_index(nic_type); if (index < 0) { pr_err("rx sdu invalid nic_type :%x\n", nic_type); return; } dev = phy_dev->dev[index]; gdm_lte_netif_rx(dev, (char *)sdu->data, (int)(hci_len - 12), nic_type); data += ((hci_len + 3) & 0xfffc) + HCI_HEADER_SIZE; } }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang23587.36%125.00%
Emil Gedda197.06%125.00%
Dan Carpenter114.09%125.00%
Joe Perches41.49%125.00%
Total269100.00%4100.00%


static void gdm_lte_pdn_table(struct net_device *dev, char *buf, int len) { struct nic *nic = netdev_priv(dev); struct hci_pdn_table_ind *pdn_table = (struct hci_pdn_table_ind *)buf; if (pdn_table->activate) { nic->pdn_table.activate = pdn_table->activate; nic->pdn_table.dft_eps_id = gdm_dev32_to_cpu( nic->phy_dev->get_endian( nic->phy_dev->priv_dev), pdn_table->dft_eps_id); nic->pdn_table.nic_type = gdm_dev32_to_cpu( nic->phy_dev->get_endian( nic->phy_dev->priv_dev), pdn_table->nic_type); netdev_info(dev, "pdn activated, nic_type=0x%x\n", nic->pdn_table.nic_type); } else { memset(&nic->pdn_table, 0x00, sizeof(struct pdn_table)); netdev_info(dev, "pdn deactivated\n"); } }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang12583.89%133.33%
Rashika Kheria1812.08%133.33%
Joe Perches64.03%133.33%
Total149100.00%3100.00%


static int gdm_lte_receive_pkt(struct phy_dev *phy_dev, char *buf, int len) { struct hci_packet *hci = (struct hci_packet *)buf; struct hci_pdn_table_ind *pdn_table = (struct hci_pdn_table_ind *)buf; struct gdm_endian *endian = phy_dev->get_endian(phy_dev->priv_dev); struct sdu *sdu; struct net_device *dev; int ret = 0; u16 cmd_evt; u32 nic_type; int index; if (!len) return ret; cmd_evt = gdm_dev16_to_cpu(endian, hci->cmd_evt); dev = phy_dev->dev[0]; if (!dev) return 0; switch (cmd_evt) { case LTE_RX_SDU: sdu = (struct sdu *)hci->data; nic_type = gdm_dev32_to_cpu(endian, sdu->nic_type); index = find_dev_index(nic_type); if (index < 0) return index; dev = phy_dev->dev[index]; gdm_lte_netif_rx(dev, hci->data, len, nic_type); break; case LTE_RX_MULTI_SDU: gdm_lte_multi_sdu_pkt(phy_dev, buf, len); break; case LTE_LINK_ON_OFF_INDICATION: netdev_info(dev, "link %s\n", ((struct hci_connect_ind *)buf)->connect ? "on" : "off"); break; case LTE_PDN_TABLE_IND: pdn_table = (struct hci_pdn_table_ind *)buf; nic_type = gdm_dev32_to_cpu(endian, pdn_table->nic_type); index = find_dev_index(nic_type); if (index < 0) return index; dev = phy_dev->dev[index]; gdm_lte_pdn_table(dev, buf, len); /* Fall through */ default: ret = gdm_lte_event_send(dev, buf, len); break; } return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang25484.95%120.00%
Dan Carpenter196.35%120.00%
Emil Gedda175.69%120.00%
Joe Perches82.68%120.00%
Ioana Ciornei10.33%120.00%
Total299100.00%5100.00%


static int rx_complete(void *arg, void *data, int len, int context) { struct phy_dev *phy_dev = arg; return gdm_lte_receive_pkt(phy_dev, data, len); }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang37100.00%1100.00%
Total37100.00%1100.00%


void start_rx_proc(struct phy_dev *phy_dev) { int i; for (i = 0; i < MAX_RX_SUBMIT_COUNT; i++) phy_dev->rcv_func(phy_dev->priv_dev, rx_complete, phy_dev, USB_COMPLETE); }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang3687.80%150.00%
Rashika Kheria512.20%150.00%
Total41100.00%2100.00%

static const struct net_device_ops gdm_netdev_ops = { .ndo_open = gdm_lte_open, .ndo_stop = gdm_lte_close, .ndo_set_config = gdm_lte_set_config, .ndo_start_xmit = gdm_lte_tx, .ndo_get_stats = gdm_lte_stats, }; static u8 gdm_lte_macaddr[ETH_ALEN] = {0x00, 0x0a, 0x3b, 0x00, 0x00, 0x00};
static void form_mac_address(u8 *dev_addr, u8 *nic_src, u8 *nic_dest, u8 *mac_address, u8 index) { /* Form the dev_addr */ if (!mac_address) ether_addr_copy(dev_addr, gdm_lte_macaddr); else ether_addr_copy(dev_addr, mac_address); /* The last byte of the mac address * should be less than or equal to 0xFC */ dev_addr[ETH_ALEN - 1] += index; /* Create random nic src and copy the first * 3 bytes to be the same as dev_addr */ eth_random_addr(nic_src); memcpy(nic_src, dev_addr, 3); /* Copy the nic_dest from dev_addr*/ ether_addr_copy(nic_dest, dev_addr); }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang7392.41%125.00%
Dilek Uzulmez33.80%125.00%
Gulsah Kose22.53%125.00%
Bhumika Goyal11.27%125.00%
Total79100.00%4100.00%


static void validate_mac_address(u8 *mac_address) { /* if zero address or multicast bit set, restore the default value */ if (is_zero_ether_addr(mac_address) || (mac_address[0] & 0x01)) { pr_err("MAC invalid, restoring default\n"); memcpy(mac_address, gdm_lte_macaddr, 6); } }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang4195.35%150.00%
Joe Perches24.65%150.00%
Total43100.00%2100.00%


int register_lte_device(struct phy_dev *phy_dev, struct device *dev, u8 *mac_address) { struct nic *nic; struct net_device *net; char pdn_dev_name[16]; int ret = 0; u8 index; validate_mac_address(mac_address); for (index = 0; index < MAX_NIC_TYPE; index++) { /* Create device name lteXpdnX */ sprintf(pdn_dev_name, "lte%%dpdn%d", index); /* Allocate netdev */ net = alloc_netdev(sizeof(struct nic), pdn_dev_name, NET_NAME_UNKNOWN, ether_setup); if (!net) { pr_err("alloc_netdev failed\n"); ret = -ENOMEM; goto err; } net->netdev_ops = &gdm_netdev_ops; net->flags &= ~IFF_MULTICAST; net->mtu = DEFAULT_MTU_SIZE; nic = netdev_priv(net); memset(nic, 0, sizeof(struct nic)); nic->netdev = net; nic->phy_dev = phy_dev; nic->nic_id = index; form_mac_address( net->dev_addr, nic->src_mac_addr, nic->dest_mac_addr, mac_address, index); SET_NETDEV_DEV(net, dev); SET_NETDEV_DEVTYPE(net, &wwan_type); ret = register_netdev(net); if (ret) goto err; netif_carrier_on(net); phy_dev->dev[index] = net; } return 0; err: unregister_lte_device(phy_dev); return ret; }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang23997.95%125.00%
Joe Perches20.82%125.00%
Tom Gundersen20.82%125.00%
Somya Anand10.41%125.00%
Total244100.00%4100.00%


void unregister_lte_device(struct phy_dev *phy_dev) { struct net_device *net; int index; for (index = 0; index < MAX_NIC_TYPE; index++) { net = phy_dev->dev[index]; if (!net) continue; unregister_netdev(net); free_netdev(net); } }

Contributors

PersonTokensPropCommitsCommitProp
Won Kang5798.28%150.00%
Ioana Ciornei11.72%150.00%
Total58100.00%2100.00%


Overall Contributors

PersonTokensPropCommitsCommitProp
Won Kang438994.75%15.00%
Rashika Kheria621.34%420.00%
Joe Perches390.84%15.00%
Dan Carpenter360.78%15.00%
Emil Gedda360.78%15.00%
Monam Agarwal340.73%15.00%
Gulsah Kose140.30%15.00%
Dilek Uzulmez50.11%15.00%
Amitoj Kaur Chawla30.06%15.00%
Javier Rodriguez30.06%15.00%
Valentina Manea30.06%15.00%
Tom Gundersen20.04%15.00%
Ioana Ciornei20.04%15.00%
Somya Anand10.02%15.00%
Imre Deak10.02%15.00%
Ning Zhou10.02%15.00%
Bhumika Goyal10.02%15.00%
Total4632100.00%20100.00%
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.
Created with cregit.