Lines Matching +full:addr +full:- +full:mode

1 // SPDX-License-Identifier: GPL-2.0-only
15 ieee802154_hdr_push_addr(u8 *buf, const struct ieee802154_addr *addr, in ieee802154_hdr_push_addr() argument
20 if (addr->mode == IEEE802154_ADDR_NONE) in ieee802154_hdr_push_addr()
24 memcpy(buf + pos, &addr->pan_id, 2); in ieee802154_hdr_push_addr()
28 switch (addr->mode) { in ieee802154_hdr_push_addr()
30 memcpy(buf + pos, &addr->short_addr, 2); in ieee802154_hdr_push_addr()
35 memcpy(buf + pos, &addr->extended_addr, IEEE802154_ADDR_LEN); in ieee802154_hdr_push_addr()
40 return -EINVAL; in ieee802154_hdr_push_addr()
52 memcpy(buf + 1, &hdr->frame_counter, 4); in ieee802154_hdr_push_sechdr()
54 switch (hdr->key_id_mode) { in ieee802154_hdr_push_sechdr()
62 memcpy(buf + pos, &hdr->short_src, 4); in ieee802154_hdr_push_sechdr()
67 memcpy(buf + pos, &hdr->extended_src, IEEE802154_ADDR_LEN); in ieee802154_hdr_push_sechdr()
72 buf[pos++] = hdr->key_id; in ieee802154_hdr_push_sechdr()
83 struct ieee802154_hdr_fc *fc = &hdr->fc; in ieee802154_hdr_push()
85 buf[pos++] = hdr->seq; in ieee802154_hdr_push()
87 fc->dest_addr_mode = hdr->dest.mode; in ieee802154_hdr_push()
89 rc = ieee802154_hdr_push_addr(buf + pos, &hdr->dest, false); in ieee802154_hdr_push()
91 return -EINVAL; in ieee802154_hdr_push()
94 fc->source_addr_mode = hdr->source.mode; in ieee802154_hdr_push()
96 if (hdr->source.pan_id == hdr->dest.pan_id && in ieee802154_hdr_push()
97 hdr->dest.mode != IEEE802154_ADDR_NONE) in ieee802154_hdr_push()
98 fc->intra_pan = true; in ieee802154_hdr_push()
100 rc = ieee802154_hdr_push_addr(buf + pos, &hdr->source, fc->intra_pan); in ieee802154_hdr_push()
102 return -EINVAL; in ieee802154_hdr_push()
105 if (fc->security_enabled) { in ieee802154_hdr_push()
106 fc->version = 1; in ieee802154_hdr_push()
108 rc = ieee802154_hdr_push_sechdr(buf + pos, &hdr->sec); in ieee802154_hdr_push()
110 return -EINVAL; in ieee802154_hdr_push()
124 ieee802154_hdr_get_addr(const u8 *buf, int mode, bool omit_pan, in ieee802154_hdr_get_addr() argument
125 struct ieee802154_addr *addr) in ieee802154_hdr_get_addr() argument
129 addr->mode = mode; in ieee802154_hdr_get_addr()
131 if (mode == IEEE802154_ADDR_NONE) in ieee802154_hdr_get_addr()
135 memcpy(&addr->pan_id, buf + pos, 2); in ieee802154_hdr_get_addr()
139 if (mode == IEEE802154_ADDR_SHORT) { in ieee802154_hdr_get_addr()
140 memcpy(&addr->short_addr, buf + pos, 2); in ieee802154_hdr_get_addr()
143 memcpy(&addr->extended_addr, buf + pos, IEEE802154_ADDR_LEN); in ieee802154_hdr_get_addr()
148 static int ieee802154_hdr_addr_len(int mode, bool omit_pan) in ieee802154_hdr_addr_len() argument
152 switch (mode) { in ieee802154_hdr_addr_len()
156 default: return -EINVAL; in ieee802154_hdr_addr_len()
166 memcpy(&hdr->frame_counter, buf + 1, 4); in ieee802154_hdr_get_sechdr()
168 switch (hdr->key_id_mode) { in ieee802154_hdr_get_sechdr()
176 memcpy(&hdr->short_src, buf + pos, 4); in ieee802154_hdr_get_sechdr()
181 memcpy(&hdr->extended_src, buf + pos, IEEE802154_ADDR_LEN); in ieee802154_hdr_get_sechdr()
186 hdr->key_id = buf[pos++]; in ieee802154_hdr_get_sechdr()
207 dlen = ieee802154_hdr_addr_len(hdr->fc.dest_addr_mode, false); in ieee802154_hdr_minlen()
208 slen = ieee802154_hdr_addr_len(hdr->fc.source_addr_mode, in ieee802154_hdr_minlen()
209 hdr->fc.intra_pan); in ieee802154_hdr_minlen()
212 return -EINVAL; in ieee802154_hdr_minlen()
214 return 3 + dlen + slen + hdr->fc.security_enabled; in ieee802154_hdr_minlen()
222 pos += ieee802154_hdr_get_addr(buf + pos, hdr->fc.dest_addr_mode, in ieee802154_hdr_get_addrs()
223 false, &hdr->dest); in ieee802154_hdr_get_addrs()
224 pos += ieee802154_hdr_get_addr(buf + pos, hdr->fc.source_addr_mode, in ieee802154_hdr_get_addrs()
225 hdr->fc.intra_pan, &hdr->source); in ieee802154_hdr_get_addrs()
227 if (hdr->fc.intra_pan) in ieee802154_hdr_get_addrs()
228 hdr->source.pan_id = hdr->dest.pan_id; in ieee802154_hdr_get_addrs()
239 return -EINVAL; in ieee802154_hdr_pull()
241 memcpy(hdr, skb->data, 3); in ieee802154_hdr_pull()
245 return -EINVAL; in ieee802154_hdr_pull()
247 pos += ieee802154_hdr_get_addrs(skb->data + pos, hdr); in ieee802154_hdr_pull()
249 if (hdr->fc.security_enabled) { in ieee802154_hdr_pull()
250 int want = pos + ieee802154_hdr_sechdr_len(skb->data[pos]); in ieee802154_hdr_pull()
253 return -EINVAL; in ieee802154_hdr_pull()
255 pos += ieee802154_hdr_get_sechdr(skb->data + pos, &hdr->sec); in ieee802154_hdr_pull()
270 return -EINVAL; in ieee802154_hdr_peek_addrs()
276 return -EINVAL; in ieee802154_hdr_peek_addrs()
291 return -EINVAL; in ieee802154_hdr_peek()
293 if (hdr->fc.security_enabled) { in ieee802154_hdr_peek()
298 return -EINVAL; in ieee802154_hdr_peek()
300 pos += ieee802154_hdr_get_sechdr(buf + pos, &hdr->sec); in ieee802154_hdr_peek()
311 if (hdr->fc.security_enabled) { in ieee802154_max_payload()
312 hlen += ieee802154_sechdr_lengths[hdr->sec.key_id_mode] - 1; in ieee802154_max_payload()
313 hlen += ieee802154_sechdr_authtag_len(&hdr->sec); in ieee802154_max_payload()
316 return IEEE802154_MTU - hlen - IEEE802154_MFR_SIZE; in ieee802154_max_payload()