2017-03-30 23:38:56 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* net/sixlowpan/sixlowpan_framer.c
|
|
|
|
*
|
2024-09-11 14:39:39 +02:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*
|
2021-04-02 12:39:20 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
2021-04-02 12:39:20 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
2021-04-02 12:39:20 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <assert.h>
|
2017-05-03 17:40:42 +02:00
|
|
|
#include <errno.h>
|
2017-03-30 23:38:56 +02:00
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include "nuttx/net/net.h"
|
2017-08-20 15:10:48 +02:00
|
|
|
#include "nuttx/net/radiodev.h"
|
2017-05-03 17:40:42 +02:00
|
|
|
#include "nuttx/wireless/ieee802154/ieee802154_mac.h"
|
2017-03-30 23:38:56 +02:00
|
|
|
|
|
|
|
#include "sixlowpan/sixlowpan_internal.h"
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
|
2020-04-16 17:40:34 +02:00
|
|
|
#ifdef CONFIG_WIRELESS_IEEE802154
|
2017-03-30 23:38:56 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-05-04 19:33:22 +02:00
|
|
|
* Name: sixlowpan_anyaddrnull
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-05-04 19:33:22 +02:00
|
|
|
* If the destination address is all zero in the MAC header buf, then it is
|
2017-05-04 17:05:41 +02:00
|
|
|
* broadcast on the 802.15.4 network.
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2017-05-04 19:33:22 +02:00
|
|
|
* addr - The address to check
|
|
|
|
* addrlen - The length of the address in bytes
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2017-05-04 19:33:22 +02:00
|
|
|
* True if the address is all zero.
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-05-09 15:34:59 +02:00
|
|
|
static bool sixlowpan_anyaddrnull(FAR const uint8_t *addr, uint8_t addrlen)
|
2017-03-30 23:38:56 +02:00
|
|
|
{
|
2017-05-04 19:33:22 +02:00
|
|
|
while (addrlen-- > 0)
|
2017-03-30 23:38:56 +02:00
|
|
|
{
|
2017-05-04 19:33:22 +02:00
|
|
|
if (addr[addrlen] != 0x00)
|
2017-03-30 23:38:56 +02:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2017-05-04 19:33:22 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: sixlowpan_saddrnull
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* If the destination address is all zero in the MAC header buf, then it is
|
|
|
|
* broadcast on the 802.15.4 network.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2017-05-04 19:33:22 +02:00
|
|
|
* eaddr - The short address to check
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The address length associated with the address mode.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-05-08 18:56:35 +02:00
|
|
|
static inline bool sixlowpan_saddrnull(FAR const uint8_t *saddr)
|
2017-05-04 19:33:22 +02:00
|
|
|
{
|
|
|
|
return sixlowpan_anyaddrnull(saddr, NET_6LOWPAN_SADDRSIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: sixlowpan_eaddrnull
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* If the destination address is all zero in the MAC header buf, then it is
|
|
|
|
* broadcast on the 802.15.4 network.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2017-05-04 19:33:22 +02:00
|
|
|
* eaddr - The extended address to check
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* The address length associated with the address mode.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-05-08 18:56:35 +02:00
|
|
|
static inline bool sixlowpan_eaddrnull(FAR const uint8_t *eaddr)
|
2017-05-04 19:33:22 +02:00
|
|
|
{
|
|
|
|
return sixlowpan_anyaddrnull(eaddr, NET_6LOWPAN_EADDRSIZE);
|
|
|
|
}
|
|
|
|
|
2017-03-30 23:38:56 +02:00
|
|
|
/****************************************************************************
|
2017-05-03 17:40:42 +02:00
|
|
|
* Public Functions
|
2017-03-30 23:38:56 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-05-03 17:40:42 +02:00
|
|
|
* Name: sixlowpan_meta_data
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-05-03 17:40:42 +02:00
|
|
|
* Based on the collected attributes and addresses, construct the MAC meta
|
|
|
|
* data structure that we need to interface with the IEEE802.15.4 MAC.
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
2017-05-03 17:40:42 +02:00
|
|
|
* Input Parameters:
|
2017-07-29 21:42:26 +02:00
|
|
|
* radio - Radio network driver state instance.
|
2017-05-08 18:56:35 +02:00
|
|
|
* pktmeta - Meta-data specific to the current outgoing frame
|
|
|
|
* meta - Location to return the corresponding meta data.
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-02-23 09:50:23 +01:00
|
|
|
* Ok is returned on success; Otherwise a negated errno value is returned.
|
2017-05-03 17:40:42 +02:00
|
|
|
*
|
|
|
|
* Assumptions:
|
|
|
|
* Called with the network locked.
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-08-19 16:48:52 +02:00
|
|
|
int sixlowpan_meta_data(FAR struct radio_driver_s *radio,
|
2017-07-31 03:10:51 +02:00
|
|
|
FAR const struct ieee802_txmetadata_s *pktmeta,
|
2017-08-19 20:32:56 +02:00
|
|
|
FAR struct ieee802154_frame_meta_s *meta)
|
2017-03-30 23:38:56 +02:00
|
|
|
{
|
|
|
|
bool rcvrnull;
|
|
|
|
|
2017-05-04 21:19:11 +02:00
|
|
|
/* Initialize all settings to all zero */
|
2017-03-30 23:38:56 +02:00
|
|
|
|
2017-05-03 17:40:42 +02:00
|
|
|
memset(meta, 0, sizeof(struct ieee802154_frame_meta_s));
|
2017-03-30 23:38:56 +02:00
|
|
|
|
2017-05-04 21:19:11 +02:00
|
|
|
/* Source address mode */
|
2017-03-30 23:38:56 +02:00
|
|
|
|
2017-08-19 20:32:56 +02:00
|
|
|
meta->srcmode = pktmeta->sextended != 0 ?
|
2017-07-17 07:20:01 +02:00
|
|
|
IEEE802154_ADDRMODE_EXTENDED :
|
|
|
|
IEEE802154_ADDRMODE_SHORT;
|
2017-03-30 23:38:56 +02:00
|
|
|
|
2017-05-04 21:19:11 +02:00
|
|
|
/* Check for a broadcast destination address (all zero) */
|
2017-03-30 23:38:56 +02:00
|
|
|
|
2017-05-08 18:56:35 +02:00
|
|
|
if (pktmeta->dextended != 0)
|
2017-05-04 19:33:22 +02:00
|
|
|
{
|
2017-05-04 21:19:11 +02:00
|
|
|
/* Extended destination address mode */
|
|
|
|
|
2017-07-31 03:10:51 +02:00
|
|
|
rcvrnull = sixlowpan_eaddrnull(pktmeta->dest.nm_addr);
|
2017-05-04 19:33:22 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2017-05-04 21:19:11 +02:00
|
|
|
/* Short destination address mode */
|
|
|
|
|
2017-07-31 03:10:51 +02:00
|
|
|
rcvrnull = sixlowpan_saddrnull(pktmeta->dest.nm_addr);
|
2017-05-04 19:33:22 +02:00
|
|
|
}
|
|
|
|
|
2017-11-01 21:15:21 +01:00
|
|
|
if (!rcvrnull)
|
2017-03-30 23:38:56 +02:00
|
|
|
{
|
2017-07-17 07:20:01 +02:00
|
|
|
meta->flags.ackreq = TRUE;
|
2017-03-30 23:38:56 +02:00
|
|
|
}
|
|
|
|
|
2017-05-04 21:19:11 +02:00
|
|
|
/* Destination address */
|
2017-03-30 23:38:56 +02:00
|
|
|
|
2017-05-04 21:19:11 +02:00
|
|
|
/* If the output address is NULL, then it is broadcast on the 802.15.4
|
|
|
|
* network.
|
2017-03-30 23:38:56 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
if (rcvrnull)
|
|
|
|
{
|
|
|
|
/* Broadcast requires short address mode. */
|
|
|
|
|
2017-08-04 18:58:29 +02:00
|
|
|
meta->destaddr.mode = IEEE802154_ADDRMODE_SHORT;
|
|
|
|
meta->destaddr.saddr[0] = 0xff;
|
|
|
|
meta->destaddr.saddr[1] = 0xff;
|
2017-03-30 23:38:56 +02:00
|
|
|
}
|
2017-05-08 18:56:35 +02:00
|
|
|
else if (pktmeta->dextended != 0)
|
2017-05-04 19:33:22 +02:00
|
|
|
{
|
2017-05-04 21:19:11 +02:00
|
|
|
/* Extended destination address mode */
|
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
meta->destaddr.mode = IEEE802154_ADDRMODE_EXTENDED;
|
2019-08-16 03:26:44 +02:00
|
|
|
sixlowpan_eaddrcopy(&meta->destaddr.eaddr, pktmeta->dest.nm_addr);
|
2017-05-04 19:33:22 +02:00
|
|
|
}
|
2017-03-30 23:38:56 +02:00
|
|
|
else
|
|
|
|
{
|
2017-05-04 21:19:11 +02:00
|
|
|
/* Short destination address mode */
|
|
|
|
|
2017-06-14 08:49:27 +02:00
|
|
|
meta->destaddr.mode = IEEE802154_ADDRMODE_SHORT;
|
2018-12-18 16:06:41 +01:00
|
|
|
|
|
|
|
/* 802.15.4 layer expects address in Little-Endian byte order */
|
|
|
|
|
|
|
|
meta->destaddr.saddr[0] = pktmeta->dest.nm_addr[1];
|
|
|
|
meta->destaddr.saddr[1] = pktmeta->dest.nm_addr[0];
|
2017-05-04 19:33:22 +02:00
|
|
|
}
|
2017-03-30 23:38:56 +02:00
|
|
|
|
2018-12-18 16:06:41 +01:00
|
|
|
/* 802.15.4 layer expects address in Little-Endian byte order */
|
|
|
|
|
|
|
|
meta->destaddr.panid[0] = pktmeta->dpanid[1];
|
|
|
|
meta->destaddr.panid[1] = pktmeta->dpanid[0];
|
2017-05-04 21:19:11 +02:00
|
|
|
|
|
|
|
/* Handle associated with MSDU. Will increment once per packet, not
|
2020-02-22 19:31:14 +01:00
|
|
|
* necessarily per frame: The same MSDU handle will be used for each
|
2017-05-06 14:48:06 +02:00
|
|
|
* fragment of a disassembled packet.
|
2017-05-04 21:19:11 +02:00
|
|
|
*/
|
|
|
|
|
2017-07-29 21:42:26 +02:00
|
|
|
meta->handle = radio->r_msdu_handle++;
|
2017-04-19 21:33:20 +02:00
|
|
|
|
2017-05-04 21:19:11 +02:00
|
|
|
#ifdef CONFIG_IEEE802154_SECURITY
|
2017-05-06 14:48:06 +02:00
|
|
|
# warning CONFIG_IEEE802154_SECURITY not yet supported
|
2017-05-03 17:40:42 +02:00
|
|
|
#endif
|
2017-06-28 21:32:19 +02:00
|
|
|
|
2017-05-04 21:19:11 +02:00
|
|
|
#ifdef CONFIG_IEEE802154_UWB
|
2017-05-06 14:48:06 +02:00
|
|
|
# warning CONFIG_IEEE802154_UWB not yet supported
|
2017-05-04 21:19:11 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
/* Ranging left zero */
|
2017-03-30 23:38:56 +02:00
|
|
|
|
2017-05-04 21:19:11 +02:00
|
|
|
return OK;
|
2017-05-03 17:40:42 +02:00
|
|
|
}
|
2017-07-31 03:10:51 +02:00
|
|
|
#endif
|
2017-03-30 23:38:56 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2017-05-03 17:40:42 +02:00
|
|
|
* Name: sixlowpan_frame_hdrlen
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* This function is before the first frame has been sent in order to
|
|
|
|
* determine what the size of the IEEE802.15.4 header will be. No frame
|
|
|
|
* buffer is required to make this determination.
|
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2017-07-29 21:42:26 +02:00
|
|
|
* radio - A reference IEEE802.15.4 MAC network device structure.
|
2017-05-03 17:40:42 +02:00
|
|
|
* meta - Meta data that describes the MAC header
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2020-02-22 19:31:14 +01:00
|
|
|
* The frame header length is returned on success; otherwise, a negated
|
2017-03-30 23:38:56 +02:00
|
|
|
* errno value is return on failure.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-08-19 16:48:52 +02:00
|
|
|
int sixlowpan_frame_hdrlen(FAR struct radio_driver_s *radio,
|
2017-07-31 03:10:51 +02:00
|
|
|
FAR const void *meta)
|
2017-03-30 23:38:56 +02:00
|
|
|
{
|
2017-07-29 21:42:26 +02:00
|
|
|
return radio->r_get_mhrlen(radio, meta);
|
2017-03-30 23:38:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-05-03 17:40:42 +02:00
|
|
|
* Name: sixlowpan_frame_submit
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
|
|
|
* Description:
|
2017-04-01 17:07:16 +02:00
|
|
|
* This function is called after eiether (1) the IEEE802.15.4 MAC driver
|
2017-05-03 17:40:42 +02:00
|
|
|
* polls for TX data or (2) after the IEEE802.15.4 MAC driver provides a
|
|
|
|
* new incoming frame and the network responds with an outgoing packet. It
|
|
|
|
* submits any new outgoing frame to the MAC.
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
2018-02-01 17:00:02 +01:00
|
|
|
* Input Parameters:
|
2017-07-29 21:42:26 +02:00
|
|
|
* radio - A reference to a radio network device instance.
|
2017-05-03 17:40:42 +02:00
|
|
|
* meta - Meta data that describes the MAC header
|
|
|
|
* frame - The IOB containing the frame to be submitted.
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
|
|
|
* Returned Value:
|
2017-05-03 17:40:42 +02:00
|
|
|
* Zero (OK) is returned on success; otherwise, a negated errno value is
|
|
|
|
* return on any failure.
|
2017-03-30 23:38:56 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-08-19 16:48:52 +02:00
|
|
|
int sixlowpan_frame_submit(FAR struct radio_driver_s *radio,
|
2017-07-31 03:10:51 +02:00
|
|
|
FAR const void *meta, FAR struct iob_s *frame)
|
2017-03-30 23:38:56 +02:00
|
|
|
{
|
2017-07-29 21:42:26 +02:00
|
|
|
return radio->r_req_data(radio, meta, frame);
|
2017-03-30 23:38:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* CONFIG_NET_6LOWPAN */
|