mac802154: account for all header parts during wpan header creationg

The current WPAN header creation code checks for EMSGSIZE conditions,
but does not account for the MIC field that link layer security may add
at the end of the frame. Now that we can accurately calculate the
maximum payload size of packets, use that to check for EMSGSIZE
conditions.

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
ieee802154: change _cb handling slightly

The current mac_cb handling of ieee802154 is rather awkward and limited.
Decompose the single flags field into multiple fields with the meanings
of each subfield of the flags field to make future extensions (for
example, link-layer security) easier. Also don't set the frame sequence
number in upper layers, since that's a thing the MAC is supposed to set
on frame transmit - we set it on header creation, but assuming that
upper layers do not blindly duplicate our headers, this is fine.

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
6lowpan: fix fragmentation

Currently, 6lowpan creates one 802.15.4 MAC header for the original
packet the device was given by upper layers and reuses this header for
all fragments, if fragmentation is required. This also reuses frame
sequence numbers, which must not happen. 6lowpan also has issues with
fragmentation in the presence of security headers, since those may imply
the presence of trailing fields that are not accounted for by the
fragmentation code right now.

Fix both of these issues by properly allocating fragment skbs with
headromm and tailroom as specified by the underlying device, create one
header for each skb instead of reusing the original header, let the
underlying device do the rest.

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
ieee802154: fix dgram socket sendmsg()

802.15.4 datagram sockets do not currently have a compliant sendmsg().
The destination address supplied is always ignored, and in unconnected
mode, packets are broadcast instead of dropped with -EDESTADDRREQ. This
patch fixes 802.15.4 dgram sockets to be compliant, i.e.

 !conn && !msg_name => -EDESTADDRREQ
 !conn &&  msg_name => send to msg_name
  conn && !msg_name => send to connected
  conn &&  msg_name => -EISCONN

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
mac802154: make mac802154_wpan_open static

This function is only used within the same translation unit, so mark it
static.

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
ieee802154: add types for link-layer security

The added structures match 802.15.4-2011 link-layer security PIBs as
closely as is reasonable. Some lists required by the standard were
modeled as bitmaps (frame_types and command_frame_ids in *llsec_key,
802.15.4-2011 7.5/Table 61), since using lists for those seems a bit
excessive and not particularly useful. The DeviceDescriptorHandleList
was inverted and is here a per-device list, since operations on this
list are likely to have both a key and a device at hand, and per-device
lists of keys are shorter than per-key lists of devices.

For the mac802154 implementation of llsec, we mostly need only containers with
a little management info for the ieee802154* versions of these structs.
The one exception is they key struct, which requires one AEAD transform
for encryption and decryption per authsize and a CTR transform for
unauthenticated encryption/decryption. If we had a CCM* mode, which is
just like CCM but also supports authsize == 0, this would be less hacky.

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
mac802154: update Kconfig

Link-layer security requires AES CCM for authenticated modes and AES CTR
for the unauthenticated encryption mode.

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
mac802154: add llsec init/destroy and parameter access functions

Per-llsec hashes and lists can be safely initialized here, but delay adding
cleanup code for those lists and hashes while their element accessors do
not yet exists. llsec keys and devices require special cleanup code.

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
mac802154: add llsec key management functions

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
mac802154: add llsec device management functions

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
mac802154: add llsec device key management functions

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
mac802154: add llsec security level management functions

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
mac802154: add llsec encryption method

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
mac802154: add llsec decryption method

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
mac802154: integrate llsec with wpan devices

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
ieee802154: add dgram sockopts for security control

Allow datagram sockets to override the security settings of the device
they send from on a per-socket basis. Requires CAP_NET_ADMIN or
CAP_NET_RAW, since raw sockets can send arbitrary packets anyway.

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
mac802154: add llsec configuration functions

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
mac802154: propagate device address changes to llsec

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
ieee802154: add netlink interfaces for llsec parameter configuration

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>
ieee802154: add netlink interfaces for llsec key table configuration

Signed-off-by: Phoebe Buckheister <phoebe.buckheister@itwm.fraunhofer.de>