^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) * Copyright (C) 2007-2012 Siemens AG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Written by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) * Pavel Smolenskiy <pavel.smolenskiy@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/crc-ccitt.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <asm/unaligned.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <net/mac802154.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <net/ieee802154_netdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <net/nl802154.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #include "ieee802154_i.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) static int ieee802154_deliver_skb(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) skb->ip_summed = CHECKSUM_UNNECESSARY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) skb->protocol = htons(ETH_P_IEEE802154);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) return netif_receive_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) ieee802154_subif_frame(struct ieee802154_sub_if_data *sdata,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) struct sk_buff *skb, const struct ieee802154_hdr *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) struct wpan_dev *wpan_dev = &sdata->wpan_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) __le16 span, sshort;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int rc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) pr_debug("getting packet via slave interface %s\n", sdata->dev->name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) span = wpan_dev->pan_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) sshort = wpan_dev->short_addr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) switch (mac_cb(skb)->dest.mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) case IEEE802154_ADDR_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) if (mac_cb(skb)->dest.mode != IEEE802154_ADDR_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) /* FIXME: check if we are PAN coordinator */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) skb->pkt_type = PACKET_OTHERHOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /* ACK comes with both addresses empty */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) skb->pkt_type = PACKET_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) case IEEE802154_ADDR_LONG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) if (mac_cb(skb)->dest.pan_id != span &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) mac_cb(skb)->dest.pan_id != cpu_to_le16(IEEE802154_PANID_BROADCAST))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) skb->pkt_type = PACKET_OTHERHOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) else if (mac_cb(skb)->dest.extended_addr == wpan_dev->extended_addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) skb->pkt_type = PACKET_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) skb->pkt_type = PACKET_OTHERHOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) case IEEE802154_ADDR_SHORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if (mac_cb(skb)->dest.pan_id != span &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) mac_cb(skb)->dest.pan_id != cpu_to_le16(IEEE802154_PANID_BROADCAST))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) skb->pkt_type = PACKET_OTHERHOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) else if (mac_cb(skb)->dest.short_addr == sshort)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) skb->pkt_type = PACKET_HOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) else if (mac_cb(skb)->dest.short_addr ==
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) cpu_to_le16(IEEE802154_ADDR_BROADCAST))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) skb->pkt_type = PACKET_BROADCAST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) skb->pkt_type = PACKET_OTHERHOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) pr_debug("invalid dest mode\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) goto fail;
^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) skb->dev = sdata->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) /* TODO this should be moved after netif_receive_skb call, otherwise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * wireshark will show a mac header with security fields and the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) * payload is already decrypted.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) rc = mac802154_llsec_decrypt(&sdata->sec, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) if (rc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) pr_debug("decryption failed: %i\n", rc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) sdata->dev->stats.rx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) sdata->dev->stats.rx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) switch (mac_cb(skb)->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) case IEEE802154_FC_TYPE_BEACON:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) case IEEE802154_FC_TYPE_ACK:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) case IEEE802154_FC_TYPE_MAC_CMD:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) case IEEE802154_FC_TYPE_DATA:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) return ieee802154_deliver_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) pr_warn_ratelimited("ieee802154: bad frame received "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) "(type = %d)\n", mac_cb(skb)->type);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) goto fail;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) fail:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) return NET_RX_DROP;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) ieee802154_print_addr(const char *name, const struct ieee802154_addr *addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) if (addr->mode == IEEE802154_ADDR_NONE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) pr_debug("%s not present\n", name);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) pr_debug("%s PAN ID: %04x\n", name, le16_to_cpu(addr->pan_id));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) if (addr->mode == IEEE802154_ADDR_SHORT) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) pr_debug("%s is short: %04x\n", name,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) le16_to_cpu(addr->short_addr));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) u64 hw = swab64((__force u64)addr->extended_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) pr_debug("%s is hardware: %8phC\n", name, &hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) static int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) ieee802154_parse_frame_start(struct sk_buff *skb, struct ieee802154_hdr *hdr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) int hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) struct ieee802154_mac_cb *cb = mac_cb_init(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) skb_reset_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) hlen = ieee802154_hdr_pull(skb, hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) if (hlen < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) skb->mac_len = hlen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) pr_debug("fc: %04x dsn: %02x\n", le16_to_cpup((__le16 *)&hdr->fc),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) hdr->seq);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) cb->type = hdr->fc.type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) cb->ackreq = hdr->fc.ack_request;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) cb->secen = hdr->fc.security_enabled;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) ieee802154_print_addr("destination", &hdr->dest);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) ieee802154_print_addr("source", &hdr->source);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) cb->source = hdr->source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) cb->dest = hdr->dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) if (hdr->fc.security_enabled) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) u64 key;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) pr_debug("seclevel %i\n", hdr->sec.level);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) switch (hdr->sec.key_id_mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) case IEEE802154_SCF_KEY_IMPLICIT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) pr_debug("implicit key\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) case IEEE802154_SCF_KEY_INDEX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) pr_debug("key %02x\n", hdr->sec.key_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) case IEEE802154_SCF_KEY_SHORT_INDEX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) pr_debug("key %04x:%04x %02x\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) le32_to_cpu(hdr->sec.short_src) >> 16,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) le32_to_cpu(hdr->sec.short_src) & 0xffff,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) hdr->sec.key_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) case IEEE802154_SCF_KEY_HW_INDEX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) key = swab64((__force u64)hdr->sec.extended_src);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) pr_debug("key source %8phC %02x\n", &key,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) hdr->sec.key_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) __ieee802154_rx_handle_packet(struct ieee802154_local *local,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) int ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) struct ieee802154_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) struct ieee802154_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) ret = ieee802154_parse_frame_start(skb, &hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) if (ret) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) pr_debug("got invalid frame\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) list_for_each_entry_rcu(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) if (sdata->wpan_dev.iftype != NL802154_IFTYPE_NODE)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (!ieee802154_sdata_running(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) ieee802154_subif_frame(sdata, skb, &hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) skb = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) kfree_skb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) static void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) ieee802154_monitors_rx(struct ieee802154_local *local, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) struct sk_buff *skb2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) struct ieee802154_sub_if_data *sdata;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) skb_reset_mac_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) skb->ip_summed = CHECKSUM_UNNECESSARY;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) skb->pkt_type = PACKET_OTHERHOST;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) skb->protocol = htons(ETH_P_IEEE802154);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) list_for_each_entry_rcu(sdata, &local->interfaces, list) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) if (sdata->wpan_dev.iftype != NL802154_IFTYPE_MONITOR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) if (!ieee802154_sdata_running(sdata))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) skb2 = skb_clone(skb, GFP_ATOMIC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) if (skb2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) skb2->dev = sdata->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) ieee802154_deliver_skb(skb2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) sdata->dev->stats.rx_packets++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) sdata->dev->stats.rx_bytes += skb->len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) void ieee802154_rx(struct ieee802154_local *local, struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) u16 crc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) WARN_ON_ONCE(softirq_count() == 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) if (local->suspended)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) /* TODO: When a transceiver omits the checksum here, we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) * add an own calculated one. This is currently an ugly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) * solution because the monitor needs a crc here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) if (local->hw.flags & IEEE802154_HW_RX_OMIT_CKSUM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) crc = crc_ccitt(0, skb->data, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) put_unaligned_le16(crc, skb_put(skb, 2));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) rcu_read_lock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) ieee802154_monitors_rx(local, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) /* Check if transceiver doesn't validate the checksum.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) * If not we validate the checksum here.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) if (local->hw.flags & IEEE802154_HW_RX_DROP_BAD_CKSUM) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) crc = crc_ccitt(0, skb->data, skb->len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) if (crc) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) goto drop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) /* remove crc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) skb_trim(skb, skb->len - 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) __ieee802154_rx_handle_packet(local, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) rcu_read_unlock();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) drop:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) kfree_skb(skb);
^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) void
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) ieee802154_rx_irqsafe(struct ieee802154_hw *hw, struct sk_buff *skb, u8 lqi)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) struct ieee802154_local *local = hw_to_local(hw);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) mac_cb(skb)->lqi = lqi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) skb->pkt_type = IEEE802154_RX_MSG;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) skb_queue_tail(&local->skb_queue, skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) tasklet_schedule(&local->tasklet);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) EXPORT_SYMBOL(ieee802154_rx_irqsafe);