Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3) #include <net/6lowpan.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4) #include <net/ndisc.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5) #include <net/ieee802154_netdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6) #include <net/mac802154.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8) #include "6lowpan_i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #define LOWPAN_FRAG1_HEAD_SIZE	0x4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #define LOWPAN_FRAGN_HEAD_SIZE	0x5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) struct lowpan_addr_info {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) 	struct ieee802154_addr daddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 	struct ieee802154_addr saddr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) static inline struct
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) lowpan_addr_info *lowpan_skb_priv(const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) 	WARN_ON_ONCE(skb_headroom(skb) < sizeof(struct lowpan_addr_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 	return (struct lowpan_addr_info *)(skb->data -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 			sizeof(struct lowpan_addr_info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) /* This callback will be called from AF_PACKET and IPv6 stack, the AF_PACKET
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27)  * sockets gives an 8 byte array for addresses only!
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29)  * TODO I think AF_PACKET DGRAM (sending/receiving) RAW (sending) makes no
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30)  * sense here. We should disable it, the right use-case would be AF_INET6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31)  * RAW/DGRAM sockets.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) int lowpan_header_create(struct sk_buff *skb, struct net_device *ldev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 			 unsigned short type, const void *daddr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 			 const void *saddr, unsigned int len)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct wpan_dev *wpan_dev = lowpan_802154_dev(ldev)->wdev->ieee802154_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct lowpan_addr_info *info = lowpan_skb_priv(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct lowpan_802154_neigh *llneigh = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	const struct ipv6hdr *hdr = ipv6_hdr(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct neighbour *n;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	if (!daddr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 	/* TODO:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	 * if this package isn't ipv6 one, where should it be routed?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	if (type != ETH_P_IPV6)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 		return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 	/* intra-pan communication */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	info->saddr.pan_id = wpan_dev->pan_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 	info->daddr.pan_id = info->saddr.pan_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 	if (!memcmp(daddr, ldev->broadcast, EUI64_ADDR_LEN)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		info->daddr.short_addr = cpu_to_le16(IEEE802154_ADDR_BROADCAST);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 		info->daddr.mode = IEEE802154_ADDR_SHORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 		__le16 short_addr = cpu_to_le16(IEEE802154_ADDR_SHORT_UNSPEC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 		n = neigh_lookup(&nd_tbl, &hdr->daddr, ldev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 		if (n) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 			llneigh = lowpan_802154_neigh(neighbour_priv(n));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 			read_lock_bh(&n->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 			short_addr = llneigh->short_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 			read_unlock_bh(&n->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 		if (llneigh &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 		    lowpan_802154_is_valid_src_short_addr(short_addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 			info->daddr.short_addr = short_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			info->daddr.mode = IEEE802154_ADDR_SHORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			info->daddr.mode = IEEE802154_ADDR_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 			ieee802154_be64_to_le64(&info->daddr.extended_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 						daddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 		if (n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 			neigh_release(n);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	if (!saddr) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 		if (lowpan_802154_is_valid_src_short_addr(wpan_dev->short_addr)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 			info->saddr.mode = IEEE802154_ADDR_SHORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			info->saddr.short_addr = wpan_dev->short_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			info->saddr.mode = IEEE802154_ADDR_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 			info->saddr.extended_addr = wpan_dev->extended_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		info->saddr.mode = IEEE802154_ADDR_LONG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		ieee802154_be64_to_le64(&info->saddr.extended_addr, saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) static struct sk_buff*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) lowpan_alloc_frag(struct sk_buff *skb, int size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 		  const struct ieee802154_hdr *master_hdr, bool frag1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct net_device *wdev = lowpan_802154_dev(skb->dev)->wdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	struct sk_buff *frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	frag = alloc_skb(wdev->needed_headroom + wdev->needed_tailroom + size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 			 GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (likely(frag)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		frag->dev = wdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		frag->priority = skb->priority;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 		skb_reserve(frag, wdev->needed_headroom);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 		skb_reset_network_header(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		*mac_cb(frag) = *mac_cb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		if (frag1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 			skb_put_data(frag, skb_mac_header(skb), skb->mac_len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 			rc = wpan_dev_hard_header(frag, wdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 						  &master_hdr->dest,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 						  &master_hdr->source, size);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 			if (rc < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 				kfree_skb(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 				return ERR_PTR(rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 			}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 		frag = ERR_PTR(-ENOMEM);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 	return frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) lowpan_xmit_fragment(struct sk_buff *skb, const struct ieee802154_hdr *wpan_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 		     u8 *frag_hdr, int frag_hdrlen,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 		     int offset, int len, bool frag1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	struct sk_buff *frag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	raw_dump_inline(__func__, " fragment header", frag_hdr, frag_hdrlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	frag = lowpan_alloc_frag(skb, frag_hdrlen + len, wpan_hdr, frag1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	if (IS_ERR(frag))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 		return PTR_ERR(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	skb_put_data(frag, frag_hdr, frag_hdrlen);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	skb_put_data(frag, skb_network_header(skb) + offset, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	raw_dump_table(__func__, " fragment dump", frag->data, frag->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 	return dev_queue_xmit(frag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) lowpan_xmit_fragmented(struct sk_buff *skb, struct net_device *ldev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 		       const struct ieee802154_hdr *wpan_hdr, u16 dgram_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 		       u16 dgram_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	__be16 frag_tag;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	u8 frag_hdr[5];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	int frag_cap, frag_len, payload_cap, rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	int skb_unprocessed, skb_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	frag_tag = htons(lowpan_802154_dev(ldev)->fragment_tag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	lowpan_802154_dev(ldev)->fragment_tag++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 	frag_hdr[0] = LOWPAN_DISPATCH_FRAG1 | ((dgram_size >> 8) & 0x07);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	frag_hdr[1] = dgram_size & 0xff;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	memcpy(frag_hdr + 2, &frag_tag, sizeof(frag_tag));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	payload_cap = ieee802154_max_payload(wpan_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	frag_len = round_down(payload_cap - LOWPAN_FRAG1_HEAD_SIZE -
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 			      skb_network_header_len(skb), 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	skb_offset = skb_network_header_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 	skb_unprocessed = skb->len - skb->mac_len - skb_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	rc = lowpan_xmit_fragment(skb, wpan_hdr, frag_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 				  LOWPAN_FRAG1_HEAD_SIZE, 0,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 				  frag_len + skb_network_header_len(skb),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 				  true);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 		pr_debug("%s unable to send FRAG1 packet (tag: %d)",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 			 __func__, ntohs(frag_tag));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 		goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	frag_hdr[0] &= ~LOWPAN_DISPATCH_FRAG1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	frag_hdr[0] |= LOWPAN_DISPATCH_FRAGN;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	frag_cap = round_down(payload_cap - LOWPAN_FRAGN_HEAD_SIZE, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		dgram_offset += frag_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		skb_offset += frag_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		skb_unprocessed -= frag_len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 		frag_len = min(frag_cap, skb_unprocessed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		frag_hdr[4] = dgram_offset >> 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		rc = lowpan_xmit_fragment(skb, wpan_hdr, frag_hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 					  LOWPAN_FRAGN_HEAD_SIZE, skb_offset,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 					  frag_len, false);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			pr_debug("%s unable to send a FRAGN packet. (tag: %d, offset: %d)\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 				 __func__, ntohs(frag_tag), skb_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 			goto err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	} while (skb_unprocessed > frag_cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	ldev->stats.tx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	ldev->stats.tx_bytes += dgram_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	return NET_XMIT_SUCCESS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) err:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	return rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) static int lowpan_header(struct sk_buff *skb, struct net_device *ldev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 			 u16 *dgram_size, u16 *dgram_offset)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	struct wpan_dev *wpan_dev = lowpan_802154_dev(ldev)->wdev->ieee802154_ptr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	struct ieee802154_mac_cb *cb = mac_cb_init(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	struct lowpan_addr_info info;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	memcpy(&info, lowpan_skb_priv(skb), sizeof(info));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	*dgram_size = skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 	lowpan_header_compress(skb, ldev, &info.daddr, &info.saddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	/* dgram_offset = (saved bytes after compression) + lowpan header len */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	*dgram_offset = (*dgram_size - skb->len) + skb_network_header_len(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	cb->type = IEEE802154_FC_TYPE_DATA;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	if (info.daddr.mode == IEEE802154_ADDR_SHORT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	    ieee802154_is_broadcast_short_addr(info.daddr.short_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		cb->ackreq = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		cb->ackreq = wpan_dev->ackreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	return wpan_dev_hard_header(skb, lowpan_802154_dev(ldev)->wdev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 				    &info.daddr, &info.saddr, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) netdev_tx_t lowpan_xmit(struct sk_buff *skb, struct net_device *ldev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	struct ieee802154_hdr wpan_hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	int max_single, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 	u16 dgram_size, dgram_offset;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	pr_debug("package xmit\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	WARN_ON_ONCE(skb->len > IPV6_MIN_MTU);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	/* We must take a copy of the skb before we modify/replace the ipv6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	 * header as the header could be used elsewhere
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	if (unlikely(skb_headroom(skb) < ldev->needed_headroom ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		     skb_tailroom(skb) < ldev->needed_tailroom)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		struct sk_buff *nskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		nskb = skb_copy_expand(skb, ldev->needed_headroom,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 				       ldev->needed_tailroom, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		if (likely(nskb)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 			consume_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			skb = nskb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 			kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			return NET_XMIT_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		skb = skb_unshare(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		if (!skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 			return NET_XMIT_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	ret = lowpan_header(skb, ldev, &dgram_size, &dgram_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	if (ret < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 		return NET_XMIT_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	if (ieee802154_hdr_peek(skb, &wpan_hdr) < 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		return NET_XMIT_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	max_single = ieee802154_max_payload(&wpan_hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	if (skb_tail_pointer(skb) - skb_network_header(skb) <= max_single) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		skb->dev = lowpan_802154_dev(ldev)->wdev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 		ldev->stats.tx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 		ldev->stats.tx_bytes += dgram_size;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 		return dev_queue_xmit(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		netdev_tx_t rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 		pr_debug("frame is too big, fragmentation is needed\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 		rc = lowpan_xmit_fragmented(skb, ldev, &wpan_hdr, dgram_size,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 					    dgram_offset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 		return rc < 0 ? NET_XMIT_DROP : rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }