^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) * An interface between IEEE802.15.4 device and rest of the kernel.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright (C) 2007-2012 Siemens AG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Written by:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) * Pavel Smolenskiy <pavel.smolenskiy@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) * Maxim Gorbachyov <maxim.gorbachev@siemens.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) * Maxim Osipov <maxim.osipov@siemens.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) * Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) * Alexander Smirnov <alex.bluesman.smirnov@gmail.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #ifndef IEEE802154_NETDEVICE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #define IEEE802154_NETDEVICE_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <net/af_ieee802154.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #include <linux/skbuff.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #include <linux/ieee802154.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #include <net/cfg802154.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) struct ieee802154_sechdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #if defined(__LITTLE_ENDIAN_BITFIELD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) u8 level:3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) key_id_mode:2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) reserved:3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #elif defined(__BIG_ENDIAN_BITFIELD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) u8 reserved:3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) key_id_mode:2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) level:3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #error "Please fix <asm/byteorder.h>"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) u8 key_id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) __le32 frame_counter;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) union {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) __le32 short_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) __le64 extended_src;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) struct ieee802154_hdr_fc {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) #if defined(__LITTLE_ENDIAN_BITFIELD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) u16 type:3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) security_enabled:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) frame_pending:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) ack_request:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) intra_pan:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) reserved:3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) dest_addr_mode:2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) version:2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) source_addr_mode:2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) #elif defined(__BIG_ENDIAN_BITFIELD)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) u16 reserved:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) intra_pan:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) ack_request:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) frame_pending:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) security_enabled:1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) type:3,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) source_addr_mode:2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) version:2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) dest_addr_mode:2,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) reserved2:2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) #error "Please fix <asm/byteorder.h>"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) struct ieee802154_hdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) struct ieee802154_hdr_fc fc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) u8 seq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) struct ieee802154_addr source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) struct ieee802154_addr dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) struct ieee802154_sechdr sec;
^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) /* pushes hdr onto the skb. fields of hdr->fc that can be calculated from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) * the contents of hdr will be, and the actual value of those bits in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) * hdr->fc will be ignored. this includes the INTRA_PAN bit and the frame
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) * version, if SECEN is set.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) int ieee802154_hdr_push(struct sk_buff *skb, struct ieee802154_hdr *hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) /* pulls the entire 802.15.4 header off of the skb, including the security
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) * header, and performs pan id decompression
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int ieee802154_hdr_pull(struct sk_buff *skb, struct ieee802154_hdr *hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) /* parses the frame control, sequence number of address fields in a given skb
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) * and stores them into hdr, performing pan id decompression and length checks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) * to be suitable for use in header_ops.parse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) int ieee802154_hdr_peek_addrs(const struct sk_buff *skb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct ieee802154_hdr *hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) /* parses the full 802.15.4 header a given skb and stores them into hdr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) * performing pan id decompression and length checks to be suitable for use in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) * header_ops.parse
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int ieee802154_hdr_peek(const struct sk_buff *skb, struct ieee802154_hdr *hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) int ieee802154_max_payload(const struct ieee802154_hdr *hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) static inline int
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) ieee802154_sechdr_authtag_len(const struct ieee802154_sechdr *sec)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) switch (sec->level) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) case IEEE802154_SCF_SECLEVEL_MIC32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) case IEEE802154_SCF_SECLEVEL_ENC_MIC32:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) return 4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) case IEEE802154_SCF_SECLEVEL_MIC64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) case IEEE802154_SCF_SECLEVEL_ENC_MIC64:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) return 8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) case IEEE802154_SCF_SECLEVEL_MIC128:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) case IEEE802154_SCF_SECLEVEL_ENC_MIC128:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) return 16;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) case IEEE802154_SCF_SECLEVEL_NONE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) case IEEE802154_SCF_SECLEVEL_ENC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) static inline int ieee802154_hdr_length(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) struct ieee802154_hdr hdr;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) int len = ieee802154_hdr_pull(skb, &hdr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) if (len > 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) skb_push(skb, len);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) return len;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static inline bool ieee802154_addr_equal(const struct ieee802154_addr *a1,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) const struct ieee802154_addr *a2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) if (a1->pan_id != a2->pan_id || a1->mode != a2->mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) if ((a1->mode == IEEE802154_ADDR_LONG &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) a1->extended_addr != a2->extended_addr) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) (a1->mode == IEEE802154_ADDR_SHORT &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) a1->short_addr != a2->short_addr))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) return false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) return true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) static inline __le64 ieee802154_devaddr_from_raw(const void *raw)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) u64 temp;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) memcpy(&temp, raw, IEEE802154_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) return (__force __le64)swab64(temp);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static inline void ieee802154_devaddr_to_raw(void *raw, __le64 addr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) u64 temp = swab64((__force u64)addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) memcpy(raw, &temp, IEEE802154_ADDR_LEN);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) static inline void ieee802154_addr_from_sa(struct ieee802154_addr *a,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) const struct ieee802154_addr_sa *sa)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) a->mode = sa->addr_type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) a->pan_id = cpu_to_le16(sa->pan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) switch (a->mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) case IEEE802154_ADDR_SHORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) a->short_addr = cpu_to_le16(sa->short_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) case IEEE802154_ADDR_LONG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) a->extended_addr = ieee802154_devaddr_from_raw(sa->hwaddr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) static inline void ieee802154_addr_to_sa(struct ieee802154_addr_sa *sa,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) const struct ieee802154_addr *a)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) sa->addr_type = a->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) sa->pan_id = le16_to_cpu(a->pan_id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) switch (a->mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) case IEEE802154_ADDR_SHORT:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) sa->short_addr = le16_to_cpu(a->short_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) case IEEE802154_ADDR_LONG:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) ieee802154_devaddr_to_raw(sa->hwaddr, a->extended_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) * A control block of skb passed between the ARPHRD_IEEE802154 device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) * and other stack parts.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) struct ieee802154_mac_cb {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) u8 lqi;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) u8 type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) bool ackreq;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) bool secen;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) bool secen_override;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) u8 seclevel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) bool seclevel_override;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) struct ieee802154_addr source;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) struct ieee802154_addr dest;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) static inline struct ieee802154_mac_cb *mac_cb(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) return (struct ieee802154_mac_cb *)skb->cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static inline struct ieee802154_mac_cb *mac_cb_init(struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) BUILD_BUG_ON(sizeof(struct ieee802154_mac_cb) > sizeof(skb->cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) memset(skb->cb, 0, sizeof(struct ieee802154_mac_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) return mac_cb(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) IEEE802154_LLSEC_DEVKEY_IGNORE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) IEEE802154_LLSEC_DEVKEY_RESTRICT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) IEEE802154_LLSEC_DEVKEY_RECORD,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) __IEEE802154_LLSEC_DEVKEY_MAX,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) #define IEEE802154_MAC_SCAN_ED 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) #define IEEE802154_MAC_SCAN_ACTIVE 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) #define IEEE802154_MAC_SCAN_PASSIVE 2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) #define IEEE802154_MAC_SCAN_ORPHAN 3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) struct ieee802154_mac_params {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) s8 transmit_power;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) u8 min_be;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) u8 max_be;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) u8 csma_retries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) s8 frame_retries;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) bool lbt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct wpan_phy_cca cca;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) s32 cca_ed_level;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) struct wpan_phy;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) enum {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) IEEE802154_LLSEC_PARAM_ENABLED = BIT(0),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) IEEE802154_LLSEC_PARAM_FRAME_COUNTER = BIT(1),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) IEEE802154_LLSEC_PARAM_OUT_LEVEL = BIT(2),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) IEEE802154_LLSEC_PARAM_OUT_KEY = BIT(3),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) IEEE802154_LLSEC_PARAM_KEY_SOURCE = BIT(4),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) IEEE802154_LLSEC_PARAM_PAN_ID = BIT(5),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) IEEE802154_LLSEC_PARAM_HWADDR = BIT(6),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) IEEE802154_LLSEC_PARAM_COORD_HWADDR = BIT(7),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) IEEE802154_LLSEC_PARAM_COORD_SHORTADDR = BIT(8),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) struct ieee802154_llsec_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) int (*get_params)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) struct ieee802154_llsec_params *params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) int (*set_params)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) const struct ieee802154_llsec_params *params,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) int changed);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) int (*add_key)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) const struct ieee802154_llsec_key_id *id,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) const struct ieee802154_llsec_key *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) int (*del_key)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) const struct ieee802154_llsec_key_id *id);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) int (*add_dev)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) const struct ieee802154_llsec_device *llsec_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) int (*del_dev)(struct net_device *dev, __le64 dev_addr);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) int (*add_devkey)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) __le64 device_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) const struct ieee802154_llsec_device_key *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) int (*del_devkey)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) __le64 device_addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) const struct ieee802154_llsec_device_key *key);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) int (*add_seclevel)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) const struct ieee802154_llsec_seclevel *sl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) int (*del_seclevel)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) const struct ieee802154_llsec_seclevel *sl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) void (*lock_table)(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) void (*get_table)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) struct ieee802154_llsec_table **t);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) void (*unlock_table)(struct net_device *dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) * This should be located at net_device->ml_priv
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) * get_phy should increment the reference counting on returned phy.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) * Use wpan_wpy_put to put that reference.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) struct ieee802154_mlme_ops {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /* The following fields are optional (can be NULL). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) int (*assoc_req)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) struct ieee802154_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) u8 channel, u8 page, u8 cap);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) int (*assoc_resp)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) struct ieee802154_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) __le16 short_addr, u8 status);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) int (*disassoc_req)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) struct ieee802154_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) u8 reason);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) int (*start_req)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) struct ieee802154_addr *addr,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) u8 channel, u8 page, u8 bcn_ord, u8 sf_ord,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) u8 pan_coord, u8 blx, u8 coord_realign);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) int (*scan_req)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) u8 type, u32 channels, u8 page, u8 duration);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) int (*set_mac_params)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) const struct ieee802154_mac_params *params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) void (*get_mac_params)(struct net_device *dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) struct ieee802154_mac_params *params);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) const struct ieee802154_llsec_ops *llsec;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) static inline struct ieee802154_mlme_ops *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) ieee802154_mlme_ops(const struct net_device *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) return dev->ml_priv;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) #endif