Merge remote-tracking branch 'origin/master' into ieee802154

This commit is contained in:
Gregory Nutt
2017-04-01 09:08:35 -06:00
83 changed files with 8170 additions and 1135 deletions
+3 -3
View File
@@ -464,9 +464,9 @@ Notes about Header Files
Certain header files, such as setjmp.h, stdarg.h, and math.h, may still
be needed from your toolchain and your compiler may not, however, be able
to find these if you compile NuttX without using standard header file.
If that is the case, one solution is to copy those header file from
your toolchain into the NuttX include directory.
to find these if you compile NuttX without using standard header files
(ie., with -nostdinc). If that is the case, one solution is to copy
those header file from your toolchain into the NuttX include directory.
Duplicated Header Files.
+1 -1
View File
@@ -1823,7 +1823,7 @@ config STM32F7_HAVE_RTC_COUNTER
config STM32F7_HAVE_RTC_SUBSECONDS
bool
default n
default y
config RTC_MAGIC_REG
int "The BKP register used to store/check the Magic value to determine if RTC is set already"
+4
View File
@@ -149,6 +149,10 @@ ifeq ($(filter y,$(CONFIG_STM32F7_IWDG) $(CONFIG_STM32F7_RTC_LSICLOCK)),y)
CHIP_CSRCS += stm32_lsi.c
endif
ifeq ($(CONFIG_STM32F7_RTC_LSECLOCK),y)
CHIP_CSRCS += stm32_lse.c
endif
ifeq ($(CONFIG_STM32F7_I2C),y)
CHIP_CSRCS += stm32_i2c.c
endif
+1 -1
View File
@@ -129,7 +129,7 @@ static int stm32_exti_pvd_isr(int irq, void *context, void *arg)
****************************************************************************/
int stm32_exti_pvd(bool risingedge, bool fallingedge, bool event,
xcpt_t func, void *arg);
xcpt_t func, void *arg)
{
/* Get the previous GPIO IRQ handler; Save the new IRQ handler. */
@@ -1,8 +1,9 @@
/****************************************************************************
* net/sixlowpan/sixlowpan_sniffer.c
* arch/arm/src/stm32f7/stm32_lse.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* Authors: Gregory Nutt <gnutt@nuttx.org>
* David Sidrane <david_s5@nscdg.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -39,43 +40,47 @@
#include <nuttx/config.h>
#include "nuttx/net/net.h"
#include "nuttx/net/sixlowpan.h"
#include "up_arch.h"
#include "sixlowpan/sixlowpan_internal.h"
#ifdef CONFIG_NET_6LOWPAN_SNIFFER
#include "stm32_rcc.h"
#include "stm32_pwr.h"
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Function: sixlowpan_set_sniffer
* Name: stm32_rcc_enablelse
*
* Description:
* Configure to use an architecture-specific sniffer to enable tracing of
* IP.
*
* Input parameters:
* sniffer - A reference to the new sniffer to be used. This may
* be a NULL value to disable the sniffer.
*
* Returned Value:
* None
* Enable the External Low-Speed (LSE) oscillator.
*
****************************************************************************/
void sixlowpan_set_sniffer(FAR struct sixlowpan_rime_sniffer_s *sniffer)
void stm32_rcc_enablelse(void)
{
/* Make sure that the sniffer is not in use */
uint32_t regval;
net_lock();
/* The LSE is in the RTC domain and write access is denied to this domain
* after reset, you have to enable write access using DBP bit in the PWR CR
* register before to configuring the LSE.
*/
/* Then instantiate the new sniffer */
stm32_pwr_enablebkp(true);
g_sixlowpan_sniffer = sniffer;
net_unlock();
/* Enable the External Low-Speed (LSE) oscillator by setting the LSEON bit
* the RCC BDCR register.
*/
regval = getreg32(STM32_RCC_BDCR);
regval |= RCC_BDCR_LSEON;
putreg32(regval,STM32_RCC_BDCR);
/* Wait for the LSE clock to be ready */
while (((regval = getreg32(STM32_RCC_BDCR)) & RCC_BDCR_LSERDY) == 0);
/* Disable backup domain access if it was disabled on entry */
stm32_pwr_enablebkp(false);
}
#endif /* CONFIG_NET_6LOWPAN_SNIFFER */
+1 -1
View File
@@ -1,5 +1,5 @@
/****************************************************************************
* arch/arm/src/stm32f/stm32_lsi.c
* arch/arm/src/stm32f7/stm32_lsi.c
*
* Copyright (C) 2012, 2015-2016 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org>
+50 -30
View File
@@ -196,7 +196,7 @@ static void rtc_dumpregs(FAR const char *msg)
rtcinfo(" TSDR: %08x\n", getreg32(STM32_RTC_TSDR));
rtcinfo(" TSSSR: %08x\n", getreg32(STM32_RTC_TSSSR));
rtcinfo(" CALR: %08x\n", getreg32(STM32_RTC_CALR));
rtcinfo(" TAFCR: %08x\n", getreg32(STM32_RTC_TAFCR));
rtcinfo(" TAMPCR: %08x\n", getreg32(STM32_RTC_TAMPCR));
rtcinfo("ALRMASSR: %08x\n", getreg32(STM32_RTC_ALRMASSR));
rtcinfo("ALRMBSSR: %08x\n", getreg32(STM32_RTC_ALRMBSSR));
rtcinfo("MAGICREG: %08x\n", getreg32(RTC_MAGIC_REG));
@@ -227,7 +227,8 @@ static void rtc_dumpregs(FAR const char *msg)
****************************************************************************/
#ifdef CONFIG_DEBUG_RTC_INFO
static void rtc_dumptime(FAR const struct tm *tp, FAR const char *msg)
static void rtc_dumptime(FAR const struct tm *tp, FAR const uint32_t *usecs,
FAR const char *msg)
{
rtcinfo("%s:\n", msg);
rtcinfo(" tm_sec: %08x\n", tp->tm_sec);
@@ -236,9 +237,14 @@ static void rtc_dumptime(FAR const struct tm *tp, FAR const char *msg)
rtcinfo(" tm_mday: %08x\n", tp->tm_mday);
rtcinfo(" tm_mon: %08x\n", tp->tm_mon);
rtcinfo(" tm_year: %08x\n", tp->tm_year);
if (usecs != NULL)
{
rtcinfo(" usecs: %08x\n", (unsigned int)*usecs);
}
}
#else
# define rtc_dumptime(tp, msg)
# define rtc_dumptime(tp, usecs, msg)
#endif
/****************************************************************************
@@ -1069,34 +1075,48 @@ int up_rtc_initialize(void)
*
****************************************************************************/
#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
#ifdef CONFIG_STM32F7_HAVE_RTC_SUBSECONDS
int stm32_rtc_getdatetime_with_subseconds(FAR struct tm *tp, FAR long *nsec)
#else
int up_rtc_getdatetime(FAR struct tm *tp)
#endif
{
#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
uint32_t ssr;
#endif
uint32_t dr;
uint32_t tr;
uint32_t tmp;
#ifdef CONFIG_STM32F7_HAVE_RTC_SUBSECONDS
uint32_t ssr;
uint32_t prediv_s;
uint32_t usecs;
#endif
/* Sample the data time registers. There is a race condition here... If
* we sample the time just before midnight on December 31, the date could
* be wrong because the day rolled over while were sampling.
* be wrong because the day rolled over while were sampling. Thus loop for
* checking overflow here is needed. There is a race condition with
* subseconds too. If we sample TR register just before second rolling
* and subseconds are read at wrong second, we get wrong time.
*/
do
{
dr = getreg32(STM32_RTC_DR);
tr = getreg32(STM32_RTC_TR);
#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
#ifdef CONFIG_STM32F7_HAVE_RTC_SUBSECONDS
ssr = getreg32(STM32_RTC_SSR);
tmp = getreg32(STM32_RTC_TR);
if (tmp != tr)
{
continue;
}
#endif
tmp = getreg32(STM32_RTC_DR);
if (tmp == dr)
{
break;
}
}
while (tmp != dr);
while (1);
rtc_dumpregs("Reading Time");
@@ -1141,31 +1161,31 @@ int up_rtc_getdatetime(FAR struct tm *tp)
tp->tm_isdst = 0
#endif
#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
#ifdef CONFIG_STM32F7_HAVE_RTC_SUBSECONDS
/* Return RTC sub-seconds if no configured and if a non-NULL value
* of nsec has been provided to receive the sub-second value.
*/
if (nsec)
prediv_s = getreg32(STM32_RTC_PRER) & RTC_PRER_PREDIV_S_MASK;
prediv_s >>= RTC_PRER_PREDIV_S_SHIFT;
ssr &= RTC_SSR_MASK;
/* Maximum prediv_s is 0x7fff, thus we can multiply by 100000 and
* still fit 32-bit unsigned integer.
*/
usecs = (((prediv_s - ssr) * 100000) / (prediv_s + 1)) * 10;
if (nsec != NULL)
{
uint32_t prediv_s;
uint32_t usecs;
prediv_s = getreg32(STM32_RTC_PRER) & RTC_PRER_PREDIV_S_MASK;
prediv_s >>= RTC_PRER_PREDIV_S_SHIFT;
ssr &= RTC_SSR_MASK;
/* Maximum prediv_s is 0x7fff, thus we can multiply by 100000 and
* still fit 32-bit unsigned integer.
*/
usecs = (((prediv_s - ssr) * 100000) / (prediv_s + 1)) * 10;
*nsec = usecs * 1000;
}
#endif /* CONFIG_STM32_HAVE_RTC_SUBSECONDS */
rtc_dumptime((FAR const struct tm *)tp, "Returning");
rtc_dumptime((FAR const struct tm *)tp, &usecs, "Returning");
#else /* CONFIG_STM32_HAVE_RTC_SUBSECONDS */
rtc_dumptime((FAR const struct tm *)tp, NULL, "Returning");
#endif
return OK;
}
@@ -1192,7 +1212,7 @@ int up_rtc_getdatetime(FAR struct tm *tp)
*
****************************************************************************/
#ifdef CONFIG_STM32_HAVE_RTC_SUBSECONDS
#ifdef CONFIG_STM32F7_HAVE_RTC_SUBSECONDS
int up_rtc_getdatetime(FAR struct tm *tp)
{
return stm32_rtc_getdatetime_with_subseconds(tp, NULL);
@@ -1221,7 +1241,7 @@ int stm32_rtc_setdatetime(FAR const struct tm *tp)
uint32_t dr;
int ret;
rtc_dumptime(tp, "Setting time");
rtc_dumptime(tp, NULL, "Setting time");
/* Then write the broken out values to the RTC */
@@ -1337,7 +1357,7 @@ int stm32_rtc_setalarm(FAR struct alm_setalarm_s *alminfo)
/* REVISIT: Should test that the time is in the future */
rtc_dumptime(&alminfo->as_time, "New alarm time");
rtc_dumptime(&alminfo->as_time, NULL, "New alarm time");
/* Break out the values to the HW alarm register format. The values in
* all STM32 fields match the fields of struct tm in this case. Notice
+1 -1
View File
@@ -1510,7 +1510,7 @@ static int stm32_sdmmc_rdyinterrupt(int irq, void *context, void *arg)
*
****************************************************************************/
static int stm32_sdmmc_interrupt(int irq, void *context, void *arg);
static int stm32_sdmmc_interrupt(int irq, void *context, void *arg)
{
struct stm32_dev_s *priv =(struct stm32_dev_s *)arg;
uint32_t enabled;
+66 -151
View File
@@ -1,8 +1,9 @@
/****************************************************************************
* arch/arm/src/stm32f7/stm32_serial.c
*
* Copyright (C) 2015-2016 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
* Copyright (C) 2015-2017 Gregory Nutt. All rights reserved.
* Authors: Gregory Nutt <gnutt@nuttx.org>
* David Sidrane <david_s5@nscdg.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -189,16 +190,6 @@
CONFIG_USART_DMAPRIO | \
DMA_SCR_PBURST_SINGLE | \
DMA_SCR_MBURST_SINGLE)
# ifdef CONFIG_SERIAL_IFLOWCONTROL
# define SERIAL_DMA_IFLOW_CONTROL_WORD \
(DMA_SCR_DIR_P2M | \
DMA_SCR_MINC | \
DMA_SCR_PSIZE_8BITS | \
DMA_SCR_MSIZE_8BITS | \
CONFIG_USART_DMAPRIO | \
DMA_SCR_PBURST_SINGLE | \
DMA_SCR_MBURST_SINGLE)
# endif
#endif /* SERIAL_HAVE_DMA */
/* Power management definitions */
@@ -286,8 +277,7 @@ struct up_dev_s
#ifdef SERIAL_HAVE_DMA
DMA_HANDLE rxdma; /* currently-open receive DMA stream */
bool rxenable; /* DMA-based reception en/disable */
uint16_t rxdmain; /* Next byte in the DMA where hardware will write */
uint16_t rxdmaout; /* Next byte in the DMA buffer to be read */
uint32_t rxdmanext; /* Next byte in the DMA buffer to be read */
char *const rxfifo; /* Receive DMA buffer */
#endif
@@ -1139,7 +1129,22 @@ static void up_set_format(struct uart_dev_s *dev)
uint32_t regval;
uint32_t usartdiv8;
uint32_t cr1;
uint32_t cr1_ue;
uint32_t brr;
irqstate_t flags;
flags = enter_critical_section();
/* Get the original state of UE */
cr1 = up_serialin(priv, STM32_USART_CR1_OFFSET);
cr1_ue = cr1 & USART_CR1_UE;
cr1 &= ~USART_CR1_UE;
/* Disable UE as the format bits and baud rate registers can not be
* updated while UE = 1 */
up_serialout(priv, STM32_USART_CR1_OFFSET, cr1);
/* In case of oversampling by 8, the equation is:
*
@@ -1159,7 +1164,6 @@ static void up_set_format(struct uart_dev_s *dev)
/* Use oversamply by 8 only if the divisor is small. But what is small? */
cr1 = up_serialin(priv, STM32_USART_CR1_OFFSET);
if (usartdiv8 > 100)
{
/* Use usartdiv16 */
@@ -1188,30 +1192,44 @@ static void up_set_format(struct uart_dev_s *dev)
/* Configure parity mode */
regval = up_serialin(priv, STM32_USART_CR1_OFFSET);
regval &= ~(USART_CR1_PCE | USART_CR1_PS | USART_CR1_M0);
cr1 &= ~(USART_CR1_PCE | USART_CR1_PS | USART_CR1_M0 | USART_CR1_M1);
if (priv->parity == 1) /* Odd parity */
{
regval |= (USART_CR1_PCE | USART_CR1_PS);
cr1 |= (USART_CR1_PCE | USART_CR1_PS);
}
else if (priv->parity == 2) /* Even parity */
{
regval |= USART_CR1_PCE;
cr1 |= USART_CR1_PCE;
}
/* Configure word length (Default: 8-bits) */
/* Configure word length (parity uses one of configured bits)
*
* Default: 1 start, 8 data (no parity), n stop, OR
* 1 start, 7 data + parity, n stop
*/
if (priv->bits == 7)
if (priv->bits == 9 || (priv->bits == 8 && priv->parity != 0))
{
regval |= USART_CR1_M1;
/* Select: 1 start, 8 data + parity, n stop, OR
* 1 start, 9 data (no parity), n stop.
*/
cr1 |= USART_CR1_M0;
}
else if (priv->bits == 9)
else if (priv->bits == 7 && priv->parity == 0)
{
regval |= USART_CR1_M0;
/* Select: 1 start, 7 data (no parity), n stop, OR
*/
cr1 |= USART_CR1_M1;
}
up_serialout(priv, STM32_USART_CR1_OFFSET, regval);
/* Else Select: 1 start, 7 data + parity, n stop, OR
* 1 start, 8 data (no parity), n stop.
*/
up_serialout(priv, STM32_USART_CR1_OFFSET, cr1);
/* Configure STOP bits */
@@ -1230,7 +1248,8 @@ static void up_set_format(struct uart_dev_s *dev)
regval = up_serialin(priv, STM32_USART_CR3_OFFSET);
regval &= ~(USART_CR3_CTSE | USART_CR3_RTSE);
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && !defined(CONFIG_STM32F7_FLOWCONTROL_BROKEN)
#if defined(CONFIG_SERIAL_IFLOWCONTROL) && \
!defined(CONFIG_STM32F7_FLOWCONTROL_BROKEN)
if (priv->iflow && (priv->rts_gpio != 0))
{
regval |= USART_CR3_RTSE;
@@ -1245,6 +1264,8 @@ static void up_set_format(struct uart_dev_s *dev)
#endif
up_serialout(priv, STM32_USART_CR3_OFFSET, regval);
up_serialout(priv, STM32_USART_CR1_OFFSET, cr1 | cr1_ue);
leave_critical_section(flags);
}
#endif /* CONFIG_SUPPRESS_UART_CONFIG */
@@ -1473,35 +1494,19 @@ static int up_dma_setup(struct uart_dev_s *dev)
priv->rxdma = stm32_dmachannel(priv->rxdma_channel);
#ifdef CONFIG_SERIAL_IFLOWCONTROL
if (priv->iflow)
{
/* Configure for non-circular DMA reception into the RX FIFO */
/* Configure for circular DMA reception into the RX FIFO */
stm32_dmasetup(priv->rxdma,
priv->usartbase + STM32_USART_RDR_OFFSET,
(uint32_t)priv->rxfifo,
RXDMA_BUFFER_SIZE,
SERIAL_DMA_IFLOW_CONTROL_WORD);
}
else
#endif
{
/* Configure for circular DMA reception into the RX FIFO */
stm32_dmasetup(priv->rxdma,
priv->usartbase + STM32_USART_RDR_OFFSET,
(uint32_t)priv->rxfifo,
RXDMA_BUFFER_SIZE,
SERIAL_DMA_CONTROL_WORD);
}
stm32_dmasetup(priv->rxdma,
priv->usartbase + STM32_USART_RDR_OFFSET,
(uint32_t)priv->rxfifo,
RXDMA_BUFFER_SIZE,
SERIAL_DMA_CONTROL_WORD);
/* Reset our DMA shadow pointer to match the address just
* programmed above.
*/
priv->rxdmaout = 0;
priv->rxdmain = 0;
priv->rxdmanext = 0;
/* Enable receive DMA for the UART */
@@ -1509,26 +1514,12 @@ static int up_dma_setup(struct uart_dev_s *dev)
regval |= USART_CR3_DMAR;
up_serialout(priv, STM32_USART_CR3_OFFSET, regval);
#ifdef CONFIG_SERIAL_IFLOWCONTROL
if (priv->iflow)
{
/* Start the DMA channel, and arrange for callbacks at the full point
* in the FIFO. After buffer gets full, hardware flow-control kicks
* in and DMA transfer is stopped.
*/
/* Start the DMA channel, and arrange for callbacks at the half and
* full points in the FIFO. This ensures that we have half a FIFO
* worth of time to claim bytes before they are overwritten.
*/
stm32_dmastart(priv->rxdma, up_dma_rxcallback, (void *)priv, false);
}
else
#endif
{
/* Start the DMA channel, and arrange for callbacks at the half and
* full points in the FIFO. This ensures that we have half a FIFO
* worth of time to claim bytes before they are overwritten.
*/
stm32_dmastart(priv->rxdma, up_dma_rxcallback, (void *)priv, true);
}
stm32_dmastart(priv->rxdma, up_dma_rxcallback, (void *)priv, true);
return OK;
}
@@ -2226,49 +2217,27 @@ static bool up_rxflowcontrol(struct uart_dev_s *dev,
static int up_dma_receive(struct uart_dev_s *dev, unsigned int *status)
{
struct up_dev_s *priv = (struct up_dev_s *)dev->priv;
uint32_t rxdmain;
int c = 0;
/* If additional bytes have been added to the DMA buffer, then we will need
* to invalidate the DMA buffer before reading the byte.
*/
rxdmain = up_dma_nextrx(priv);
if (rxdmain != priv->rxdmain)
if (up_dma_nextrx(priv) != priv->rxdmanext)
{
/* Invalidate the DMA buffer */
arch_invalidate_dcache((uintptr_t)priv->rxfifo,
(uintptr_t)priv->rxfifo + RXDMA_BUFFER_SIZE - 1);
/* Since DMA is ongoing, there are lots of race conditions here. We
* just have to hope that the rxdmaout stays well ahead of rxdmain.
*/
/* Now read from the DMA buffer */
priv->rxdmain = rxdmain;
}
c = priv->rxfifo[priv->rxdmanext];
/* Now check if there are any bytes to read from the DMA buffer */
if (rxdmain != priv->rxdmaout)
{
c = priv->rxfifo[priv->rxdmaout];
priv->rxdmaout++;
if (priv->rxdmaout == RXDMA_BUFFER_SIZE)
priv->rxdmanext++;
if (priv->rxdmanext == RXDMA_BUFFER_SIZE)
{
#ifdef CONFIG_SERIAL_IFLOWCONTROL
if (priv->iflow)
{
/* RX DMA buffer full. RX paused, RTS line pulled up to prevent
* more input data from other end.
*/
}
else
#endif
{
priv->rxdmaout = 0;
}
priv->rxdmanext = 0;
}
}
@@ -2276,41 +2245,6 @@ static int up_dma_receive(struct uart_dev_s *dev, unsigned int *status)
}
#endif
/****************************************************************************
* Name: up_dma_reenable
*
* Description:
* Call to re-enable RX DMA.
*
****************************************************************************/
#if defined(SERIAL_HAVE_DMA) && defined(CONFIG_SERIAL_IFLOWCONTROL)
static void up_dma_reenable(struct up_dev_s *priv)
{
/* Configure for non-circular DMA reception into the RX FIFO */
stm32_dmasetup(priv->rxdma,
priv->usartbase + STM32_USART_RDR_OFFSET,
(uint32_t)priv->rxfifo,
RXDMA_BUFFER_SIZE,
SERIAL_DMA_IFLOW_CONTROL_WORD);
/* Reset our DMA shadow pointer to match the address just programmed
* above.
*/
priv->rxdmaout = 0;
priv->rxdmain = 0;
/* Start the DMA channel, and arrange for callbacks at the full point in
* the FIFO. After buffer gets full, hardware flow-control kicks in and
* DMA transfer is stopped.
*/
stm32_dmastart(priv->rxdma, up_dma_rxcallback, (void *)priv, false);
}
#endif
/****************************************************************************
* Name: up_dma_rxint
*
@@ -2333,15 +2267,6 @@ static void up_dma_rxint(struct uart_dev_s *dev, bool enable)
*/
priv->rxenable = enable;
#ifdef CONFIG_SERIAL_IFLOWCONTROL
if (priv->iflow && priv->rxenable && (priv->rxdmaout == RXDMA_BUFFER_SIZE))
{
/* Re-enable RX DMA. */
up_dma_reenable(priv);
}
#endif
}
#endif
@@ -2362,7 +2287,7 @@ static bool up_dma_rxavailable(struct uart_dev_s *dev)
* do not match, then there are bytes to be received.
*/
return (up_dma_nextrx(priv) != priv->rxdmaout);
return (up_dma_nextrx(priv) != priv->rxdmanext);
}
#endif
@@ -2486,16 +2411,6 @@ static void up_dma_rxcallback(DMA_HANDLE handle, uint8_t status, void *arg)
if (priv->rxenable && up_dma_rxavailable(&priv->dev))
{
uart_recvchars(&priv->dev);
#ifdef CONFIG_SERIAL_IFLOWCONTROL
if (priv->iflow && priv->rxenable &&
(priv->rxdmaout == RXDMA_BUFFER_SIZE))
{
/* Re-enable RX DMA. */
up_dma_reenable(priv);
}
#endif
}
}
#endif
+1 -1
View File
@@ -437,8 +437,8 @@ static void skel_receive(FAR struct skel_driver_s *priv)
skel_transmit(priv);
}
}
#endif
else
#endif
{
NETDEV_RXDROPPED(&priv->sk_dev);
}
+3 -3
View File
@@ -374,19 +374,19 @@
#define _LOOPIOCVALID(c) (_IOC_TYPE(c)==_LOOPBASE)
#define _LOOPIOC(nr) _IOC(_LOOPBASE,nr)
/* Modem driver ioctl definitions ********************************************/
/* Modem driver ioctl definitions *******************************************/
/* see nuttx/include/modem/ioctl.h */
#define _MODEMIOCVALID(c) (_IOC_TYPE(c)==_MODEMBASE)
#define _MODEMIOC(nr) _IOC(_MODEMBASE,nr)
/* I2C driver ioctl definitions **********************************************/
/* I2C driver ioctl definitions *********************************************/
/* see nuttx/include/i2c/i2c_master.h */
#define _I2CIOCVALID(c) (_IOC_TYPE(c)==_I2CBASE)
#define _I2CIOC(nr) _IOC(_I2CBASE,nr)
/* SPI driver ioctl definitions **********************************************/
/* SPI driver ioctl definitions *********************************************/
/* see nuttx/include/spi/spi_transfer.h */
#define _SPIIOCVALID(c) (_IOC_TYPE(c)==_SPIBASE)
+1 -1
View File
@@ -79,7 +79,7 @@ enum net_lltype_e
NET_LL_SLIP, /* Serial Line Internet Protocol (SLIP) */
NET_LL_TUN, /* TUN Virtual Network Device */
NET_LL_IEEE80211, /* IEEE 802.11 */
NET_LL_IEEE805154 /* IEEE 802.15.4 MAC */
NET_LL_IEEE802154 /* IEEE 802.15.4 MAC */
};
/* This defines a bitmap big enough for one bit for each socket option */
+210 -47
View File
@@ -97,7 +97,7 @@
*
* - Maximum Transfer Unit (MTU)
* - TCP Receive Window size (See TCP configuration options below)
*
*
* A better solution would be to support device-by-device MTU and receive
* window sizes. This minimum support is require to support the optimal
* SLIP MTU of 296 bytes and the standard Ethernet MTU of 1500
@@ -226,6 +226,12 @@
# define MIN_NET_DEV_MTU CONFIG_NET_6LOWPAN_MTU
# define MAX_NET_DEV_MTU CONFIG_NET_6LOWPAN_MTU
/* For the IEEE802.15.4 MAC device, we will use the packet MTU
* (which is probably much larger than the IEEE802.15.4 fram size)
*/
# define NET_LO_MTU MAX_NET_DEV_MTU
#else
/* Perhaps only Unix domain sockets or the loopback device */
@@ -289,47 +295,113 @@
#endif
/* The UDP maximum packet size. This is should not be to set to more
* than NET_DEV_MTU(d) - NET_LL_HDRLEN(dev) - IPv4UDP_HDRLEN.
* than NET_DEV_MTU(d) - NET_LL_HDRLEN(dev) - IPv*_HDRLEN.
*
* REVISIT: It is unclear to me if the UDP_HDRLEN should subtracted
* or not.
*/
#define UDP_MSS(d,h) (NET_DEV_MTU(d) - NET_LL_HDRLEN(d) - (h))
/* If Ethernet is supported, then it will have the smaller MSS */
#if defined(CONFIG_NET_SLIP)
# define SLIP_UDP_MSS(h) (CONFIG_NET_SLIP_MTU - (h))
# define __MIN_UDP_MSS(h) SLIP_UDP_MSS(h)
#elif defined(CONFIG_NET_LOOPBACK)
# define LO_UDP_MSS(h) (NET_LO_MTU - (h))
# define __MIN_UDP_MSS(h) LO_UDP_MSS(h)
#endif
#define UDP_MSS(d,h) (NET_DEV_MTU(d) - NET_LL_HDRLEN(d) (h))
#ifdef CONFIG_NET_ETHERNET
# define ETH_UDP_MSS(h) (CONFIG_NET_ETH_MTU - ETH_HDRLEN - (h))
# undef __MIN_UDP_MSS
# define __MIN_UDP_MSS(h) ETH_UDP_MSS(h)
# define __MAX_UDP_MSS(h) ETH_UDP_MSS(h)
# define ETH_UDP_MSS(h) (CONFIG_NET_ETH_MTU - ETH_HDRLEN - (h))
# ifndef CONFIG_NET_MULTILINK
# define __MIN_UDP_MSS(h) ETH_UDP_MSS(h)
# define __MAX_UDP_MSS(h) ETH_UDP_MSS(h)
# endif
#endif
/* If SLIP is supported, then it will have the larger MSS */
#ifdef CONFIG_NET_6LOWPAN
# define IEEE802154_UDP_MSS(h) (CONFIG_NET_6LOWPAN_MAXPAYLOAD - (h))
# ifndef CONFIG_NET_MULTILINK
# define __MIN_UDP_MSS(h) IEEE802154_UDP_MSS(h)
# define __MAX_UDP_MSS(h) IEEE802154_UDP_MSS(h)
# endif
#endif
#ifdef CONFIG_NET_LOOPBACK
# define LO_UDP_MSS(h) (NET_LO_MTU - (h))
# ifndef CONFIG_NET_MULTILINK
# define __MIN_UDP_MSS(h) LO_UDP_MSS(h)
# define __MAX_UDP_MSS(h) LO_UDP_MSS(h)
# endif
#endif
#ifdef CONFIG_NET_SLIP
# undef __MAX_UDP_MSS
# define __MAX_UDP_MSS(h) SLIP_UDP_MSS(h)
# define SLIP_UDP_MSS(h) (CONFIG_NET_SLIP_MTU - (h))
# ifndef CONFIG_NET_MULTILINK
# define __MIN_UDP_MSS(h) SLIP_UDP_MSS(h)
# define __MAX_UDP_MSS(h) SLIP_UDP_MSS(h)
# endif
#endif
/* If IPv4 is supported, it will have the larger MSS */
#ifdef CONFIG_NET_MULTILINK
# undef __LAST_MIN_UDP_MSS
# undef __LAST_MAX_UDP_MSS
#ifdef CONFIG_NET_IPv6
# define UDP_IPv6_MSS(d) UDP_MSS(d,IPv6_HDRLEN)
# define ETH_IPv6_UDP_MSS ETH_UDP_MSS(IPv6_HDRLEN)
# define SLIP_IPv6_UDP_MSS SLIP_UDP_MSS(IPv6_HDRLEN)
# ifdef CONFIG_NET_ETHERNET
# ifdef __LAST_MIN_UDP_MSS
# define __MIN_UDP_MSS(h) MIN(ETH_UDP_MSS(h),__LAST_MIN_UDP_MSS(h))
# define __MAX_UDP_MSS(h) MAX(ETH_UDP_MSS(h),__LAST_MAX_UDP_MSS(h))
# else
# define __MIN_UDP_MSS(h) ETH_UDP_MSS(h)
# define __MAX_UDP_MSS(h) ETH_UDP_MSS(h)
# endif
# undef __LAST_MIN_UDP_MSS
# undef __LAST_MAX_UDP_MSS
# define __LAST_MIN_UDP_MSS(h) __MIN_UDP_MSS(h)
# define __LAST_MAX_UDP_MSS(h) __MAX_UDP_MSS(h)
# endif
# define MAX_IPv6_UDP_MSS __MAX_UDP_MSS(IPv6_HDRLEN)
# define MAX_UDP_MSS __MAX_UDP_MSS(IPv6_HDRLEN)
# ifdef CONFIG_NET_6LOWPAN
# ifdef __LAST_MIN_UDP_MSS
# define __MIN_UDP_MSS(h) MIN(IEEE802154_UDP_MSS(h),__LAST_MIN_UDP_MSS(h))
# define __MAX_UDP_MSS(h) MAX(IEEE802154_UDP_MSS(h),__LAST_MAX_UDP_MSS(h))
# else
# define __MIN_UDP_MSS(h) IEEE802154_UDP_MSS(h)
# define __MAX_UDP_MSS(h) IEEE802154_UDP_MSS(h)
# endif
# undef __LAST_MIN_UDP_MSS
# undef __LAST_MAX_UDP_MSS
# define __LAST_MIN_UDP_MSS(h) __MIN_UDP_MSS(h)
# define __LAST_MAX_UDP_MSS(h) __MAX_UDP_MSS(h)
# endif
# ifdef CONFIG_NET_LOOPBACK
# ifdef __LAST_MIN_UDP_MSS
# define __MIN_UDP_MSS(h) MIN(LO_UDP_MSS(h),__LAST_MIN_UDP_MSS(h))
# define __MAX_UDP_MSS(h) MAX(LO_UDP_MSS(h),__LAST_MAX_UDP_MSS(h))
# else
# define __MIN_UDP_MSS(h) LO_UDP_MSS(h)
# define __MAX_UDP_MSS(h) LO_UDP_MSS(h)
# endif
# undef __LAST_MIN_UDP_MSS
# undef __LAST_MAX_UDP_MSS
# define __LAST_MIN_UDP_MSS(h) __MIN_UDP_MSS(h)
# define __LAST_MAX_UDP_MSS(h) __MAX_UDP_MSS(h)
# endif
# ifdef CONFIG_NET_SLIP
# ifdef __LAST_MIN_UDP_MSS
# define __MIN_UDP_MSS(h) MIN(SLIP_UDP_MSS(h),__LAST_MIN_UDP_MSS(h))
# define __MAX_UDP_MSS(h) MAX(SLIP_UDP_MSS(h),__LAST_MAX_UDP_MSS(h))
# else
# define __MIN_UDP_MSS(h) SLIP_UDP_MSS(h)
# define __MAX_UDP_MSS(h) SLIP_UDP_MSS(h)
# endif
# undef __LAST_MIN_UDP_MSS
# undef __LAST_MAX_UDP_MSS
# define __LAST_MIN_UDP_MSS(h) __MIN_UDP_MSS(h)
# define __LAST_MAX_UDP_MSS(h) __MAX_UDP_MSS(h)
# endif
# undef __LAST_MIN_UDP_MSS
# undef __LAST_MAX_UDP_MSS
#endif
#ifdef CONFIG_NET_IPv4
/* NOTE: MSS calcuation excludes the UDP_HDRLEN. */
#ifdef CONFIG_NET_IPv4
# define UDP_IPv4_MSS(d) UDP_MSS(d,IPv4_HDRLEN)
# define ETH_IPv4_UDP_MSS ETH_UDP_MSS(IPv4_HDRLEN)
# define SLIP_IPv4_UDP_MSS SLIP_UDP_MSS(IPv4_HDRLEN)
@@ -416,36 +488,115 @@
* link layer protocols (CONFIG_NET_MULTILINK), each network device
* may support a different UDP MSS value. Here we arbitrarily select
* the minimum MSS for that case.
*
* REVISIT: It is unclear to me if the TCP_HDRLEN should subtracted
* or not.
*/
#define TCP_MSS(d,h) (NET_DEV_MTU(d) - NET_LL_HDRLEN(d) - TCP_HDRLEN - (h))
#define LO_TCP_MSS(h) (NET_LO_MTU - (h))
#define TCP_MSS(d,h) (NET_DEV_MTU(d) - NET_LL_HDRLEN(d) - (h))
#define LO_TCP_MSS(h) (NET_LO_MTU - (h))
/* If Ethernet is supported, then it will have the smaller MSS */
#if defined(CONFIG_NET_SLIP)
# define SLIP_TCP_MSS(h) (CONFIG_NET_SLIP_MTU - (h))
# define __MIN_TCP_MSS(h) SLIP_TCP_MSS(h)
#elif defined(CONFIG_NET_LOOPBACK)
# define LO_TCP_MSS(h) (NET_LO_MTU - (h))
# define __MIN_TCP_MSS(h) LO_TCP_MSS(h)
#endif
/* Get the smallest and largest MSS */
#ifdef CONFIG_NET_ETHERNET
# define ETH_TCP_MSS(h) (CONFIG_NET_ETH_MTU - ETH_HDRLEN - (h))
# undef __MIN_TCP_MSS
# define __MIN_TCP_MSS(h) ETH_TCP_MSS(h)
# define __MAX_TCP_MSS(h) ETH_TCP_MSS(h)
# define ETH_TCP_MSS(h) (CONFIG_NET_ETH_MTU - ETH_HDRLEN - (h))
# ifndef CONFIG_NET_MULTILINK
# define __MIN_TCP_MSS(h) ETH_TCP_MSS(h)
# define __MAX_TCP_MSS(h) ETH_TCP_MSS(h)
# endif
#endif
/* If SLIP is supported, then it will have the larger MSS */
#ifdef CONFIG_NET_6LOWPAN
# define IEEE802154_TCP_MSS(h) CONFIG_NET_6LOWPAN_MAXPAYLOAD
# ifndef CONFIG_NET_MULTILINK
# define __MIN_TCP_MSS(h) IEEE802154_TCP_MSS(h)
# define __MAX_TCP_MSS(h) IEEE802154_TCP_MSS(h)
# endif
#endif
#ifdef CONFIG_NET_LOOPBACK
# define LO_TCP_MSS(h) (NET_LO_MTU - (h))
# ifndef CONFIG_NET_MULTILINK
# define __MIN_TCP_MSS(h) LO_TCP_MSS(h)
# define __MAX_TCP_MSS(h) LO_TCP_MSS(h)
# endif
#endif
#ifdef CONFIG_NET_SLIP
# undef __MAX_TCP_MSS
# define __MAX_TCP_MSS(h) SLIP_TCP_MSS(h)
# define SLIP_TCP_MSS(h) (CONFIG_NET_SLIP_MTU - (h))
# ifndef CONFIG_NET_MULTILINK
# define __MIN_TCP_MSS(h) SLIP_TCP_MSS(h)
# define __MAX_TCP_MSS(h) SLIP_TCP_MSS(h)
# endif
#endif
/* If IPv4 is support, it will have the larger MSS */
#ifdef CONFIG_NET_MULTILINK
# undef __LAST_MIN_TCP_MSS
# undef __LAST_MAX_TCP_MSS
# ifdef CONFIG_NET_ETHERNET
# ifdef __LAST_MIN_TCP_MSS
# define __MIN_TCP_MSS(h) MIN(ETH_TCP_MSS(h),__LAST_MIN_TCP_MSS(h))
# define __MAX_TCP_MSS(h) MAX(ETH_TCP_MSS(h),__LAST_MAX_TCP_MSS(h))
# else
# define __MIN_TCP_MSS(h) ETH_TCP_MSS(h)
# define __MAX_TCP_MSS(h) ETH_TCP_MSS(h)
# endif
# undef __LAST_MIN_TCP_MSS
# undef __LAST_MAX_TCP_MSS
# define __LAST_MIN_TCP_MSS(h) __MIN_TCP_MSS(h)
# define __LAST_MAX_TCP_MSS(h) __MAX_TCP_MSS(h)
# endif
# ifdef CONFIG_NET_6LOWPAN
# ifdef __LAST_MIN_TCP_MSS
# define __MIN_TCP_MSS(h) MIN(IEEE802154_TCP_MSS(h),__LAST_MIN_TCP_MSS(h))
# define __MAX_TCP_MSS(h) MAX(IEEE802154_TCP_MSS(h),__LAST_MAX_TCP_MSS(h))
# else
# define __MIN_TCP_MSS(h) IEEE802154_TCP_MSS(h)
# define __MAX_TCP_MSS(h) IEEE802154_TCP_MSS(h)
# endif
# undef __LAST_MIN_TCP_MSS
# undef __LAST_MAX_TCP_MSS
# define __LAST_MIN_TCP_MSS(h) __MIN_TCP_MSS(h)
# define __LAST_MAX_TCP_MSS(h) __MAX_TCP_MSS(h)
# endif
# ifdef CONFIG_NET_LOOPBACK
# ifdef __LAST_MIN_TCP_MSS
# define __MIN_TCP_MSS(h) MIN(LO_TCP_MSS(h),__LAST_MIN_TCP_MSS(h))
# define __MAX_TCP_MSS(h) MAX(LO_TCP_MSS(h),__LAST_MAX_TCP_MSS(h))
# else
# define __MIN_TCP_MSS(h) LO_TCP_MSS(h)
# define __MAX_TCP_MSS(h) LO_TCP_MSS(h)
# endif
# undef __LAST_MIN_TCP_MSS
# undef __LAST_MAX_TCP_MSS
# define __LAST_MIN_TCP_MSS(h) __MIN_TCP_MSS(h)
# define __LAST_MAX_TCP_MSS(h) __MAX_TCP_MSS(h)
# endif
# ifdef CONFIG_NET_SLIP
# ifdef __LAST_MIN_TCP_MSS
# define __MIN_TCP_MSS(h) MIN(SLIP_TCP_MSS(h),__LAST_MIN_TCP_MSS(h))
# define __MAX_TCP_MSS(h) MAX(SLIP_TCP_MSS(h),__LAST_MAX_TCP_MSS(h))
# else
# define __MIN_TCP_MSS(h) SLIP_TCP_MSS(h)
# define __MAX_TCP_MSS(h) SLIP_TCP_MSS(h)
# endif
# undef __LAST_MIN_TCP_MSS
# undef __LAST_MAX_TCP_MSS
# define __LAST_MIN_TCP_MSS(h) __MIN_TCP_MSS(h)
# define __LAST_MAX_TCP_MSS(h) __MAX_TCP_MSS(h)
# endif
# undef __LAST_MIN_TCP_MSS
# undef __LAST_MAX_TCP_MSS
#endif
/* If IPv4 is supported, it will have the larger MSS.
* NOTE: MSS calcuation excludes the TCP_HDRLEN.
*/
#ifdef CONFIG_NET_IPv6
# define TCP_IPv6_MSS(d) TCP_MSS(d,IPv6_HDRLEN)
@@ -547,6 +698,18 @@
# define CONFIG_NET_ARP_MAXAGE 120
#endif
/* Usrsock configuration options */
/* The maximum amount of concurrent usrsock connections, Default: 6 */
#ifndef CONFIG_NET_USRSOCK_CONNS
# ifdef CONFIG_NET_USRSOCK
# define CONFIG_NET_USRSOCK_CONNS 6
# else
# define CONFIG_NET_USRSOCK_CONNS 0
# endif
#endif
/* General configuration options */
/* Delay after receive to catch a following packet. No delay should be
+2 -1
View File
@@ -419,7 +419,8 @@ int ipv6_input(FAR struct net_driver_s *dev);
#endif
#ifdef CONFIG_NET_6LOWPAN
int sixlowpan_input(FAR struct net_driver_s *dev);
struct ieee802154_driver_s; /* See sixlowpan.h */
int sixlowpan_input(FAR struct ieee802154_driver_s *ieee);
#endif
/****************************************************************************
+173 -167
View File
@@ -53,6 +53,7 @@
#include <stdint.h>
#include <nuttx/net/iob.h>
#include <nuttx/net/netdev.h>
/****************************************************************************
@@ -98,7 +99,6 @@
#define SIXLOWPAN_IPHC_TTL_255 0x03
#define SIXLOWPAN_IPHC_TTL_I 0x00
/* Values of fields within the IPHC encoding second byte */
#define SIXLOWPAN_IPHC_CID 0x80
@@ -232,62 +232,61 @@
#define SIXLOWPAN_MAC_STDFRAME 127
/* Packet buffer Definitions */
/* Frame buffer helper macros.
*
* The IEEE802.15.4 MAC driver structures includes a list of IOB
* structures, i_framelist, containing frames to be sent by the driver or
* that were received by the driver. The IOB structure is defined in
* include/nuttx/net/iob.h. The length of data in the IOB is provided by
* the io_len field of the IOB structure.
*
* NOTE that IOBs must be configured such that CONFIG_IOB_BUFSIZE >=
* CONFIG_NET_6LOWPAN_FRAMELEN
*
* 1. On a TX poll, the IEEE802.15.4 MAC driver should provide its driver
* structure with i_framelist set to NULL. At the conclusion of the
* poll, if there are frames to be sent, they will have been added to
* the i_framelist. The non-empty frame list is the indication that
* there is data to be sent.
*
* The IEEE802.15.4 may use the FRAME_IOB_EMPTY() macro to determine
* if there there frames to be sent. If so, it should remove each
* frame from the frame list using the FRAME_IOB_REMOVE() macro and send
* it. That macro will return NULL when all of the frames have been
* sent.
*
* After sending each frame, the driver must return the IOB to the pool
* of free IOBs using the FROM_IOB_FREE() macro.
*/
#define PACKETBUF_HDR_SIZE 48
#define PACKETBUF_ATTR_PACKET_TYPE_DATA 0
#define PACKETBUF_ATTR_PACKET_TYPE_ACK 1
#define PACKETBUF_ATTR_PACKET_TYPE_STREAM 2
#define PACKETBUF_ATTR_PACKET_TYPE_STREAM_END 3
#define PACKETBUF_ATTR_PACKET_TYPE_TIMESTAMP 4
#define FRAME_IOB_EMPTY(ieee) ((ieee)->i_framelist == NULL)
#define FRAME_IOB_REMOVE(ieee, iob) \
do \
{ \
(iob) = (ieee)->i_framelist; \
(ieee)->i_framelist = (iob)->io_flink; \
(iob)->io_flink = NULL; \
} \
while (0)
#define FRAME_IOB_FREE(iob) iob_free(iob)
/* Packet buffer attributes (indices into i_pktattr) */
/* 2. When receiving data, the IEEE802.15.4 MAC driver should receive the
* frame data directly into the payload area of an IOB structure. That
* IOB structure may be obtained using the FRAME_IOB_ALLOC() macro. The
* single frame should be added to the frame list using FRAME_IOB_ADD()
* (it will be a list of length one) . The MAC driver should then inform
* the network of the by calling sixlowpan_input().
*/
#define PACKETBUF_ATTR_NONE 0
/* Scope 0 attributes: used only on the local node. */
#define PACKETBUF_ATTR_CHANNEL 1
#define PACKETBUF_ATTR_NETWORK_ID 2
#define PACKETBUF_ATTR_LINK_QUALITY 3
#define PACKETBUF_ATTR_RSSI 4
#define PACKETBUF_ATTR_TIMESTAMP 5
#define PACKETBUF_ATTR_RADIO_TXPOWER 6
#define PACKETBUF_ATTR_LISTEN_TIME 7
#define PACKETBUF_ATTR_TRANSMIT_TIME 8
#define PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS 9
#define PACKETBUF_ATTR_MAC_SEQNO 10
#define PACKETBUF_ATTR_MAC_ACK 11
/* Scope 1 attributes: used between two neighbors only. */
#define PACKETBUF_ATTR_RELIABLE 12
#define PACKETBUF_ATTR_PACKET_ID 13
#define PACKETBUF_ATTR_PACKET_TYPE 14
#define PACKETBUF_ATTR_REXMIT 15
#define PACKETBUF_ATTR_MAX_REXMIT 16
#define PACKETBUF_ATTR_NUM_REXMIT 17
#define PACKETBUF_ATTR_PENDING 18
/* Scope 2 attributes: used between end-to-end nodes. */
#define PACKETBUF_ATTR_HOPS 11
#define PACKETBUF_ATTR_TTL 20
#define PACKETBUF_ATTR_EPACKET_ID 21
#define PACKETBUF_ATTR_EPACKET_TYPE 22
#define PACKETBUF_ATTR_ERELIABLE 23
#define PACKETBUF_NUM_ATTRS 24
/* Addresses (indices into i_pktaddr) */
#define PACKETBUF_ADDR_SENDER 0
#define PACKETBUF_ADDR_RECEIVER 1
#define PACKETBUF_ADDR_ESENDER 2
#define PACKETBUF_ADDR_ERECEIVER 3
#define PACKETBUF_NUM_ADDRS 4
#define FRAME_IOB_ALLOC() iob_alloc(false)
#define FRAME_IOB_ADD(ieee, iob) \
do \
{ \
(iob)->io_flink = (ieee)->i_framelist; \
(ieee)->i_framelist = (iob); \
} \
while (0)
/****************************************************************************
* Public Types
@@ -305,18 +304,20 @@ struct rimeaddr_s
* difference is that fragmentation must be supported.
*
* The IEEE802.15.4 MAC does not use the d_buf packet buffer directly.
* Rather, it uses a smaller frame buffer, i_frame.
* Rather, it uses a list smaller frame buffers, i_framelist.
*
* - The packet fragment data is provided to the i_frame buffer each time
* that the IEEE802.15.4 MAC needs to send more data. The length of
* the frame is provided in i_frame.
* - The packet fragment data is provided to an IOB in the i_framelist
* buffer each time that the IEEE802.15.4 MAC needs to send more data.
* The length of the frame is provided in the io_len field of the IOB.
*
* In this case, the d_buf holds the packet data yet to be sent; d_len
* holds the size of entire packet.
* In this case, the d_buf is not used at all and, if fact, may be
* NULL.
*
* - Received frames are provided by IEEE802.15.4 MAC to the network
* via i_frame with length i_framelen for reassembly in d_buf; d_len
* will hold the size of the reassembled packet.
* via and IOB in i_framelist with length io_len for reassembly in
* d_buf; d_len will hold the size of the reassembled packet.
*
* In this case, a d_buf of size CONFIG_NET_6LOWPAN_MTU must be provided.
*
* This is accomplished by "inheriting" the standard 'struct net_driver_s'
* and appending the frame buffer as well as other metadata needed to
@@ -328,36 +329,51 @@ struct rimeaddr_s
* this structure. In general, all fields must be set to NULL. In
* addtion:
*
* 1) i_panid must be set to identify the network. It may be set to 0xfff
* 1. i_panid must be set to identify the network. It may be set to 0xfff
* if the device is not associated.
* 2) i_dsn must be set to a random value. After that, it will be managed
*
* 2. i_dsn must be set to a random value. After that, it will be managed
* by the network.
* 3) i_nodeaddr must be set after the MAC is assigned an address.
* 4) On network TX poll operations, the IEEE802.15.4 MAC needs to provide
* the i_frame buffer with size greater than or equal to
* CONFIG_NET_6LOWPAN_FRAMELEN. No dev.d_buf need be provided in this
* case. The entire is TX is performed using only the i_frame buffer.
* 5) On network input RX oprations, both buffers must be provided. The size
* of the i_frame buffer is, again, greater than or equal to
* CONFIG_NET_6LOWPAN_FRAMELEN. The larger dev.d_buf must have a size
* of at least the advertised MTU of the protocol, CONFIG_NET_6LOWPAN_MTU.
* If fragmentation is enabled, then the logical packet size may be
* significantly larger than the size of the frame buffer. The dev.d_buf
* is used for de-compressing each frame and reassembling any fragmented
* packets to create the full input packet that is provided to the
* application.
*
* Frame Organization:
* 3. i_nodeaddr must be set after the MAC is assigned an address.
*
* Content Offset
* +------------------+ 0
* | Frame Header |
* +------------------+ i_dataoffset
* | Procotol Headers |
* | Data Payload |
* +------------------+ i_framelen
* | Unused |
* +------------------+ CONFIG_NET_6LOWPAN_FRAMELEN
* 4. On a TX poll, the IEEE802.15.4 MAC driver should provide its driver
* structure with i_framelist set to NULL. At the conclusion of the
* poll, if there are frames to be sent, they will have been added to
* the i_framelist. The non-empty frame list at the conclusion of the
* TX poll is the indication that is data to be sent.
*
* The IEEE802.15.4 may use the FRAME_IOB_EMPTY() macro to determine
* if there there frames to be sent. If so, it should remove each
* frame from the frame list using the FRAME_IOB_REMOVE() macro and send
* it. That macro will return NULL when all of the frames have been
* sent.
*
* After sending each frame, the driver must return the IOB to the pool
* of free IOBs using the FROM_IOB_FREE() macro.
*
* 5. When receiving data both buffers must be provided:
*
* The IEEE802.15.4 MAC driver should receive the frame data directly
* into the payload area of an IOB structure. That IOB structure may be
* obtained using the FRAME_IOB_ALLOC() macro. The single frame should
* be added to the frame list using FRAME_IOB_ADD() (it will be a list of
* length one).
*
* The larger dev.d_buf must have a size of at least the advertised MTU
* of the protocol, CONFIG_NET_6LOWPAN_MTU. If fragmentation is enabled,
* then the logical packet size may be significantly larger than the
* size of the frame buffer. The dev.d_buf is used for de-compressing
* each frame and reassembling any fragmented packets to create the full
* input packet that is provided to the application.
*
* The MAC driver should then inform the network of the by calling
* sixlowpan_input().
*
* Normally, the network will free the IOB and will nullify the frame
* list. But ss a complexity, the result of receiving a frame may be
* that the network may respond provide an outgoing frames in the
* frame list.
*/
struct ieee802154_driver_s
@@ -370,31 +386,21 @@ struct ieee802154_driver_s
/* IEEE802.15.4 MAC-specific definitions follow. */
/* The i_frame array is used to hold outgoing frame. When the
* IEEE802.15.4 device polls for new data, the outgoing frame containing
* the next fragment is placed in i_frame.
/* The i_framelist is used to hold a outgoing frames contained in IOB
* structures. When the IEEE802.15.4 device polls for new TX data, the
* outgoing frame(s) containing the packet fragments are placed in IOBs
* and queued in i_framelist.
*
* The network will handle only a single outgong frame at a time. The
* IEEE802.15.4 MAC driver design may be concurrently sending and
* requesting new framesusing break-off fram buffers. That frame buffer
* management must be controlled by the IEEE802.15.4 MAC driver.
* The i_framelist is similary used to hold incoming frames in IOB
* structures. The IEEE802.15.4 MAC driver must receive frames in an IOB,
* place the IOB in the i_framelist, and call sixlowpan_input().
*
* Driver provided frame buffers should of size CONFIG_NET_6LOWPAN_FRAMELEN
* and should be 16-bit aligned.
* The IEEE802.15.4 MAC driver design may be concurrently sending and
* requesting new frames using lists of IOBs. That IOB frame buffer
* management must be managed by the IEEE802.15.4 MAC driver.
*/
FAR uint8_t *i_frame;
/* The length of valid data in the i_frame buffer.
*
* When the network device driver calls the network input function,
* i_framelen should be set to zero. If there is frame to be sent
* by the network, i_framelen will be set to indicate the size of
* frame to be sent. The value zero means that there is no frame
* to be sent.
*/
uint16_t i_framelen;
FAR struct iob_s *i_framelist;
/* i_panid. The PAN ID is 16-bit number that identifies the network. It
* must be unique to differentiate a network. All the nodes in the same
@@ -421,39 +427,12 @@ struct ieee802154_driver_s
uint8_t i_dsn;
/* The following fields are device-specific metadata used by the 6loWPAN
* stack and should not be modified by the IEEE802.15.4 MAC network drvier.
/* i_dgramtag. Datagram tag to be put in the header of the set of
* fragments. It is used by the recipient to match fragments of the
* same payload.
*/
/* A pointer to the rime buffer.
*
* We initialize it to the beginning of the rime buffer, then access
* different fields by updating the offset ieee->i_rime_hdrlen.
*/
FAR uint8_t *i_rimeptr;
/* i_uncomp_hdrlen is the length of the headers before compression (if HC2
* is used this includes the UDP header in addition to the IP header).
*/
uint8_t i_uncomp_hdrlen;
/* i_rime_hdrlen is the total length of (the processed) 6lowpan headers
* (fragment headers, IPV6 or HC1, HC2, and HC1 and HC2 non compressed
* fields).
*/
uint8_t i_rime_hdrlen;
/* Offset first available byte for the payload after header region. */
uint8_t i_dataoffset;
/* Packet buffer metadata: Attributes and addresses */
uint16_t i_pktattrs[PACKETBUF_NUM_ATTRS];
struct rimeaddr_s i_pktaddrs[PACKETBUF_NUM_ADDRS];
uint16_t i_dgramtag;
};
/* The structure of a next header compressor. This compressor is provided
@@ -480,18 +459,65 @@ struct sixlowpan_nhcompressor_s
FAR uint8_t *uncompressed_len);
};
/* RIME sniffer callbacks */
struct sixlowpan_rime_sniffer_s
{
CODE void (*input)(void);
CODE void (*output)(int mac_status);
};
/****************************************************************************
* Public Function Prototypes
****************************************************************************/
/****************************************************************************
* Name: sixlowpan_input
*
* Description:
* Process an incoming 6loWPAN frame.
*
* This function is called when the device driver has received a 6loWPAN
* frame from the network. The frame from the device driver must be
* provided in a IOB present in the i_framelist: The frame data is in the
* IOB io_data[] buffer and the length of the frame is in the IOB io_len
* field. Only a single IOB is expected in the i_framelist. This incoming
* data will be processed one frame at a time.
*
* An non-NULL d_buf of size CONFIG_NET_6LOWPAN_MTU must also be provided.
* The frame will be decompressed and placed in the d_buf. Fragmented
* packets will also be reassembled in the d_buf as they are received
* (meaning for the driver, that two packet buffers are required: One for
* reassembly of RX packets and one used for TX polling).
*
* After each frame is processed into d_buf, the IOB is removed and
* deallocated. i_framelist will be nullified. If reassembly is
* incomplete, this function will return to called with i_framelist
* equal to NULL. The partially reassembled packet must be preserved by
* the IEEE802.15.4 MAC and provided again when the next frame is
* received.
*
* When the packet in the d_buf is fully reassembled, it will be provided
* to the network as with any other received packet. d_len will be set
* the the length of the uncompressed, reassembled packet.
*
* After the network processes the packet, d_len will be set to zero.
* Network logic may also decide to send a response to the packet. In
* that case, the outgoing network packet will be placed in d_buf the
* d_buf and d_len will be set to a non-zero value. That case is handled
* by this function.
*
* If that case occurs, the packet will be converted to a list of
* compressed and possibly fragmented frames in i_framelist as with other
* TX operations.
*
* So from the standpoint of the IEEE802.15.4 MAC driver, there are two
* possible results: (1) i_framelist is NULL meaning that the frame
* was fully processed and freed, or (2) i_framelist is non-NULL meaning
* that there are outgoing frame(s) to be sent.
*
* Input Parameters:
* ieee - The IEEE802.15.4 MAC network driver interface.
*
* Returned Value:
* Ok is returned on success; Othewise a negated errno value is returned.
*
****************************************************************************/
int sixlowpan_input(FAR struct ieee802154_driver_s *ieee);
/****************************************************************************
* Function: sixlowpan_set_compressor
*
@@ -509,24 +535,4 @@ struct sixlowpan_rime_sniffer_s
void sixlowpan_set_compressor(FAR struct sixlowpan_nhcompressor_s *compressor);
/****************************************************************************
* Function: sixlowpan_set_sniffer
*
* Description:
* Configure to use an architecture-specific sniffer to enable tracing of
* IP.
*
* Input parameters:
* sniffer - A reference to the new sniffer to be used. This may
* be a NULL value to disable the sniffer.
*
* Returned Value:
* None
*
****************************************************************************/
#ifdef CONFIG_NET_6LOWPAN_SNIFFER
void sixlowpan_set_sniffer(FAR struct sixlowpan_rime_sniffer_s *sniffer);
#endif
#endif /* __INCLUDE_NUTTX_NET_SIXLOWOAN_H */
+233
View File
@@ -0,0 +1,233 @@
/****************************************************************************
* include/nuttx/net/usrsock.h
*
* Copyright (C) 2015, 2017 Haltian Ltd. All rights reserved.
* Author: Jussi Kivilinna <jussi.kivilinna@haltian.com>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*
****************************************************************************/
#ifndef __INCLUDE_NUTTX_NET_USRSOCK_H
#define __INCLUDE_NUTTX_NET_USRSOCK_H
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <stdbool.h>
#include <nuttx/net/netconfig.h>
#include <nuttx/compiler.h>
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Event message flags */
#define USRSOCK_EVENT_ABORT (1 << 0)
#define USRSOCK_EVENT_SENDTO_READY (1 << 1)
#define USRSOCK_EVENT_RECVFROM_AVAIL (1 << 2)
#define USRSOCK_EVENT_REMOTE_CLOSED (1 << 3)
/* Response message flags */
#define USRSOCK_MESSAGE_FLAG_REQ_IN_PROGRESS (1 << 0)
#define USRSOCK_MESSAGE_FLAG_EVENT (1 << 1)
#define USRSOCK_MESSAGE_IS_EVENT(flags) \
(!!((flags) & USRSOCK_MESSAGE_FLAG_EVENT))
#define USRSOCK_MESSAGE_IS_REQ_RESPONSE(flags) \
(!USRSOCK_MESSAGE_IS_EVENT(flags))
#define USRSOCK_MESSAGE_REQ_IN_PROGRESS(flags) \
(!!((flags) & USRSOCK_MESSAGE_FLAG_REQ_IN_PROGRESS))
#define USRSOCK_MESSAGE_REQ_COMPLETED(flags) \
(!USRSOCK_MESSAGE_REQ_IN_PROGRESS(flags))
/****************************************************************************
* Public Types
****************************************************************************/
/* Request types */
enum usrsock_request_types_e
{
USRSOCK_REQUEST_SOCKET = 0,
USRSOCK_REQUEST_CLOSE,
USRSOCK_REQUEST_CONNECT,
USRSOCK_REQUEST_SENDTO,
USRSOCK_REQUEST_RECVFROM,
USRSOCK_REQUEST_SETSOCKOPT,
USRSOCK_REQUEST_GETSOCKOPT,
USRSOCK_REQUEST_GETSOCKNAME,
USRSOCK_REQUEST_BIND,
USRSOCK_REQUEST__MAX
};
/* Response/event message types */
enum usrsock_message_types_e
{
USRSOCK_MESSAGE_RESPONSE_ACK = 0,
USRSOCK_MESSAGE_RESPONSE_DATA_ACK,
USRSOCK_MESSAGE_SOCKET_EVENT,
};
/* Request structures (kernel => /dev/usrsock => daemon) */
begin_packed_struct struct usrsock_request_common_s
{
int8_t reqid;
uint8_t xid;
} end_packed_struct;
begin_packed_struct struct usrsock_request_socket_s
{
struct usrsock_request_common_s head;
int16_t domain;
int16_t type;
int16_t protocol;
} end_packed_struct;
begin_packed_struct struct usrsock_request_close_s
{
struct usrsock_request_common_s head;
int16_t usockid;
} end_packed_struct;
begin_packed_struct struct usrsock_request_bind_s
{
struct usrsock_request_common_s head;
int16_t usockid;
uint16_t addrlen;
} end_packed_struct;
begin_packed_struct struct usrsock_request_connect_s
{
struct usrsock_request_common_s head;
int16_t usockid;
uint16_t addrlen;
} end_packed_struct;
begin_packed_struct struct usrsock_request_sendto_s
{
struct usrsock_request_common_s head;
int16_t usockid;
uint16_t addrlen;
uint16_t buflen;
} end_packed_struct;
begin_packed_struct struct usrsock_request_recvfrom_s
{
struct usrsock_request_common_s head;
int16_t usockid;
uint16_t max_buflen;
uint16_t max_addrlen;
} end_packed_struct;
begin_packed_struct struct usrsock_request_setsockopt_s
{
struct usrsock_request_common_s head;
int16_t usockid;
int16_t level;
int16_t option;
uint16_t valuelen;
} end_packed_struct;
begin_packed_struct struct usrsock_request_getsockopt_s
{
struct usrsock_request_common_s head;
int16_t usockid;
int16_t level;
int16_t option;
uint16_t max_valuelen;
} end_packed_struct;
begin_packed_struct struct usrsock_request_getsockname_s
{
struct usrsock_request_common_s head;
int16_t usockid;
uint16_t max_addrlen;
} end_packed_struct;
/* Response/event message structures (kernel <= /dev/usrsock <= daemon) */
begin_packed_struct struct usrsock_message_common_s
{
int8_t msgid;
int8_t flags;
} end_packed_struct;
/* Request acknowledgment/completion message */
begin_packed_struct struct usrsock_message_req_ack_s
{
struct usrsock_message_common_s head;
uint8_t xid;
int32_t result;
} end_packed_struct;
/* Request acknowledgment/completion message */
begin_packed_struct struct usrsock_message_datareq_ack_s
{
struct usrsock_message_req_ack_s reqack;
/* head.result => positive buflen, negative error-code. */
uint16_t valuelen; /* length of value returned after buffer */
uint16_t valuelen_nontrunc; /* actual non-truncated length of value at
* daemon-sïde. */
} end_packed_struct;
/* Socket event message */
begin_packed_struct struct usrsock_message_socket_event_s
{
struct usrsock_message_common_s head;
int16_t usockid;
uint16_t events;
} end_packed_struct;
#endif /* __INCLUDE_NUTTX_NET_USRSOCK_H */
+37 -10
View File
@@ -123,28 +123,37 @@ config NET_USER_DEVFMT
config NET_ETHERNET
bool "Ethernet support"
default y if !NET_SLIP
default n if NET_SLIP
select NETDEV_MULTINIC if NET_LOOPBACK || NET_SLIP || NET_TUN
select NET_MULTILINK if NET_LOOPBACK || NET_SLIP || NET_TUN
default y
select NETDEV_MULTINIC if NET_6LOWPAN || NET_LOOPBACK || NET_SLIP || NET_TUN
select NET_MULTILINK if NET_6LOWPAN || NET_LOOPBACK || NET_SLIP || NET_TUN
---help---
If NET_SLIP is not selected, then Ethernet will be used (there is
no need to define anything special in the configuration file to use
Ethernet -- it is the default).
menuconfig NET_6LOWPAN
bool "IEEE 802.15.4 6LoWPAN support"
default n
select NETDEV_MULTINIC if NET_ETHERNET || NET_LOOPBACK || NET_SLIP || NET_TUN
select NET_MULTILINK if NET_ETHERNET || NET_LOOPBACK || NET_SLIP || NET_TUN
depends on EXPERIMENTAL && NET_IPv6
---help---
Enable support for IEEE 802.15.4 Low power Wireless Personal Area
Networking (6LoWPAN).
config NET_LOOPBACK
bool "Local loopback"
default n
select NETDEV_MULTINIC if NET_ETHERNET || NET_SLIP || NET_TUN
select NET_MULTILINK if NET_ETHERNET || NET_SLIP || NET_TUN
select NETDEV_MULTINIC if NET_ETHERNET || NET_6LOWPAN || NET_SLIP || NET_TUN
select NET_MULTILINK if NET_ETHERNET || NET_6LOWPAN || NET_SLIP || NET_TUN
---help---
Add support for the local network loopback device, lo.
config NET_SLIP
bool "SLIP support"
default n
select NETDEV_MULTINIC if NET_ETHERNET || NET_LOOPBACK || NET_TUN
select NET_MULTILINK if NET_ETHERNET || NET_LOOPBACK || NET_TUN
select NETDEV_MULTINIC if NET_ETHERNET || NET_6LOWPAN || NET_LOOPBACK || NET_TUN
select NET_MULTILINK if NET_ETHERNET || NET_6LOWPAN || NET_LOOPBACK || NET_TUN
---help---
Enables building of the SLIP driver. SLIP requires
at least one IP protocol selected.
@@ -190,8 +199,8 @@ endif # NET_SLIP
config NET_TUN
bool "TUN Virtual Network Device support"
default n
select NETDEV_MULTINIC if NET_ETHERNET || NET_LOOPBACK || NET_SLIP
select NET_MULTILINK if NET_ETHERNET || NET_LOOPBACK || NET_SLIP
select NETDEV_MULTINIC if NET_ETHERNET || NET_6LOWPAN || NET_LOOPBACK || NET_SLIP
select NET_MULTILINK if NET_ETHERNET || NET_6LOWPAN || NET_LOOPBACK || NET_SLIP
select ARCH_HAVE_NETDEV_STATISTICS
if NET_TUN
@@ -236,6 +245,23 @@ config TUN_LPWORK
endchoice # Work queue
endif # NET_TUN
config NET_USRSOCK
bool "User-space networking stack API"
default n
---help---
Enable or disable user-space networking stack support.
User-space networking stack API allows user-space daemon to
provide TCP/IP stack implementation for NuttX network.
Main use for this is to allow use and integration of
HW-provided TCP/IP stacks for NuttX.
For example, user-space daemon can translate /dev/usrsock API
requests to HW TCP/IP API requests while rest of the user-space
can access standard socket API, with socket descriptors that
can be used with NuttX system calls.
endmenu # Data link support
source "net/netdev/Kconfig"
@@ -271,6 +297,7 @@ source "net/arp/Kconfig"
source "net/loopback/Kconfig"
source "net/iob/Kconfig"
source "net/procfs/Kconfig"
source "net/usrsock/Kconfig"
source "net/utils/Kconfig"
config NET_STATISTICS
+1
View File
@@ -72,6 +72,7 @@ include devif/Make.defs
include loopback/Make.defs
include route/Make.defs
include procfs/Make.defs
include usrsock/Make.defs
include utils/Make.defs
endif
+19 -15
View File
@@ -22,21 +22,25 @@ Directory Structure
+- route - Routing table support
+- tcp - Transmission Control Protocol
+- udp - User Datagram Protocol
+- usrsock - User socket API for user-space networking stack
`- utils - Miscellaneous utility functions
+----------------------------------------------------------------+
| Application layer |
+----------------------------------------------------------------+
+----------------------------------------------------------------+
| Socket layer (socket/) |
+----------------------------------------------------------------+
+------------++--------------------------------------------------+
| Network || Protocol stacks (arp, ipv6, icmp, pkt, tcp, udp) |
| Device |+--------------------------------------------------+
| Interface |+------------------------------------++------------+
| (netdev/) || Network Device Interface (devif/) || Utilities |
+------------++------------------------------------++------------+
+----------------------------------------------------------------+
| Network Device Drivers |
+----------------------------------------------------------------+
+-------------------------------------------------------------------++------------------------+
| Application layer || usrsock daemon |
+-------------------------------------------------------------------++------------------------+
+-------------------------------------------------------------------++----------------+ +-----+
| Socket layer (socket/) || /dev/usrsock | | |
+-------------------------------------------------------------------++----------------+ | |
+------------++--------------------------------------------------++-------------------+ | |
| Network || Protocol stacks (arp, ipv6, icmp, pkt, tcp, udp) || usrsock/ | | |
| Device |+--------------------------------------------------++-------------------+ | |
| Interface |+------------------------------------++---------------------------------+ | |
| (netdev/) || Network Device Interface (devif/) || Utilities | | |
+------------++------------------------------------++---------------------------------+ | |
+----------------------------------------------------------------+ | |
| Network Device Drivers | | HAL |
+----------------------------------------------------------------+ +-----+
+----------------------------------------------------------------+ +--------------------------+
| Networking Hardware | | Hardware TCP/IP Stack |
+----------------------------------------------------------------+ +--------------------------+
+10 -3
View File
@@ -1,7 +1,7 @@
/****************************************************************************
* net/devif/devif.h
*
* Copyright (C) 2007-2009, 2013-2016 Gregory Nutt. All rights reserved.
* Copyright (C) 2007-2009, 2013-2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* This logic was leveraged from uIP which also has a BSD-style license:
@@ -170,11 +170,13 @@
#define TCP_NEWDATA (1 << 1)
#define UDP_NEWDATA TCP_NEWDATA
#define PKT_NEWDATA TCP_NEWDATA
#define WPAN_NEWDATA TCP_NEWDATA
#define TCP_SNDACK (1 << 2)
#define TCP_REXMIT (1 << 3)
#define TCP_POLL (1 << 4)
#define UDP_POLL TCP_POLL
#define PKT_POLL TCP_POLL
#define WPAN_POLL TCP_POLL
#define TCP_BACKLOG (1 << 5)
#define TCP_CLOSE (1 << 6)
#define TCP_ABORT (1 << 7)
@@ -234,12 +236,17 @@
*/
struct net_driver_s; /* Forward reference */
typedef CODE uint16_t (*devif_callback_event_t)(FAR struct net_driver_s *dev,
FAR void *pvconn,
FAR void *pvpriv,
uint16_t flags);
struct devif_callback_s
{
FAR struct devif_callback_s *nxtconn;
FAR struct devif_callback_s *nxtdev;
uint16_t (*event)(FAR struct net_driver_s *dev, FAR void *pvconn,
FAR void *pvpriv, uint16_t flags);
FAR devif_callback_event_t event;
FAR void *priv;
uint16_t flags;
};
+7 -7
View File
@@ -186,7 +186,7 @@ static inline int devif_poll_igmp(FAR struct net_driver_s *dev,
*
****************************************************************************/
#ifdef CONFIG_NET_UDP
#ifdef NET_UDP_HAVE_STACK
static int devif_poll_udp_connections(FAR struct net_driver_s *dev,
devif_poll_callback_t callback)
{
@@ -208,7 +208,7 @@ static int devif_poll_udp_connections(FAR struct net_driver_s *dev,
return bstop;
}
#endif /* CONFIG_NET_UDP */
#endif /* NET_UDP_HAVE_STACK */
/****************************************************************************
* Function: devif_poll_tcp_connections
@@ -222,7 +222,7 @@ static int devif_poll_udp_connections(FAR struct net_driver_s *dev,
*
****************************************************************************/
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
static inline int devif_poll_tcp_connections(FAR struct net_driver_s *dev,
devif_poll_callback_t callback)
{
@@ -261,7 +261,7 @@ static inline int devif_poll_tcp_connections(FAR struct net_driver_s *dev,
*
****************************************************************************/
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
static inline int devif_poll_tcp_timer(FAR struct net_driver_s *dev,
devif_poll_callback_t callback,
int hsec)
@@ -349,7 +349,7 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback)
if (!bstop)
#endif
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
{
/* Traverse all of the active TCP connections and perform the poll
* action.
@@ -360,7 +360,7 @@ int devif_poll(FAR struct net_driver_s *dev, devif_poll_callback_t callback)
if (!bstop)
#endif
#ifdef CONFIG_NET_UDP
#ifdef NET_UDP_HAVE_STACK
{
/* Traverse all of the allocated UDP connections and perform
* the poll action
@@ -467,7 +467,7 @@ int devif_timer(FAR struct net_driver_s *dev, devif_poll_callback_t callback)
neighbor_periodic(hsec);
#endif
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
/* Traverse all of the active TCP connections and perform the
* timer action.
*/
+3 -3
View File
@@ -391,7 +391,7 @@ int ipv4_input(FAR struct net_driver_s *dev)
#endif /* CONFIG_NET_TCP_REASSEMBLY */
}
#if defined(CONFIG_NET_BROADCAST) && defined(CONFIG_NET_UDP)
#if defined(CONFIG_NET_BROADCAST) && defined(NET_UDP_HAVE_STACK)
/* If IP broadcast support is configured, we check for a broadcast
* UDP packet, which may be destined to us (even if there is no IP
* address yet assigned to the device as is the case when we are
@@ -459,13 +459,13 @@ int ipv4_input(FAR struct net_driver_s *dev)
switch (pbuf->proto)
{
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
case IP_PROTO_TCP: /* TCP input */
tcp_ipv4_input(dev);
break;
#endif
#ifdef CONFIG_NET_UDP
#ifdef NET_UDP_HAVE_STACK
case IP_PROTO_UDP: /* UDP input */
udp_ipv4_input(dev);
break;
+3 -3
View File
@@ -197,7 +197,7 @@ int ipv6_input(FAR struct net_driver_s *dev)
* negotiating over DHCP for an address).
*/
#if defined(CONFIG_NET_BROADCAST) && defined(CONFIG_NET_UDP)
#if defined(CONFIG_NET_BROADCAST) && defined(NET_UDP_HAVE_STACK)
if (ipv6->proto == IP_PROTO_UDP &&
net_ipv6addr_cmp(ipv6->destipaddr, g_ipv6_alloneaddr))
{
@@ -253,13 +253,13 @@ int ipv6_input(FAR struct net_driver_s *dev)
switch (ipv6->proto)
{
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
case IP_PROTO_TCP: /* TCP input */
tcp_ipv6_input(dev);
break;
#endif
#ifdef CONFIG_NET_UDP
#ifdef NET_UDP_HAVE_STACK
case IP_PROTO_UDP: /* UDP input */
udp_ipv6_input(dev);
break;
+10 -1
View File
@@ -39,7 +39,16 @@ ifeq ($(CONFIG_NET_IPv6),y)
NET_CSRCS += neighbor_initialize.c neighbor_add.c neighbor_lookup.c
NET_CSRCS += neighbor_update.c neighbor_periodic.c neighbor_findentry.c
NET_CSRCS += neighbor_out.c
# Link layer specific support
ifeq ($(CONFIG_NET_ETHERNET),y)
NET_CSRCS += neighbor_ethernet_out.c
endif
ifeq ($(CONFIG_NET_6LOWPAN),y)
# NET_CSRCS += neighbor_6lowpan_out.c
endif
# Include utility build support
@@ -1,7 +1,7 @@
/****************************************************************************
* net/neighbor/neighbor_out.c
* net/neighbor/neighbor_ethernet_out.c
*
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
* Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Redistribution and use in source and binary forms, with or without
+9 -2
View File
@@ -57,6 +57,7 @@
#include "local/local.h"
#include "igmp/igmp.h"
#include "route/route.h"
#include "usrsock/usrsock.h"
#include "utils/utils.h"
/****************************************************************************
@@ -130,7 +131,7 @@ void net_setup(void)
local_initialize();
#endif
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
/* Initialize the listening port structures */
tcp_listen_initialize();
@@ -146,7 +147,7 @@ void net_setup(void)
#endif
#endif /* CONFIG_NET_TCP */
#ifdef CONFIG_NET_UDP
#ifdef NET_UDP_HAVE_STACK
/* Initialize the UDP connection structures */
udp_initialize();
@@ -163,6 +164,12 @@ void net_setup(void)
net_initroute();
#endif
#ifdef CONFIG_NET_USRSOCK
/* Initialize the user-space socket API */
usrsock_initialize();
#endif
}
/****************************************************************************
-14
View File
@@ -3,14 +3,6 @@
# see the file kconfig-language.txt in the NuttX tools repository.
#
menuconfig NET_6LOWPAN
bool "IEEE 802.15.4 6LoWPAN support"
default n
depends on EXPERIMENTAL && NET_IPv6
---help---
Enable support for IEEE 802.15.4 Low power Wireless Personal Area
Networking (6LoWPAN).
if NET_6LOWPAN
config NET_6LOWPAN_FRAG
@@ -186,10 +178,4 @@ config NET_6LOWPAN_TCP_RECVWNDO
the application is slow to process incoming data, or high (32768
bytes) if the application processes data quickly.
config NET_6LOWPAN_SNIFFER
default n
---help---
Enable use use an architecture-specific sniffer to support tracing
of IP.
endif # NET_6LOWPAN
+2 -6
View File
@@ -1,7 +1,7 @@
############################################################################
# net/sixlowpan/Make.defs
#
# Copyright (C) 2016 Gregory Nutt. All rights reserved.
# Copyright (C) 2017 Gregory Nutt. All rights reserved.
# Author: Gregory Nutt <gnutt@nuttx.org>
#
# Redistribution and use in source and binary forms, with or without
@@ -41,7 +41,7 @@ ifeq ($(CONFIG_NET_6LOWPAN),y)
NET_CSRCS += sixlowpan_initialize.c sixlowpan_globals.c sixlowpan_utils.c
NET_CSRCS += sixlowpan_input.c sixlowpan_send.c sixlowpan_framer.c
NET_CSRCS += sixlowpan_compressor.c
NET_CSRCS += sixlowpan_framelist.c sixlowpan_compressor.c
ifeq ($(CONFIG_NET_TCP),y)
NET_CSRCS += sixlowpan_tcpsend.c
@@ -59,10 +59,6 @@ ifeq ($(CONFIG_NET_6LOWPAN_COMPRESSION_HC06),y)
NET_CSRCS += sixlowpan_hc06.c
endif
ifeq ($(CONFIG_NET_6LOWPAN_SNIFFER),y)
NET_CSRCS += sixlowpan_sniffer.c
endif
# Include the sixlowpan directory in the build
DEPPATH += --dep-path sixlowpan
-1
View File
@@ -40,7 +40,6 @@
#include <nuttx/config.h>
#include "nuttx/net/net.h"
#include "nuttx/net/sixlowpan.h"
#include "sixlowpan/sixlowpan_internal.h"
+473
View File
@@ -0,0 +1,473 @@
/****************************************************************************
* net/sixlowpan/sixlowpan_framelist.c
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Parts of this file derive from Contiki:
*
* Copyright (c) 2008, Swedish Institute of Computer Science.
* All rights reserved.
* Authors: Adam Dunkels <adam@sics.se>
* Nicolas Tsiftes <nvt@sics.se>
* Niclas Finne <nfi@sics.se>
* Mathilde Durvy <mdurvy@cisco.com>
* Julien Abeille <jabeille@cisco.com>
* Joakim Eriksson <joakime@sics.se>
* Joel Hoglund <joel@sics.se>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <string.h>
#include <assert.h>
#include <debug.h>
#include <nuttx/net/netdev.h>
#include "sixlowpan/sixlowpan_internal.h"
#ifdef CONFIG_NET_6LOWPAN
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Configuration ************************************************************/
/* A single IOB must be big enough to hold a full frame */
#if CONFIG_IOB_BUFSIZE < CONFIG_NET_6LOWPAN_FRAMELEN
# error IOBs must be large enough to hold full IEEE802.14.5 frame
#endif
/* There must be at least enough IOBs to hold the full MTU. Probably still
* won't work unless there are a few more.
*/
#if CONFIG_NET_6LOWPAN_MTU > (CONFIG_IOB_BUFSIZE * CONFIG_IOB_NBUFFERS)
# error Not enough IOBs to hold one full IEEE802.14.5 packet
#endif
/****************************************************************************
* Private Functions
****************************************************************************/
/****************************************************************************
* Name: sixlowpan_compress_ipv6hdr
*
* Description:
* IPv6 dispatch "compression" function. Packets "Compression" when only
* IPv6 dispatch is used
*
* There is no compression in this case, all fields are sent
* inline. We just add the IPv6 dispatch byte before the packet.
*
* 0 1 2 3
* 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
* | IPv6 Dsp | IPv6 header and payload ...
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
* Input Parameters:
* ieee - Pointer to IEEE802.15.4 MAC driver structure.
* ipv6 - Pointer to the IPv6 header to "compress"
*
* Returned Value:
* None
*
****************************************************************************/
static void sixlowpan_compress_ipv6hdr(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6)
{
/* Indicate the IPv6 dispatch and length */
*g_rimeptr = SIXLOWPAN_DISPATCH_IPV6;
g_rime_hdrlen += SIXLOWPAN_IPV6_HDR_LEN;
/* Copy the IPv6 header and adjust pointers */
memcpy(g_rimeptr + g_rime_hdrlen, ipv6, IPv6_HDRLEN);
g_rime_hdrlen += IPv6_HDRLEN;
g_uncomp_hdrlen += IPv6_HDRLEN;
}
/****************************************************************************
* Public Functions
****************************************************************************/
/****************************************************************************
* Name: sixlowpan_queue_frames
*
* Description:
* Process an outgoing UDP or TCP packet. This function is called from
* send interrupt logic when a TX poll is received. It formates the
* list of frames to be sent by the IEEE802.15.4 MAC driver.
*
* The payload data is in the caller 's_buf' and is of length 's_len'.
* Compressed headers will be added and if necessary the packet is
* fragmented. The resulting packet/fragments are put in ieee->i_framelist
* and the entire list of frames will be delivered to the 802.15.4 MAC via
* ieee->i_framelist.
*
* Input Parameters:
* ieee - The IEEE802.15.4 MAC driver instance
* ipv6hdr - IPv6 header followed by TCP or UDP header.
* buf - Data to send
* len - Length of data to send
* destmac - The IEEE802.15.4 MAC address of the destination
*
* Returned Value:
* Ok is returned on success; Othewise a negated errno value is returned.
* This function is expected to fail if the driver is not an IEEE802.15.4
* MAC network driver. In that case, the UDP/TCP will fall back to normal
* IPv4/IPv6 formatting.
*
* Assumptions:
* Called with the network locked.
*
****************************************************************************/
int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *destip,
FAR const void *buf, size_t len,
FAR const struct rimeaddr_s *destmac)
{
FAR struct iob_s *iob;
int framer_hdrlen;
struct rimeaddr_s dest;
uint16_t outlen = 0;
/* Initialize global data. Locking the network guarantees that we have
* exclusive use of the global values for intermediate calculations.
*/
FRAME_RESET();
g_uncomp_hdrlen = 0;
g_rime_hdrlen = 0;
/* REVISIT: Do I need this rimeptr? */
g_rimeptr = &ieee->i_dev.d_buf[PACKETBUF_HDR_SIZE];
/* Reset rime buffer, packet buffer metatadata */
memset(g_pktattrs, 0, PACKETBUF_NUM_ATTRS * sizeof(uint16_t));
memset(g_pktaddrs, 0, PACKETBUF_NUM_ADDRS * sizeof(struct rimeaddr_s));
g_pktattrs[PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS] =
CONFIG_NET_6LOWPAN_MAX_MACTRANSMITS;
/* Set stream mode for all TCP packets, except FIN packets. */
if (destip->proto == IP_PROTO_TCP)
{
FAR const struct tcp_hdr_s *tcp =
&((FAR const struct ipv6tcp_hdr_s *)destip)->tcp;
if ((tcp->flags & TCP_FIN) == 0 &&
(tcp->flags & TCP_CTL) != TCP_ACK)
{
g_pktattrs[PACKETBUF_ATTR_PACKET_TYPE] = PACKETBUF_ATTR_PACKET_TYPE_STREAM;
}
else if ((tcp->flags & TCP_FIN) == TCP_FIN)
{
g_pktattrs[PACKETBUF_ATTR_PACKET_TYPE] = PACKETBUF_ATTR_PACKET_TYPE_STREAM_END;
}
}
/* The destination address will be tagged to each outbound packet. If the
* argument destmac is NULL, we are sending a broadcast packet.
*/
if (destmac == NULL)
{
memset(&dest, 0, sizeof(struct rimeaddr_s));
}
else
{
rimeaddr_copy(&dest, (FAR const struct rimeaddr_s *)destmac);
}
ninfo("Sending packet len %d\n", len);
#ifndef CONFIG_NET_6LOWPAN_COMPRESSION_IPv6
if (len >= CONFIG_NET_6LOWPAN_COMPRESSION_THRESHOLD)
{
/* Try to compress the headers */
#if defined(CONFIG_NET_6LOWPAN_COMPRESSION_HC1)
sixlowpan_compresshdr_hc1(ieee, &dest);
#elif defined(CONFIG_NET_6LOWPAN_COMPRESSION_HC06)
sixlowpan_compresshdr_hc06(ieee, &dest);
#else
# error No compression specified
#endif
}
else
#endif /* !CONFIG_NET_6LOWPAN_COMPRESSION_IPv6 */
{
/* Small.. use IPv6 dispatch (no compression) */
sixlowpan_compress_ipv6hdr(ieee, destip);
}
ninfo("Header of len %d\n", g_rime_hdrlen);
rimeaddr_copy(&g_pktaddrs[PACKETBUF_ADDR_RECEIVER], &dest);
/* Pre-calculate frame header length. */
framer_hdrlen = sixlowpan_hdrlen(ieee, ieee->i_panid);
if (framer_hdrlen < 0)
{
/* Failed to determine the size of the header failed. */
nerr("ERROR: sixlowpan_hdrlen() failed: %d\n", framer_hdrlen);
return framer_hdrlen;
}
/* Check if we need to fragment the packet into several frames */
if ((int)len - (int)g_uncomp_hdrlen >
(int)CONFIG_NET_6LOWPAN_MAXPAYLOAD - framer_hdrlen -
(int)g_rime_hdrlen)
{
#if CONFIG_NET_6LOWPAN_FRAG
/* ieee->i_framelist will hold the generated frames; frames will be
* added at qtail.
*/
FAR struct iob_s *qtail;
int verify;
/* The outbound IPv6 packet is too large to fit into a single 15.4
* packet, so we fragment it into multiple packets and send them.
* The first fragment contains frag1 dispatch, then
* IPv6/HC1/HC06/HC_UDP dispatchs/headers.
* The following fragments contain only the fragn dispatch.
*/
ninfo("Fragmentation sending packet len %d\n", len);
/* Allocate an IOB to hold the first fragment, waiting if necessary. */
iob = iob_alloc(false);
DEBUGASSERT(iob != NULL);
/* Initialize the IOB */
iob->io_flink = NULL;
iob->io_len = 0;
iob->io_offset = 0;
iob->io_pktlen = 0;
/* Create 1st Fragment */
/* Add the frame header */
verify = sixlowpan_framecreate(ieee, iob, ieee->i_panid);
DEBUGASSERT(verify == framer_hdrlen);
UNUSED(verify);
/* Move HC1/HC06/IPv6 header */
memmove(g_rimeptr + SIXLOWPAN_FRAG1_HDR_LEN, g_rimeptr, g_rime_hdrlen);
/* Setup up the fragment header.
*
* The fragment header contains three fields: Datagram size, datagram
* tag and datagram offset:
*
* 1. Datagram size describes the total (un-fragmented) payload.
* 2. Datagram tag identifies the set of fragments and is used to
* match fragments of the same payload.
* 3. Datagram offset identifies the fragments offset within the un-
* fragmented payload.
*
* The fragment header length is 4 bytes for the first header and 5
* bytes for all subsequent headers.
*/
PUTINT16(RIME_FRAG_PTR, RIME_FRAG_DISPATCH_SIZE,
((SIXLOWPAN_DISPATCH_FRAG1 << 8) | len));
PUTINT16(RIME_FRAG_PTR, RIME_FRAG_TAG, ieee->i_dgramtag);
ieee->i_dgramtag++;
/* Copy payload and enqueue */
g_rime_hdrlen += SIXLOWPAN_FRAG1_HDR_LEN;
g_rime_payloadlen =
(CONFIG_NET_6LOWPAN_MAXPAYLOAD - framer_hdrlen - g_rime_hdrlen) & 0xf8;
memcpy(g_rimeptr + g_rime_hdrlen,
(FAR uint8_t *)destip + g_uncomp_hdrlen, g_rime_payloadlen);
iob->io_len += g_rime_payloadlen + g_rime_hdrlen;
/* Set outlen to what we already sent from the IP payload */
outlen = g_rime_payloadlen + g_uncomp_hdrlen;
ninfo("First fragment: len %d, tag %d\n",
g_rime_payloadlen, ieee->i_dgramtag);
/* Add the first frame to the IOB queue */
ieee->i_framelist = iob;
qtail = iob;
/* Keep track of the total amount of data queue */
iob->io_pktlen = iob->io_len;
/* Create following fragments */
g_rime_hdrlen = SIXLOWPAN_FRAGN_HDR_LEN;
while (outlen < len)
{
/* Allocate an IOB to hold the next fragment, waiting if
* necessary.
*/
iob = iob_alloc(false);
DEBUGASSERT(iob != NULL);
/* Initialize the IOB */
iob->io_flink = NULL;
iob->io_len = 0;
iob->io_offset = 0;
iob->io_pktlen = 0;
/* Add the frame header */
verify = sixlowpan_framecreate(ieee, iob, ieee->i_panid);
DEBUGASSERT(vreify == framer_hdrlen);
UNUSED(verify);
/* Move HC1/HC06/IPv6 header */
memmove(g_rimeptr + SIXLOWPAN_FRAGN_HDR_LEN, g_rimeptr, g_rime_hdrlen);
/* Setup up the fragment header */
PUTINT16(RIME_FRAG_PTR, RIME_FRAG_DISPATCH_SIZE,
((SIXLOWPAN_DISPATCH_FRAGN << 8) | len));
PUTINT16(RIME_FRAG_PTR, RIME_FRAG_TAG, ieee->i_dgramtag);
RIME_FRAG_PTR[RIME_FRAG_OFFSET] = outlen >> 3;
/* Copy payload and enqueue */
if (len - outlen < g_rime_payloadlen)
{
/* Last fragment */
g_rime_payloadlen = len - outlen;
}
else
{
g_rime_payloadlen =
(CONFIG_NET_6LOWPAN_MAXPAYLOAD - framer_hdrlen - g_rime_hdrlen) & 0xf8;
}
memcpy(g_rimeptr + g_rime_hdrlen, (FAR uint8_t *)destip + outlen,
g_rime_payloadlen);
iob->io_len = g_rime_payloadlen + g_rime_hdrlen;
/* Set outlen to what we already sent from the IP payload */
outlen += (g_rime_payloadlen + g_uncomp_hdrlen);
ninfo("sixlowpan output: fragment offset %d, len %d, tag %d\n",
outlen >> 3, g_rime_payloadlen, ieee->i_dgramtag);
/* Add the next frame to the tail of the IOB queue */
qtail->io_flink = iob;
/* Keep track of the total amount of data queue */
ieee->i_framelist->io_pktlen += iob->io_len;
}
#else
nerr("ERROR: Packet too large: %d\n", len);
nerr(" Cannot to be sent without fragmentation support\n");
nerr(" dropping packet\n");
return -E2BIG;
#endif
}
else
{
int verify;
/* The packet does not need to be fragmented just copy the "payload"
* and send in one frame.
*/
/* Allocate an IOB to hold the frame, waiting if necessary. */
iob = iob_alloc(false);
DEBUGASSERT(iob != NULL);
/* Initialize the IOB */
iob->io_flink = NULL;
iob->io_len = 0;
iob->io_offset = 0;
iob->io_pktlen = 0;
/* Add the frame header */
verify = sixlowpan_framecreate(ieee, iob, ieee->i_panid);
DEBUGASSERT(vreify == framer_hdrlen);
UNUSED(verify);
/* Copy the payload and queue */
memcpy(g_rimeptr + g_rime_hdrlen, (FAR uint8_t *)destip + g_uncomp_hdrlen,
len - g_uncomp_hdrlen);
iob->io_len = len - g_uncomp_hdrlen + g_rime_hdrlen;
/* Add the first frame to the IOB queue */
ieee->i_framelist = iob;
/* Keep track of the total amount of data queue */
iob->io_pktlen = iob->io_len;
}
return OK;
}
#endif /* CONFIG_NET_6LOWPAN */
+30 -25
View File
@@ -55,7 +55,6 @@
#include <debug.h>
#include "nuttx/net/net.h"
#include "nuttx/net/sixlowpan.h"
#include "sixlowpan/sixlowpan_internal.h"
@@ -277,9 +276,10 @@ static int sixlowpan_802154_hdrlen(FAR struct frame802154_s *finfo)
*
* Input parameters:
* ieee - A reference IEEE802.15.4 MAC network device structure.
* params - Where to put the parmeters
* iob - The IOB in which to create the frame.
* dest_panid - PAN ID of the destination. May be 0xffff if the destination
* is not associated.
* params - Where to put the parmeters
*
* Returned Value:
* None.
@@ -287,8 +287,8 @@ static int sixlowpan_802154_hdrlen(FAR struct frame802154_s *finfo)
****************************************************************************/
static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee,
FAR struct frame802154_s *params,
uint16_t dest_panid)
FAR struct iob_s *iob, uint16_t dest_panid,
FAR struct frame802154_s *params)
{
bool rcvrnull;
@@ -298,22 +298,21 @@ static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee,
/* Reset to an empty frame */
ieee->i_framelen = 0;
ieee->i_dataoffset = 0;
FRAME_RESET();
/* Build the FCF (Only non-zero elements need to be initialized). */
params->fcf.frame_type = FRAME802154_DATAFRAME;
params->fcf.frame_pending = ieee->i_pktattrs[PACKETBUF_ATTR_PENDING];
params->fcf.frame_pending = g_pktattrs[PACKETBUF_ATTR_PENDING];
/* If the output address is NULL in the Rime buf, then it is broadcast
* on the 802.15.4 network.
*/
rcvrnull = sixlowpan_addrnull(ieee->i_pktaddrs[PACKETBUF_ADDR_RECEIVER].u8);
rcvrnull = sixlowpan_addrnull(g_pktaddrs[PACKETBUF_ADDR_RECEIVER].u8);
if (rcvrnull)
{
params->fcf.ack_required = ieee->i_pktattrs[PACKETBUF_ATTR_MAC_ACK];
params->fcf.ack_required = g_pktattrs[PACKETBUF_ATTR_MAC_ACK];
}
/* Insert IEEE 802.15.4 (2003) version bit. */
@@ -322,14 +321,14 @@ static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee,
/* Increment and set the data sequence number. */
if (ieee->i_pktattrs[PACKETBUF_ATTR_MAC_SEQNO] != 0)
if (g_pktattrs[PACKETBUF_ATTR_MAC_SEQNO] != 0)
{
params->seq = ieee->i_pktattrs[PACKETBUF_ATTR_MAC_SEQNO];
params->seq = g_pktattrs[PACKETBUF_ATTR_MAC_SEQNO];
}
else
{
params->seq = ieee->i_dsn++;
ieee->i_pktattrs[PACKETBUF_ATTR_MAC_SEQNO] = params->seq;
g_pktattrs[PACKETBUF_ATTR_MAC_SEQNO] = params->seq;
}
/* Complete the addressing fields. */
@@ -355,7 +354,7 @@ static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee,
/* Copy the destination address */
rimeaddr_copy((struct rimeaddr_s *)&params->dest_addr,
ieee->i_pktaddrs[PACKETBUF_ADDR_RECEIVER].u8);
g_pktaddrs[PACKETBUF_ADDR_RECEIVER].u8);
/* Use short address mode if so configured */
@@ -370,10 +369,13 @@ static void sixlowpan_setup_params(FAR struct ieee802154_driver_s *ieee,
rimeaddr_copy((struct rimeaddr_s *)&params->src_addr, &ieee->i_nodeaddr.u8);
/* Configure the payload address and length */
/* Configure the (optional) payload address and length */
params->payload = FRAME_DATA_START(ieee);
params->payload_len = FRAME_DATA_SIZE(ieee);
if (iob != NULL)
{
params->payload = FRAME_DATA_START(iob);
params->payload_len = FRAME_DATA_SIZE(iob);
}
}
/****************************************************************************
@@ -406,7 +408,7 @@ int sixlowpan_hdrlen(FAR struct ieee802154_driver_s *ieee,
/* Set up the frame parameters */
sixlowpan_setup_params(ieee, &params, dest_panid);
sixlowpan_setup_params(ieee, NULL, dest_panid, &params);
/* Return the length of the header */
@@ -516,11 +518,14 @@ int sixlowpan_802154_framecreate(FAR struct frame802154_s *finfo,
* Function: sixlowpan_framecreate
*
* Description:
* This function is called after the IEEE802.15.4 MAC driver polls for
* TX data. It creates the IEEE802.15.4 header in the frame buffer.
* This function is called after eiether (1) the IEEE802.15.4 MAC driver
* polls for TX data or (2) after the IEEE802.15.4 MAC driver provides an
* in frame and the network responds with an outgoing packet. It creates
* the IEEE802.15.4 header in the frame buffer.
*
* Input parameters:
* ieee - A reference IEEE802.15.4 MAC network device structure.
* iob - The IOB in which to create the frame.
* dest_panid - PAN ID of the destination. May be 0xffff if the destination
* is not associated.
*
@@ -531,7 +536,7 @@ int sixlowpan_802154_framecreate(FAR struct frame802154_s *finfo,
****************************************************************************/
int sixlowpan_framecreate(FAR struct ieee802154_driver_s *ieee,
uint16_t dest_panid)
FAR struct iob_s *iob, uint16_t dest_panid)
{
struct frame802154_s params;
int len;
@@ -539,7 +544,7 @@ int sixlowpan_framecreate(FAR struct ieee802154_driver_s *ieee,
/* Set up the frame parameters */
sixlowpan_setup_params(ieee, &params, dest_panid);
sixlowpan_setup_params(ieee, iob, dest_panid, &params);
/* Get the length of the header */
@@ -547,7 +552,7 @@ int sixlowpan_framecreate(FAR struct ieee802154_driver_s *ieee,
/* Allocate space for the header in the frame buffer */
ret = sixlowpan_frame_hdralloc(ieee, len);
ret = sixlowpan_frame_hdralloc(iob, len);
if (ret < 0)
{
wlerr("ERROR: Header too large: %u\n", len);
@@ -556,11 +561,11 @@ int sixlowpan_framecreate(FAR struct ieee802154_driver_s *ieee,
/* Then create the frame */
sixlowpan_802154_framecreate(&params, FRAME_HDR_START(ieee), len);
sixlowpan_802154_framecreate(&params, FRAME_HDR_START(iob), len);
wlinfo("Frame type: %02x Data len: %d %u (%u)\n",
params.fcf.frame_type, len, FRAME_DATA_SIZE(ieee),
FRAME_SIZE(ieee));
params.fcf.frame_type, len, FRAME_DATA_SIZE(iob),
FRAME_SIZE(ieee, iob));
#if CONFIG_NET_6LOWPAN_RIMEADDR_SIZE == 2
wlinfo("Dest address: %02x:%02x\n",
params.dest_addr[0], params.dest_addr[1]);
+44 -6
View File
@@ -39,8 +39,6 @@
#include <nuttx/config.h>
#include "nuttx/net/sixlowpan.h"
#include "sixlowpan/sixlowpan_internal.h"
#ifdef CONFIG_NET_6LOWPAN
@@ -53,10 +51,50 @@
FAR struct sixlowpan_nhcompressor_s *g_sixlowpan_compressor;
#ifdef CONFIG_NET_6LOWPAN_SNIFFER
/* A pointer to the optional, architecture-specific sniffer */
/* The following data values are used to hold intermediate settings while
* processing IEEE802.15.4 frames. These globals are shared with incoming
* and outgoing frame processing and possibly with mutliple IEEE802.15.4 MAC
* devices. The network lock provides exclusive use of these globals
* during that processing
*/
FAR struct sixlowpan_rime_sniffer_s *g_sixlowpan_sniffer;
#endif
/* A pointer to the rime buffer.
*
* We initialize it to the beginning of the rime buffer, then access
* different fields by updating the offset ieee->g_rime_hdrlen.
*/
FAR uint8_t *g_rimeptr;
/* The length of the payload in the Rime buffer.
*
* The payload is what comes after the compressed or uncompressed headers
* (can be the IP payload if the IP header only is compressed or the UDP
* payload if the UDP header is also compressed)
*/
uint8_t g_rime_payloadlen;
/* g_uncomp_hdrlen is the length of the headers before compression (if HC2
* is used this includes the UDP header in addition to the IP header).
*/
uint8_t g_uncomp_hdrlen;
/* g_rime_hdrlen is the total length of (the processed) 6lowpan headers
* (fragment headers, IPV6 or HC1, HC2, and HC1 and HC2 non compressed
* fields).
*/
uint8_t g_rime_hdrlen;
/* Offset first available byte for the payload after header region. */
uint8_t g_dataoffset;
/* Packet buffer metadata: Attributes and addresses */
uint16_t g_pktattrs[PACKETBUF_NUM_ATTRS];
struct rimeaddr_s g_pktaddrs[PACKETBUF_NUM_ADDRS];
#endif /* CONFIG_NET_6LOWPAN */
+5 -6
View File
@@ -59,7 +59,6 @@
#include <nuttx/config.h>
#include <nuttx/net/netdev.h>
#include <nuttx/net/sixlowpan.h>
#include "sixlowpan/sixlowpan_internal.h"
@@ -169,7 +168,7 @@ void sixlowpan_hc06_initialize(void)
}
/****************************************************************************
* Name: sixlowpan_hc06_initialize
* Name: sixlowpan_compresshdr_hc06
*
* Description:
* Compress IP/UDP header
@@ -203,7 +202,7 @@ void sixlowpan_hc06_initialize(void)
* compress the IID.
*
* Input Parameters:
* dev - A reference to the IEE802.15.4 network device state
* ieee - A reference to the IEE802.15.4 network device state
* destaddr - L2 destination address, needed to compress IP dest
*
* Returned Value:
@@ -211,7 +210,7 @@ void sixlowpan_hc06_initialize(void)
*
****************************************************************************/
void sixlowpan_compresshdr_hc06(FAR struct net_driver_s *dev,
void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
FAR struct rimeaddr_s *destaddr)
{
/* REVISIT: To be provided */
@@ -231,7 +230,7 @@ void sixlowpan_compresshdr_hc06(FAR struct net_driver_s *dev,
* appropriate values
*
* Input Parmeters:
* dev - A reference to the IEE802.15.4 network device state
* ieee - A reference to the IEE802.15.4 network device state
* iplen - Equal to 0 if the packet is not a fragment (IP length is then
* inferred from the L2 length), non 0 if the packet is a 1st
* fragment.
@@ -241,7 +240,7 @@ void sixlowpan_compresshdr_hc06(FAR struct net_driver_s *dev,
*
****************************************************************************/
void sixlowpan_uncompresshdr_hc06(FAR struct net_driver_s *dev,
void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
uint16_t iplen)
{
/* REVISIT: To be provided */
+4 -4
View File
@@ -102,7 +102,7 @@
* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
*
* Input Parmeters:
* dev - A reference to the IEE802.15.4 network device state
* ieee - A reference to the IEE802.15.4 network device state
* destaddr - L2 destination address, needed to compress the IP
* destination field
*
@@ -111,7 +111,7 @@
*
****************************************************************************/
void sixlowpan_compresshdr_hc1(FAR struct net_driver_s *dev,
void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
FAR struct rimeaddr_s *destaddr)
{
/* REVISIT: To be provided */
@@ -130,7 +130,7 @@ void sixlowpan_compresshdr_hc1(FAR struct net_driver_s *dev,
* are set to the appropriate values
*
* Input Parameters:
* dev - A reference to the IEE802.15.4 network device state
* ieee - A reference to the IEE802.15.4 network device state
* iplen - Equal to 0 if the packet is not a fragment (IP length is then
* inferred from the L2 length), non 0 if the packet is a 1st
* fragment.
@@ -140,7 +140,7 @@ void sixlowpan_compresshdr_hc1(FAR struct net_driver_s *dev,
*
****************************************************************************/
void sixlowpan_uncompresshdr_hc1(FAR struct net_driver_s *dev,
void sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
uint16_t iplen)
{
/* REVISIT: To be provided */
+269 -31
View File
@@ -1,35 +1,45 @@
/****************************************************************************
* net/sixlowpan/sixlowpan_input.c
* 6lowpan implementation (RFC4944 and draft-ietf-6lowpan-hc-06)
*
* Copyright (C) 2017 Gregory Nutt. All rights reserved.
* Copyright (C) 2017, Gregory Nutt, all rights reserved
* Author: Gregory Nutt <gnutt@nuttx.org>
*
* Derives in large part from Contiki:
*
* Copyright (c) 2008, Swedish Institute of Computer Science.
* All rights reserved.
* Authors: Adam Dunkels <adam@sics.se>
* Nicolas Tsiftes <nvt@sics.se>
* Niclas Finne <nfi@sics.se>
* Mathilde Durvy <mdurvy@cisco.com>
* Julien Abeille <jabeille@cisco.com>
* Joakim Eriksson <joakime@sics.se>
* Joel Hoglund <joel@sics.se>
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
* 3. Neither the name NuttX nor the names of its contributors may be
* used to endorse or promote products derived from this software
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the Institute nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
* THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
****************************************************************************/
@@ -39,13 +49,31 @@
#include <nuttx/config.h>
#include <assert.h>
#include <errno.h>
#include <debug.h>
#include "nuttx/net/netdev.h"
#include "nuttx/net/ip.h"
#include "nuttx/net/sixlowpan.h"
#ifdef CONFIG_NET_PKT
# include "pkt/pkt.h"
#endif
#include "sixlowpan/sixlowpan_internal.h"
#ifdef CONFIG_NET_6LOWPAN
/****************************************************************************
* Pre-processor Definitions
****************************************************************************/
/* Success return values from sixlowpan_frame_process */
#define INPUT_PARTIAL 0 /* Frame processed successful, packet incomplete */
#define INPUT_COMPLETE 1 /* Frame processed successful, packet complete */
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -79,6 +107,129 @@ static bool sixlowpan_isbroadcast(uint8_t mode, FAR uint8_t *addr)
return true;
}
/****************************************************************************
* Name: sixlowpan_set_pktattrs
*
* Description:
* Setup some packet buffer attributes
*
* Input Parameters:
* ieee - Pointer to IEEE802.15.4 MAC driver structure.
* ipv6 - Pointer to the IPv6 header to "compress"
*
* Returned Value:
* None
*
****************************************************************************/
static void sixlowpan_set_pktattrs(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6)
{
int attr = 0;
/* Set protocol in NETWORK_ID */
g_pktattrs[PACKETBUF_ATTR_NETWORK_ID] = ipv6->proto;
/* Assign values to the channel attribute (port or type + code) */
if (ipv6->proto == IP_PROTO_UDP)
{
FAR struct udp_hdr_s *udp = &((FAR struct ipv6udp_hdr_s *)ipv6)->udp;
attr = udp->srcport;
if (udp->destport < attr)
{
attr = udp->destport;
}
}
else if (ipv6->proto == IP_PROTO_TCP)
{
FAR struct tcp_hdr_s *tcp = &((FAR struct ipv6tcp_hdr_s *)ipv6)->tcp;
attr = tcp->srcport;
if (tcp->destport < attr)
{
attr = tcp->destport;
}
}
else if (ipv6->proto == IP_PROTO_ICMP6)
{
FAR struct icmpv6_iphdr_s *icmp = &((FAR struct ipv6icmp_hdr_s *)ipv6)->icmp;
attr = icmp->type << 8 | icmp->code;
}
g_pktattrs[PACKETBUF_ATTR_CHANNEL] = attr;
}
/****************************************************************************
* Name: sixlowpan_frame_process
*
* Description:
* Process an incoming 6loWPAN frame in 'iob'.
*
* If its a FRAG1 or a non-fragmented frame we first uncompress the IP
* header. The 6loWPAN payload and possibly the uncompressed IP header
* are then copied into d_buf. An indication is returned if the packet
* in d_buf is complete (i.e., non-fragmented frame or and the last
* FRAGN frame).
*
* NOTE: We do not check for overlapping sixlowpan fragments (that is a
* SHALL in the RFC 4944 and should never happen)
*
* Input Parameters:
* ieee - The IEEE802.15.4 MAC network driver interface.
* iob - The IOB containing the frame.
*
* Returned Value:
* Ok is returned on success; Othewise a negated errno value is returned.
*
****************************************************************************/
static int sixlowpan_frame_process(FAR struct ieee802154_driver_s *ieee,
FAR struct iob_s *iob)
{
/* REVISIT: To be provided */
return -ENOSYS;
}
/****************************************************************************
* Function: sixlowpan_dispatch
*
* Description:
* Inject the packet in d_buf into the network for normal packet processing.
*
* Parameters:
* ieee - The IEEE802.15.4 MAC network driver interface.
*
* Returned Value:
* None
*
****************************************************************************/
static int sixlowpan_dispatch(FAR struct ieee802154_driver_s *ieee)
{
#ifdef CONFIG_NET_PKT
/* When packet sockets are enabled, feed the frame into the packet tap */
ninfo("Packet tap\n");
pkt_input(&ieee->i_dev);
#endif
/* We only accept IPv6 packets. */
ninfo("Iv6 packet dispatch\n");
NETDEV_RXIPV6(&ieee->i_dev);
/* Give the IPv6 packet to the network layer. NOTE: If there is a
* problem with IPv6 header, it will be silently dropped and d_len will
* be set to zero. Oddly, ipv6_input() will return OK in this case.
*/
return ipv6_input(&ieee->i_dev);
}
/****************************************************************************
* Public Functions
****************************************************************************/
@@ -87,30 +238,117 @@ static bool sixlowpan_isbroadcast(uint8_t mode, FAR uint8_t *addr)
* Name: sixlowpan_input
*
* Description:
* Process an incoming IP packet.
* Process an incoming 6loWPAN frame.
*
* This function is called when the device driver has received a 6loWPAN
* packet from the network. The packet from the device driver must be
* present in the d_buf buffer, and the length of the packet should be
* placed in the d_len field.
* frame from the network. The frame from the device driver must be
* provided in a IOB present in the i_framelist: The frame data is in the
* IOB io_data[] buffer and the length of the frame is in the IOB io_len
* field. Only a single IOB is expected in the i_framelist. This incoming
* data will be processed one frame at a time.
*
* When the function returns, there may be an outbound packet placed
* in the d_buf packet buffer. If so, the d_len field is set to
* the length of the packet. If no packet is to be sent out, the
* d_len field is set to 0.
* An non-NULL d_buf of size CONFIG_NET_6LOWPAN_MTU must also be provided.
* The frame will be decompressed and placed in the d_buf. Fragmented
* packets will also be reassembled in the d_buf as they are received
* (meaning for the driver, that two packet buffers are required: One for
* reassembly of RX packets and one used for TX polling).
*
* After each frame is processed into d_buf, the IOB is removed and
* deallocated. i_framelist will be nullified. If reassembly is
* incomplete, this function will return to called with i_framelist
* equal to NULL. The partially reassembled packet must be preserved by
* the IEEE802.15.4 MAC and provided again when the next frame is
* received.
*
* When the packet in the d_buf is fully reassembled, it will be provided
* to the network as with any other received packet. d_len will be set
* the the length of the uncompressed, reassembled packet.
*
* After the network processes the packet, d_len will be set to zero.
* Network logic may also decide to send a response to the packet. In
* that case, the outgoing network packet will be placed in d_buf the
* d_buf and d_len will be set to a non-zero value. That case is handled
* by this function.
*
* If that case occurs, the packet will be converted to a list of
* compressed and possibly fragmented frames in i_framelist as with other
* TX operations.
*
* So from the standpoint of the IEEE802.15.4 MAC driver, there are two
* possible results: (1) i_framelist is NULL meaning that the frame
* was fully processed and freed, or (2) i_framelist is non-NULL meaning
* that there are outgoing frame(s) to be sent.
*
* Input Parameters:
* dev - The IEEE802.15.4 MAC network driver interface.
* ieee - The IEEE802.15.4 MAC network driver interface.
*
* Returned Value:
* Ok is returned on success; Othewise a negated errno value is returned.
*
****************************************************************************/
int sixlowpan_input(FAR struct net_driver_s *dev)
int sixlowpan_input(FAR struct ieee802154_driver_s *ieee)
{
/* REVISIT: To be provided */
return -ENOSYS;
int ret = -EINVAL;
DEBUGASSERT(ieee != NULL && !FRAME_IOB_EMPTY(ieee));
/* Verify that an IOB is provided in the device structure */
while (!FRAME_IOB_EMPTY(ieee))
{
FAR struct iob_s *iob;
/* Remove the IOB containing the frame from the device structure */
FRAME_IOB_REMOVE(ieee, iob);
DEBUGASSERT(iob != NULL);
/* Process the frame, decompressing it into the packet buffer */
ret = sixlowpan_frame_process(ieee, iob);
/* Was the frame successfully processed? Is the packet in d_buf fully
* reassembled?
*/
if (ret == INPUT_COMPLETE)
{
/* Inject the uncompressed, reassembled packet into the network */
ret = sixlowpan_dispatch(ieee);
if (ret >= 0)
{
/* Check if this resulted in a request to send an outgoing
* packet.
*/
if (ieee->i_dev.d_len > 0)
{
FAR struct ipv6_hdr_s *ipv6hdr;
struct rimeaddr_s destmac;
/* The IPv6 header followed by TCP or UDP headers should
* lie at the beginning of d_buf since there is no link
* layer protocol header.
*/
ipv6hdr = (FAR struct ipv6_hdr_s *)(ieee->i_dev.d_buf);
/* Get the Rime MAC address of the destination */
#warning Missing logic
/* Convert the outgoing packet into a frame list. */
ret = sixlowpan_queue_frames(ieee, ipv6hdr, ieee->i_dev.d_buf,
ieee->i_dev.d_len, &destmac);
ieee->i_dev.d_len = 0;
}
}
}
}
return ret;
}
#endif /* CONFIG_NET_6LOWPAN */
+231 -49
View File
@@ -63,6 +63,7 @@
#include <nuttx/net/tcp.h>
#include <nuttx/net/udp.h>
#include <nuttx/net/icmpv6.h>
#include <nuttx/net/sixlowpan.h>
#ifdef CONFIG_NET_6LOWPAN
@@ -81,30 +82,45 @@
#define rimeaddr_cmp(addr1,addr2) \
(memcmp(addr1, addr2, CONFIG_NET_6LOWPAN_RIMEADDR_SIZE) == 0)
/* Frame buffer helpers */
/* Pointers in the Rime buffer */
#define FRAME_RESET(ieee) \
do \
{ \
(ieee)->i_dataoffset = 0; \
(ieee)->i_framelen = 0; \
} \
while (0)
/* Fragment header.
*
* The fragment header is used when the payload is too large to fit in a
* single IEEE 802.15.4 frame. The fragment header contains three fields:
* Datagram size, datagram tag and datagram offset.
*
* 1. Datagram size describes the total (un-fragmented) payload.
* 2. Datagram tag identifies the set of fragments and is used to match
* fragments of the same payload.
* 3. Datagram offset identifies the fragments offset within the un-
* fragmented payload.
*
* The fragment header length is 4 bytes for the first header and 5
* bytes for all subsequent headers.
*/
#define FRAME_HDR_START(ieee) \
((ieee)->i_frame)
#define FRAME_HDR_SIZE(ieee) \
((ieee)->i_dataoffset)
#define RIME_FRAG_PTR g_rimeptr
#define RIME_FRAG_DISPATCH_SIZE 0 /* 16 bit */
#define RIME_FRAG_TAG 2 /* 16 bit */
#define RIME_FRAG_OFFSET 4 /* 8 bit */
#define FRAME_DATA_START(ieee) \
((FAR uint8_t *)((ieee)->i_frame) + (ieee)->i_dataoffset)
#define FRAME_DATA_SIZE(ieee) \
((ieee)->i_framelen - (ieee)->i_dataoffset)
/* Define the Rime buffer as a byte array */
#define FRAME_REMAINING(ieee) \
(CONFIG_NET_6LOWPAN_FRAMELEN - (ieee)->i_framelen)
#define FRAME_SIZE(ieee) \
((ieee)->i_framelen)
#define RIME_IPHC_BUF (g_rimeptr + g_rime_hdrlen)
#define RIME_HC1_PTR (g_rimeptr + g_rime_hdrlen)
#define RIME_HC1_DISPATCH 0 /* 8 bit */
#define RIME_HC1_ENCODING 1 /* 8 bit */
#define RIME_HC1_TTL 2 /* 8 bit */
#define RIME_HC1_HC_UDP_PTR (g_rimeptr + g_rime_hdrlen)
#define RIME_HC1_HC_UDP_DISPATCH 0 /* 8 bit */
#define RIME_HC1_HC_UDP_HC1_ENCODING 1 /* 8 bit */
#define RIME_HC1_HC_UDP_UDP_ENCODING 2 /* 8 bit */
#define RIME_HC1_HC_UDP_TTL 3 /* 8 bit */
#define RIME_HC1_HC_UDP_PORTS 4 /* 8 bit */
#define RIME_HC1_HC_UDP_CHKSUM 5 /* 16 bit */
/* These are some definitions of element values used in the FCF. See the
* IEEE802.15.4 spec for details.
@@ -133,6 +149,94 @@
#define FRAME802154_SECURITY_LEVEL_NONE 0
#define FRAME802154_SECURITY_LEVEL_128 3
/* Packet buffer Definitions */
#define PACKETBUF_HDR_SIZE 48
#define PACKETBUF_ATTR_PACKET_TYPE_DATA 0
#define PACKETBUF_ATTR_PACKET_TYPE_ACK 1
#define PACKETBUF_ATTR_PACKET_TYPE_STREAM 2
#define PACKETBUF_ATTR_PACKET_TYPE_STREAM_END 3
#define PACKETBUF_ATTR_PACKET_TYPE_TIMESTAMP 4
/* Packet buffer attributes (indices into i_pktattr) */
#define PACKETBUF_ATTR_NONE 0
/* Scope 0 attributes: used only on the local node. */
#define PACKETBUF_ATTR_CHANNEL 1
#define PACKETBUF_ATTR_NETWORK_ID 2
#define PACKETBUF_ATTR_LINK_QUALITY 3
#define PACKETBUF_ATTR_RSSI 4
#define PACKETBUF_ATTR_TIMESTAMP 5
#define PACKETBUF_ATTR_RADIO_TXPOWER 6
#define PACKETBUF_ATTR_LISTEN_TIME 7
#define PACKETBUF_ATTR_TRANSMIT_TIME 8
#define PACKETBUF_ATTR_MAX_MAC_TRANSMISSIONS 9
#define PACKETBUF_ATTR_MAC_SEQNO 10
#define PACKETBUF_ATTR_MAC_ACK 11
/* Scope 1 attributes: used between two neighbors only. */
#define PACKETBUF_ATTR_RELIABLE 12
#define PACKETBUF_ATTR_PACKET_ID 13
#define PACKETBUF_ATTR_PACKET_TYPE 14
#define PACKETBUF_ATTR_REXMIT 15
#define PACKETBUF_ATTR_MAX_REXMIT 16
#define PACKETBUF_ATTR_NUM_REXMIT 17
#define PACKETBUF_ATTR_PENDING 18
/* Scope 2 attributes: used between end-to-end nodes. */
#define PACKETBUF_ATTR_HOPS 11
#define PACKETBUF_ATTR_TTL 20
#define PACKETBUF_ATTR_EPACKET_ID 21
#define PACKETBUF_ATTR_EPACKET_TYPE 22
#define PACKETBUF_ATTR_ERELIABLE 23
#define PACKETBUF_NUM_ATTRS 24
/* Addresses (indices into i_pktaddr) */
#define PACKETBUF_ADDR_SENDER 0
#define PACKETBUF_ADDR_RECEIVER 1
#define PACKETBUF_ADDR_ESENDER 2
#define PACKETBUF_ADDR_ERECEIVER 3
#define PACKETBUF_NUM_ADDRS 4
/* Frame buffer helpers *****************************************************/
#define FRAME_RESET() \
do \
{ \
g_dataoffset = 0; \
} \
while (0)
#define FRAME_HDR_START(iob) ((iob)->io_data)
#define FRAME_HDR_SIZE(iob) g_dataoffset
#define FRAME_DATA_START(iob) ((FAR uint8_t *)((iob)->io_data) + g_dataoffset)
#define FRAME_DATA_SIZE(iob) ((iob)->io_len - g_dataoffset)
#define FRAME_REMAINING(iob) (CONFIG_NET_6LOWPAN_FRAMELEN - (iob)->io_len)
#define FRAME_SIZE(ieee,iob) \
((iob)->io_len)
/* General helper macros ****************************************************/
#define GETINT16(ptr,index) \
((((uint16_t)((ptr)[index]) << 8)) | ((uint16_t)(((ptr)[(index) + 1]))))
#define PUTINT16(ptr,index,value) \
do \
{ \
(ptr)[index] = ((uint16_t)(value) >> 8) & 0xff; \
(ptr)[index + 1] = (uint16_t)(value) & 0xff; \
} \
while(0)
/****************************************************************************
* Public Types
****************************************************************************/
@@ -236,12 +340,51 @@ struct frame802154_s
struct sixlowpan_nhcompressor_s; /* Foward reference */
extern FAR struct sixlowpan_nhcompressor_s *g_sixlowpan_compressor;
#ifdef CONFIG_NET_6LOWPAN_SNIFFER
/* Rime Sniffer support for one single listener to enable trace of IP */
/* The following data values are used to hold intermediate settings while
* processing IEEE802.15.4 frames. These globals are shared with incoming
* and outgoing frame processing and possibly with mutliple IEEE802.15.4 MAC
* devices. The network lock provides exclusive use of these globals
* during that processing
*/
struct sixlowpan_rime_sniffer_s; /* Foward reference */
extern FAR struct sixlowpan_rime_sniffer_s *g_sixlowpan_sniffer;
#endif
/* A pointer to the rime buffer.
*
* We initialize it to the beginning of the rime buffer, then access
* different fields by updating the offset ieee->g_rime_hdrlen.
*/
extern FAR uint8_t *g_rimeptr;
/* The length of the payload in the Rime buffer.
*
* The payload is what comes after the compressed or uncompressed headers
* (can be the IP payload if the IP header only is compressed or the UDP
* payload if the UDP header is also compressed)
*/
extern uint8_t g_rime_payloadlen;
/* g_uncomp_hdrlen is the length of the headers before compression (if HC2
* is used this includes the UDP header in addition to the IP header).
*/
extern uint8_t g_uncomp_hdrlen;
/* g_rime_hdrlen is the total length of (the processed) 6lowpan headers
* (fragment headers, IPV6 or HC1, HC2, and HC1 and HC2 non compressed
* fields).
*/
extern uint8_t g_rime_hdrlen;
/* Offset first available byte for the payload after header region. */
uint8_t g_dataoffset;
/* Packet buffer metadata: Attributes and addresses */
extern uint16_t g_pktattrs[PACKETBUF_NUM_ATTRS];
extern struct rimeaddr_s g_pktaddrs[PACKETBUF_NUM_ADDRS];
/****************************************************************************
* Public Types
@@ -254,6 +397,7 @@ extern FAR struct sixlowpan_rime_sniffer_s *g_sixlowpan_sniffer;
struct net_driver_s; /* Forward reference */
struct ieee802154_driver_s; /* Forward reference */
struct rimeaddr_s; /* Forward reference */
struct iob_s; /* Forward reference */
/****************************************************************************
* Name: sixlowpan_send
@@ -263,19 +407,19 @@ struct rimeaddr_s; /* Forward reference */
* it to be sent on an 802.15.4 network using 6lowpan. Called from common
* UDP/TCP send logic.
*
* The payload data is in the caller 'buf' and is of length 'len'.
* Compressed headers will be added and if necessary the packet is
* fragmented. The resulting packet/fragments are put in dev->d_buf and
* the first frame will be delivered to the 802.15.4 MAC. via ieee->i_frame.
*
* Input Parmeters:
* The payload data is in the caller 'buf' and is of length 'len'.
* Compressed headers will be added and if necessary the packet is
* fragmented. The resulting packet/fragments are put in ieee->i_framelist
* and the entire list of frames will be delivered to the 802.15.4 MAC via
* ieee->i_framelist.
*
* Input Parameters:
* dev - The IEEE802.15.4 MAC network driver interface.
* ipv6 - IPv6 plus TCP or UDP headers.
* buf - Data to send
* len - Length of data to send
* raddr - The MAC address of the destination
* dev - The IEEE802.15.4 MAC network driver interface.
* ipv6 - IPv6 plus TCP or UDP headers.
* buf - Data to send
* len - Length of data to send
* raddr - The MAC address of the destination
* timeout - Send timeout in deciseconds
*
* Returned Value:
* Ok is returned on success; Othewise a negated errno value is returned.
@@ -290,7 +434,8 @@ struct rimeaddr_s; /* Forward reference */
int sixlowpan_send(FAR struct net_driver_s *dev,
FAR const struct ipv6_hdr_s *ipv6, FAR const void *buf,
size_t len, FAR const struct rimeaddr_s *raddr);
size_t len, FAR const struct rimeaddr_s *raddr,
uint16_t timeout);
/****************************************************************************
* Function: sixlowpan_hdrlen
@@ -323,6 +468,7 @@ int sixlowpan_hdrlen(FAR struct ieee802154_driver_s *ieee,
*
* Input parameters:
* ieee - A reference IEEE802.15.4 MAC network device structure.
* iob - The IOB in which to create the frame.
* dest_panid - PAN ID of the destination. May be 0xffff if the destination
* is not associated.
*
@@ -333,7 +479,44 @@ int sixlowpan_hdrlen(FAR struct ieee802154_driver_s *ieee,
****************************************************************************/
int sixlowpan_framecreate(FAR struct ieee802154_driver_s *ieee,
uint16_t dest_panid);
FAR struct iob_s *iob, uint16_t dest_panid);
/****************************************************************************
* Name: sixlowpan_queue_frames
*
* Description:
* Process an outgoing UDP or TCP packet. This function is called from
* send interrupt logic when a TX poll is received. It formates the
* list of frames to be sent by the IEEE802.15.4 MAC driver.
*
* The payload data is in the caller 's_buf' and is of length 's_len'.
* Compressed headers will be added and if necessary the packet is
* fragmented. The resulting packet/fragments are put in ieee->i_framelist
* and the entire list of frames will be delivered to the 802.15.4 MAC via
* ieee->i_framelist.
*
* Input Parameters:
* ieee - The IEEE802.15.4 MAC driver instance
* ipv6hdr - IPv6 header followed by TCP or UDP header.
* buf - Data to send
* len - Length of data to send
* destmac - The IEEE802.15.4 MAC address of the destination
*
* Returned Value:
* Ok is returned on success; Othewise a negated errno value is returned.
* This function is expected to fail if the driver is not an IEEE802.15.4
* MAC network driver. In that case, the UDP/TCP will fall back to normal
* IPv4/IPv6 formatting.
*
* Assumptions:
* Called with the network locked.
*
****************************************************************************/
int sixlowpan_queue_frames(FAR struct ieee802154_driver_s *ieee,
FAR const struct ipv6_hdr_s *ipv6hdr,
FAR const void *buf, size_t len,
FAR const struct rimeaddr_s *destmac);
/****************************************************************************
* Name: sixlowpan_hc06_initialize
@@ -375,7 +558,7 @@ void sixlowpan_hc06_initialize(void);
* compression
*
* Input Parameters:
* dev - A reference to the IEE802.15.4 network device state
* ieee - A reference to the IEE802.15.4 network device state
* destaddr - L2 destination address, needed to compress IP dest
*
* Returned Value:
@@ -384,7 +567,7 @@ void sixlowpan_hc06_initialize(void);
****************************************************************************/
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
void sixlowpan_compresshdr_hc06(FAR struct net_driver_s *dev,
void sixlowpan_compresshdr_hc06(FAR struct ieee802154_driver_s *dev,
FAR struct rimeaddr_s *destaddr);
#endif
@@ -402,7 +585,7 @@ void sixlowpan_compresshdr_hc06(FAR struct net_driver_s *dev,
* appropriate values
*
* Input Parmeters:
* dev - A reference to the IEE802.15.4 network device state
* ieee - A reference to the IEE802.15.4 network device state
* iplen - Equal to 0 if the packet is not a fragment (IP length is then
* inferred from the L2 length), non 0 if the packet is a 1st
* fragment.
@@ -413,7 +596,7 @@ void sixlowpan_compresshdr_hc06(FAR struct net_driver_s *dev,
****************************************************************************/
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC06
void sixlowpan_uncompresshdr_hc06(FAR struct net_driver_s *dev,
void sixlowpan_uncompresshdr_hc06(FAR struct ieee802154_driver_s *ieee,
uint16_t iplen);
#endif
@@ -428,7 +611,7 @@ void sixlowpan_uncompresshdr_hc06(FAR struct net_driver_s *dev,
* uip_buf buffer.
*
* Input Parmeters:
* dev - A reference to the IEE802.15.4 network device state
* ieee - A reference to the IEE802.15.4 network device state
* destaddr - L2 destination address, needed to compress the IP
* destination field
*
@@ -438,7 +621,7 @@ void sixlowpan_uncompresshdr_hc06(FAR struct net_driver_s *dev,
****************************************************************************/
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1
void sixlowpan_compresshdr_hc1(FAR struct net_driver_s *dev,
void sixlowpan_compresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
FAR struct rimeaddr_s *destaddr);
#endif
@@ -455,7 +638,7 @@ void sixlowpan_compresshdr_hc1(FAR struct net_driver_s *dev,
* are set to the appropriate values
*
* Input Parameters:
* dev - A reference to the IEE802.15.4 network device state
* ieee - A reference to the IEE802.15.4 network device state
* iplen - Equal to 0 if the packet is not a fragment (IP length is then
* inferred from the L2 length), non 0 if the packet is a 1st
* fragment.
@@ -466,7 +649,7 @@ void sixlowpan_compresshdr_hc1(FAR struct net_driver_s *dev,
****************************************************************************/
#ifdef CONFIG_NET_6LOWPAN_COMPRESSION_HC1
void sixlowpan_uncompresshdr_hc1(FAR struct net_driver_s *dev,
void sixlowpan_uncompresshdr_hc1(FAR struct ieee802154_driver_s *ieee,
uint16_t ip_len);
#endif
@@ -474,12 +657,11 @@ void sixlowpan_uncompresshdr_hc1(FAR struct net_driver_s *dev,
* Name: sixlowpan_frame_hdralloc
*
* Description:
* Allocate space for a header within the frame buffer (i_frame).
* Allocate space for a header within the frame buffer (IOB).
*
****************************************************************************/
int sixlowpan_frame_hdralloc(FAR struct ieee802154_driver_s *ieee,
int size);
int sixlowpan_frame_hdralloc(FAR struct iob_s *iob, int size);
#endif /* CONFIG_NET_6LOWPAN */
#endif /* _NET_SIXLOWPAN_SIXLOWPAN_INTERNAL_H */
File diff suppressed because it is too large Load Diff
+21 -5
View File
@@ -44,8 +44,6 @@
#include <debug.h>
#include "nuttx/net/netdev.h"
#include "nuttx/net/tcp.h"
#include "nuttx/net/sixlowpan.h"
#include "netdev/netdev.h"
#include "socket/socket.h"
@@ -87,7 +85,8 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf,
FAR struct tcp_conn_s *conn;
FAR struct net_driver_s *dev;
struct ipv6tcp_hdr_s ipv6tcp;
struct rimeaddr_s dest;
struct rimeaddr_s destmac;
uint16_t timeout;
int ret;
DEBUGASSERT(psock != NULL && psock->s_crefs > 0);
@@ -128,14 +127,22 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf,
#ifdef CONFIG_NETDEV_MULTINIC
dev = netdev_findby_ipv6addr(conn->u.ipv6.laddr, conn->u.ipv6.raddr);
if (dev == NULL || dev->d_lltype != NET_LL_IEEE805154)
#ifdef CONFIG_NETDEV_MULTILINK
if (dev == NULL || dev->d_lltype != NET_LL_IEEE802154)
#else
if (dev == NULL)
#endif
{
nwarn("WARNING: Not routable or not IEEE802.15.4 MAC\n");
return (ssize_t)-ENETUNREACH;
}
#else
dev = netdev_findby_ipv6addr(conn->u.ipv6.raddr);
#ifdef CONFIG_NETDEV_MULTILINK
if (dev == NULL || dev->d_lltype != NET_LL_IEEE802154)
#else
if (dev == NULL)
#endif
{
nwarn("WARNING: Not routable\n");
return (ssize_t)-ENETUNREACH;
@@ -167,13 +174,22 @@ ssize_t psock_6lowpan_tcp_send(FAR struct socket *psock, FAR const void *buf,
* packet.
*/
#ifdef CONFIG_NET_SOCKOPTS
timeout = psock->s_sndtimeo;
#else
timeout = 0;
#endif
ret = sixlowpan_send(dev, (FAR const struct ipv6_hdr_s *)&ipv6tcp,
buf, len, &dest);
buf, len, &destmac, timeout);
if (ret < 0)
{
nerr("ERROR: sixlowpan_send() failed: %d\n", ret);
}
/* Set the socket state to idle */
psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_IDLE);
return ret;
}
+21 -5
View File
@@ -44,8 +44,6 @@
#include <debug.h>
#include "nuttx/net/netdev.h"
#include "nuttx/net/udp.h"
#include "nuttx/net/sixlowpan.h"
#include "netdev/netdev.h"
#include "socket/socket.h"
@@ -87,7 +85,8 @@ ssize_t psock_6lowpan_udp_send(FAR struct socket *psock, FAR const void *buf,
FAR struct udp_conn_s *conn;
FAR struct net_driver_s *dev;
struct ipv6udp_hdr_s ipv6udp;
struct rimeaddr_s dest;
struct rimeaddr_s destmac;
uint16_t timeout;
int ret;
DEBUGASSERT(psock != NULL && psock->s_crefs > 0);
@@ -129,14 +128,22 @@ ssize_t psock_6lowpan_udp_send(FAR struct socket *psock, FAR const void *buf,
#ifdef CONFIG_NETDEV_MULTINIC
dev = netdev_findby_ipv6addr(conn->u.ipv6.laddr, conn->u.ipv6.raddr);
if (dev == NULL || dev->d_lltype != NET_LL_IEEE805154)
#ifdef CONFIG_NETDEV_MULTILINK
if (dev == NULL || dev->d_lltype != NET_LL_IEEE802154)
#else
if (dev == NULL)
#endif
{
nwarn("WARNING: Not routable or not IEEE802.15.4 MAC\n");
return (ssize_t)-ENETUNREACH;
}
#else
dev = netdev_findby_ipv6addr(conn->u.ipv6.raddr);
#ifdef CONFIG_NETDEV_MULTILINK
if (dev == NULL || dev->d_lltype != NET_LL_IEEE802154)
#else
if (dev == NULL)
#endif
{
nwarn("WARNING: Not routable\n");
return (ssize_t)-ENETUNREACH;
@@ -168,13 +175,22 @@ ssize_t psock_6lowpan_udp_send(FAR struct socket *psock, FAR const void *buf,
* packet.
*/
#ifdef CONFIG_NET_SOCKOPTS
timeout = psock->s_sndtimeo;
#else
timeout = 0;
#endif
ret = sixlowpan_send(dev, (FAR const struct ipv6_hdr_s *)&ipv6udp,
buf, len, &dest);
buf, len, &destmac, timeout);
if (ret < 0)
{
nerr("ERROR: sixlowpan_send() failed: %d\n", ret);
}
/* Set the socket state to idle */
psock->s_flags = _SS_SETSTATE(psock->s_flags, _SF_IDLE);
return ret;
}
+9 -10
View File
@@ -44,15 +44,17 @@
* SUCH DAMAGE.
*
****************************************************************************/
/* Frame Organization:
/* Frame Organization. The IOB data is retained in the io_data[] field of the
* IOB structure like:
*
* Content Offset
* +------------------+ 0
* | Frame Header |
* +------------------+ i_dataoffset
* +------------------+ g_dataoffset
* | Procotol Headers |
* | Data Payload |
* +------------------+ i_framelen
* +------------------+ iob->io_len
* | Unused |
* +------------------+ CONFIG_NET_6LOWPAN_FRAMELEN
*/
@@ -66,8 +68,6 @@
#include <string.h>
#include <errno.h>
#include "nuttx/net/sixlowpan.h"
#include "sixlowpan/sixlowpan_internal.h"
#ifdef CONFIG_NET_6LOWPAN
@@ -84,13 +84,12 @@
*
****************************************************************************/
int sixlowpan_frame_hdralloc(FAR struct ieee802154_driver_s *ieee,
int size)
int sixlowpan_frame_hdralloc(FAR struct iob_s *iob, int size)
{
if (size <= FRAME_REMAINING(ieee))
if (size <= FRAME_REMAINING(iob))
{
ieee->i_dataoffset += size;
ieee->i_framelen += size;
g_dataoffset += size;
iob->io_len += size;
return OK;
}
+4 -1
View File
@@ -42,7 +42,10 @@ SOCK_CSRCS += net_dupsd2.c net_clone.c net_poll.c net_vfcntl.c
# TCP/IP support
ifeq ($(CONFIG_NET_TCP),y)
SOCK_CSRCS += listen.c accept.c net_monitor.c
SOCK_CSRCS += listen.c accept.c
ifneq ($(CONFIG_NET_TCP_NO_STACK),y)
SOCK_CSRCS += net_monitor.c
endif
# Local Unix domain support
+17
View File
@@ -54,6 +54,7 @@
#include "tcp/tcp.h"
#include "local/local.h"
#include "socket/socket.h"
#include "usrsock/usrsock.h"
/****************************************************************************
* Public Functions
@@ -129,7 +130,9 @@ int psock_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
FAR socklen_t *addrlen, FAR struct socket *newsock)
{
int errcode;
#ifdef NET_TCP_HAVE_STACK
int ret;
#endif
DEBUGASSERT(psock != NULL);
@@ -141,6 +144,13 @@ int psock_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
if (psock->s_type != SOCK_STREAM)
{
#ifdef CONFIG_NET_USRSOCK
if (psock->s_type == SOCK_USRSOCK_TYPE)
{
#warning "Missing logic"
}
#endif
errcode = EOPNOTSUPP;
goto errout;
}
@@ -238,6 +248,7 @@ int psock_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
else
#endif
{
#ifdef NET_TCP_HAVE_STACK
/* Perform the local accept operation (with the network locked) */
net_lock();
@@ -267,6 +278,10 @@ int psock_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
}
net_unlock();
#else
errcode = EOPNOTSUPP;
goto errout;
#endif /* NET_TCP_HAVE_STACK */
}
#endif /* CONFIG_NET_TCP */
@@ -278,8 +293,10 @@ int psock_accept(FAR struct socket *psock, FAR struct sockaddr *addr,
leave_cancellation_point();
return OK;
#ifdef NET_TCP_HAVE_STACK
errout_after_accept:
psock_close(newsock);
#endif
errout:
set_errno(errcode);
+24
View File
@@ -46,6 +46,7 @@
#include <errno.h>
#include <string.h>
#include <debug.h>
#include <assert.h>
#ifdef CONFIG_NET_PKT
# include <netpacket/packet.h>
@@ -60,6 +61,7 @@
#include "udp/udp.h"
#include "pkt/pkt.h"
#include "local/local.h"
#include "usrsock/usrsock.h"
/****************************************************************************
* Private Functions
@@ -212,6 +214,20 @@ int psock_bind(FAR struct socket *psock, const struct sockaddr *addr,
switch (psock->s_type)
{
#ifdef CONFIG_NET_USRSOCK
case SOCK_USRSOCK_TYPE:
{
FAR struct usrsock_conn_s *conn = psock->s_conn;
DEBUGASSERT(conn);
/* Perform the usrsock bind operation */
ret = usrsock_bind(conn, addr, addrlen);
}
break;
#endif
#ifdef CONFIG_NET_PKT
case SOCK_RAW:
ret = pkt_bind(psock->s_conn, lladdr);
@@ -243,9 +259,13 @@ int psock_bind(FAR struct socket *psock, const struct sockaddr *addr,
else
#endif
{
#ifdef NET_TCP_HAVE_STACK
/* Bind the TCP/IP connection structure */
ret = tcp_bind(psock->s_conn, addr);
#else
ret = -ENOSYS;
#endif
}
#endif /* CONFIG_NET_TCP */
@@ -284,9 +304,13 @@ int psock_bind(FAR struct socket *psock, const struct sockaddr *addr,
else
#endif
{
#ifdef NET_UDP_HAVE_STACK
/* Bind the UDPP/IP connection structure */
ret = udp_bind(psock->s_conn, addr);
#else
ret = -ENOSYS;
#endif
}
#endif /* CONFIG_NET_UDP */
+43 -13
View File
@@ -62,12 +62,13 @@
#include "udp/udp.h"
#include "local/local.h"
#include "socket/socket.h"
#include "usrsock/usrsock.h"
/****************************************************************************
* Private Types
****************************************************************************/
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
struct tcp_connect_s
{
FAR struct tcp_conn_s *tc_conn; /* Reference to TCP connection structure */
@@ -82,7 +83,7 @@ struct tcp_connect_s
* Private Function Prototypes
****************************************************************************/
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
static inline int psock_setup_callbacks(FAR struct socket *psock,
FAR struct tcp_connect_s *pstate);
static void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate,
@@ -92,7 +93,7 @@ static uint16_t psock_connect_interrupt(FAR struct net_driver_s *dev,
uint16_t flags);
static inline int psock_tcp_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr);
#endif /* CONFIG_NET_TCP */
#endif /* NET_TCP_HAVE_STACK */
/****************************************************************************
* Private Functions
@@ -101,7 +102,7 @@ static inline int psock_tcp_connect(FAR struct socket *psock,
* Name: psock_setup_callbacks
****************************************************************************/
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
static inline int psock_setup_callbacks(FAR struct socket *psock,
FAR struct tcp_connect_s *pstate)
{
@@ -137,13 +138,13 @@ static inline int psock_setup_callbacks(FAR struct socket *psock,
return ret;
}
#endif /* CONFIG_NET_TCP */
#endif /* NET_TCP_HAVE_STACK */
/****************************************************************************
* Name: psock_teardown_callbacks
****************************************************************************/
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
static void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate,
int status)
{
@@ -165,7 +166,7 @@ static void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate,
net_stopmonitor(conn);
}
}
#endif /* CONFIG_NET_TCP */
#endif /* NET_TCP_HAVE_STACK */
/****************************************************************************
* Name: psock_connect_interrupt
@@ -187,7 +188,7 @@ static void psock_teardown_callbacks(FAR struct tcp_connect_s *pstate,
*
****************************************************************************/
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
static uint16_t psock_connect_interrupt(FAR struct net_driver_s *dev,
FAR void *pvconn, FAR void *pvpriv,
uint16_t flags)
@@ -299,7 +300,7 @@ static uint16_t psock_connect_interrupt(FAR struct net_driver_s *dev,
else
#endif
{
pstate->tc_conn->mss = TCP_IPv4_INITIAL_MSS(dev);
pstate->tc_conn->mss = TCP_IPv6_INITIAL_MSS(dev);
}
#endif /* CONFIG_NET_IPv6 */
@@ -322,7 +323,7 @@ static uint16_t psock_connect_interrupt(FAR struct net_driver_s *dev,
return flags;
}
#endif /* CONFIG_NET_TCP */
#endif /* NET_TCP_HAVE_STACK */
/****************************************************************************
* Name: psock_tcp_connect
@@ -342,7 +343,7 @@ static uint16_t psock_connect_interrupt(FAR struct net_driver_s *dev,
*
****************************************************************************/
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
static inline int psock_tcp_connect(FAR struct socket *psock,
FAR const struct sockaddr *addr)
{
@@ -434,7 +435,7 @@ static inline int psock_tcp_connect(FAR struct socket *psock,
net_unlock();
return ret;
}
#endif /* CONFIG_NET_TCP */
#endif /* NET_TCP_HAVE_STACK */
/****************************************************************************
* Public Functions
@@ -512,7 +513,8 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
socklen_t addrlen)
{
FAR const struct sockaddr_in *inaddr = (FAR const struct sockaddr_in *)addr;
#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_UDP) || defined(CONFIG_NET_LOCAL)
#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_UDP) || \
defined(CONFIG_NET_LOCAL) || defined(CONFIG_NET_USRSOCK)
int ret;
#endif
int errcode;
@@ -570,6 +572,13 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
#endif
default:
#ifdef CONFIG_NET_USRSOCK
if (psock->s_type == SOCK_USRSOCK_TYPE)
{
break;
}
#endif
DEBUGPANIC();
errcode = EAFNOSUPPORT;
goto errout;
@@ -608,9 +617,13 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
else
#endif
{
#ifdef NET_TCP_HAVE_STACK
/* Connect the TCP/IP socket */
ret = psock_tcp_connect(psock, addr);
#else
ret = -ENOSYS;
#endif
}
#endif /* CONFIG_NET_TCP */
@@ -642,6 +655,7 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
else
#endif
{
#ifdef NET_UDP_HAVE_STACK
ret = udp_connect(psock->s_conn, addr);
if (ret < 0 || addr == NULL)
{
@@ -651,6 +665,9 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
{
psock->s_flags |= _SF_CONNECTED;
}
#else
ret = -ENOSYS;
#endif
}
#endif /* CONFIG_NET_UDP */
@@ -663,6 +680,19 @@ int psock_connect(FAR struct socket *psock, FAR const struct sockaddr *addr,
break;
#endif /* CONFIG_NET_UDP || CONFIG_NET_LOCAL_DGRAM */
#ifdef CONFIG_NET_USRSOCK
case SOCK_USRSOCK_TYPE:
{
ret = usrsock_connect(psock, addr, addrlen);
if (ret < 0)
{
errcode = -ret;
goto errout;
}
}
break;
#endif /* CONFIG_NET_USRSOCK */
default:
errcode = EBADF;
goto errout;
+30 -8
View File
@@ -44,6 +44,7 @@
#include <string.h>
#include <errno.h>
#include <assert.h>
#include <nuttx/net/net.h>
#include <nuttx/net/netdev.h>
@@ -54,6 +55,7 @@
#include "tcp/tcp.h"
#include "udp/udp.h"
#include "socket/socket.h"
#include "usrsock/usrsock.h"
#ifdef CONFIG_NET
@@ -92,7 +94,7 @@ int ipv4_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
FAR socklen_t *addrlen)
{
FAR struct net_driver_s *dev;
#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_UDP)
#if defined(NET_TCP_HAVE_STACK) || defined(NET_UDP_HAVE_STACK)
FAR struct sockaddr_in *outaddr = (FAR struct sockaddr_in *)addr;
#endif
#ifdef CONFIG_NETDEV_MULTINIC
@@ -116,7 +118,7 @@ int ipv4_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
switch (psock->s_type)
{
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
case SOCK_STREAM:
{
FAR struct tcp_conn_s *tcp_conn = (FAR struct tcp_conn_s *)psock->s_conn;
@@ -129,7 +131,7 @@ int ipv4_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
break;
#endif
#ifdef CONFIG_NET_UDP
#ifdef NET_UDP_HAVE_STACK
case SOCK_DGRAM:
{
FAR struct udp_conn_s *udp_conn = (FAR struct udp_conn_s *)psock->s_conn;
@@ -171,7 +173,7 @@ int ipv4_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
/* Set the address family and the IP address */
#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_UDP)
#if defined(NET_TCP_HAVE_STACK) || defined(NET_UDP_HAVE_STACK)
outaddr->sin_family = AF_INET;
outaddr->sin_addr.s_addr = dev->d_ipaddr;
*addrlen = sizeof(struct sockaddr_in);
@@ -215,7 +217,7 @@ int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
FAR socklen_t *addrlen)
{
FAR struct net_driver_s *dev;
#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_UDP)
#if defined(NET_TCP_HAVE_STACK) || defined(NET_UDP_HAVE_STACK)
FAR struct sockaddr_in6 *outaddr = (FAR struct sockaddr_in6 *)addr;
#endif
#ifdef CONFIG_NETDEV_MULTINIC
@@ -239,7 +241,7 @@ int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
switch (psock->s_type)
{
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
case SOCK_STREAM:
{
FAR struct tcp_conn_s *tcp_conn = (FAR struct tcp_conn_s *)psock->s_conn;
@@ -252,7 +254,7 @@ int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
break;
#endif
#ifdef CONFIG_NET_UDP
#ifdef NET_UDP_HAVE_STACK
case SOCK_DGRAM:
{
FAR struct udp_conn_s *udp_conn = (FAR struct udp_conn_s *)psock->s_conn;
@@ -294,7 +296,7 @@ int ipv6_getsockname(FAR struct socket *psock, FAR struct sockaddr *addr,
/* Set the address family and the IP address */
#if defined(CONFIG_NET_TCP) || defined(CONFIG_NET_UDP)
#if defined(NET_TCP_HAVE_STACK) || defined(NET_UDP_HAVE_STACK)
outaddr->sin6_family = AF_INET6;
memcpy(outaddr->sin6_addr.in6_u.u6_addr8, dev->d_ipv6addr, 16);
*addrlen = sizeof(struct sockaddr_in6);
@@ -371,6 +373,26 @@ int getsockname(int sockfd, FAR struct sockaddr *addr, FAR socklen_t *addrlen)
}
#endif
#ifdef CONFIG_NET_USRSOCK
if (psock->s_type == SOCK_USRSOCK_TYPE)
{
FAR struct usrsock_conn_s *conn = psock->s_conn;
DEBUGASSERT(conn);
/* Handle usrsock getsockname */
ret = usrsock_getsockname(conn, addr, addrlen);
if (ret < 0)
{
errcode = -ret;
goto errout;
}
return OK;
}
#endif
/* Handle by address domain */
switch (psock->s_domain)
+51
View File
@@ -43,9 +43,12 @@
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <debug.h>
#include <assert.h>
#include <errno.h>
#include "socket/socket.h"
#include "usrsock/usrsock.h"
#include "utils/utils.h"
/****************************************************************************
@@ -106,6 +109,40 @@ int psock_getsockopt(FAR struct socket *psock, int level, int option,
goto errout;
}
#ifdef CONFIG_NET_USRSOCK
if (psock->s_type == SOCK_USRSOCK_TYPE)
{
FAR struct usrsock_conn_s *conn = psock->s_conn;
int ret;
DEBUGASSERT(conn);
/* Some of the socket options are handled from this function. */
switch (option)
{
case SO_TYPE: /* Type can be read from NuttX psock structure. */
case SO_RCVTIMEO: /* Rx timeouts can be handled at NuttX side, thus
* simplify daemon implementation. */
case SO_SNDTIMEO: /* Rx timeouts can be handled at NuttX side, thus
* simplify daemon implementation. */
break;
default: /* Other options are passed to usrsock daemon. */
{
ret = usrsock_getsockopt(conn, level, option, value, value_len);
if (ret < 0)
{
errcode = -ret;
goto errout;
}
return OK;
}
}
}
#endif
/* Process the option */
switch (option)
@@ -159,6 +196,20 @@ int psock_getsockopt(FAR struct socket *psock, int level, int option,
goto errout;
}
#ifdef CONFIG_NET_USRSOCK
if (psock->s_type == SOCK_USRSOCK_TYPE)
{
FAR struct usrsock_conn_s *conn = psock->s_conn;
/* Return the actual socket type */
*(int*)value = conn->type;
*value_len = sizeof(int);
break;
}
#endif
/* Return the socket type */
*(FAR int *)value = psock->s_type;
+13
View File
@@ -48,6 +48,7 @@
#include "tcp/tcp.h"
#include "local/local.h"
#include "socket/socket.h"
#include "usrsock/usrsock.h"
/****************************************************************************
* Public Functions
@@ -92,6 +93,13 @@ int psock_listen(FAR struct socket *psock, int backlog)
if (psock->s_type != SOCK_STREAM || !psock->s_conn)
{
#ifdef CONFIG_NET_USRSOCK
if (psock->s_type == SOCK_USRSOCK_TYPE)
{
#warning "Missing logic"
}
#endif
errcode = EOPNOTSUPP;
goto errout;
}
@@ -118,6 +126,7 @@ int psock_listen(FAR struct socket *psock, int backlog)
else
#endif
{
#ifdef NET_TCP_HAVE_STACK
FAR struct tcp_conn_s *conn =
(FAR struct tcp_conn_s *)psock->s_conn;
@@ -143,6 +152,10 @@ int psock_listen(FAR struct socket *psock, int backlog)
*/
tcp_listen(conn);
#else
errcode = EOPNOTSUPP;
goto errout;
#endif /* NET_TCP_HAVE_STACK */
}
#endif /* CONFIG_NET_TCP */
+12 -2
View File
@@ -51,6 +51,7 @@
#include "tcp/tcp.h"
#include "udp/udp.h"
#include "socket/socket.h"
#include "usrsock/usrsock.h"
/****************************************************************************
* Public Functions
@@ -96,7 +97,7 @@ int net_clone(FAR struct socket *psock1, FAR struct socket *psock2)
DEBUGASSERT(psock2->s_conn);
psock2->s_crefs = 1; /* One reference on the new socket itself */
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
if (psock2->s_type == SOCK_STREAM)
{
FAR struct tcp_conn_s *conn = psock2->s_conn;
@@ -105,7 +106,7 @@ int net_clone(FAR struct socket *psock1, FAR struct socket *psock2)
}
else
#endif
#ifdef CONFIG_NET_UDP
#ifdef NET_UDP_HAVE_STACK
if (psock2->s_type == SOCK_DGRAM)
{
FAR struct udp_conn_s *conn = psock2->s_conn;
@@ -113,6 +114,15 @@ int net_clone(FAR struct socket *psock1, FAR struct socket *psock2)
conn->crefs++;
}
else
#endif
#ifdef CONFIG_NET_USRSOCK
if (psock2->s_type == SOCK_USRSOCK_TYPE)
{
FAR struct usrsock_conn_s *conn = psock2->s_conn;
DEBUGASSERT(conn->crefs > 0 && conn->crefs < 255);
conn->crefs++;
}
else
#endif
{
nerr("ERROR: Unsupported type: %d\n", psock2->s_type);
+53 -10
View File
@@ -67,12 +67,13 @@
#include "pkt/pkt.h"
#include "local/local.h"
#include "socket/socket.h"
#include "usrsock/usrsock.h"
/****************************************************************************
* Private Types
****************************************************************************/
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
struct tcp_close_s
{
FAR struct devif_callback_s *cl_cb; /* Reference to TCP callback instance */
@@ -106,7 +107,7 @@ struct tcp_close_s
*
****************************************************************************/
#if defined(CONFIG_NET_TCP) && defined(CONFIG_NET_SOLINGER)
#if defined(NET_TCP_HAVE_STACK) && defined(CONFIG_NET_SOLINGER)
static inline int close_timeout(FAR struct tcp_close_s *pstate)
{
FAR struct socket *psock = 0;
@@ -132,7 +133,7 @@ static inline int close_timeout(FAR struct tcp_close_s *pstate)
return FALSE;
}
#endif /* CONFIG_NET_SOCKOPTS && CONFIG_NET_SOLINGER */
#endif /* NET_TCP_HAVE_STACK && CONFIG_NET_SOLINGER */
/****************************************************************************
* Function: netclose_interrupt
@@ -151,7 +152,7 @@ static inline int close_timeout(FAR struct tcp_close_s *pstate)
*
****************************************************************************/
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
static uint16_t netclose_interrupt(FAR struct net_driver_s *dev,
FAR void *pvconn, FAR void *pvpriv,
uint16_t flags)
@@ -256,7 +257,7 @@ end_wait:
return 0;
#endif
}
#endif /* CONFIG_NET_TCP */
#endif /* NET_TCP_HAVE_STACK */
/****************************************************************************
* Function: netclose_txnotify
@@ -274,7 +275,7 @@ end_wait:
*
****************************************************************************/
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
static inline void netclose_txnotify(FAR struct socket *psock,
FAR struct tcp_conn_s *conn)
{
@@ -313,7 +314,7 @@ static inline void netclose_txnotify(FAR struct socket *psock,
}
#endif /* CONFIG_NET_IPv6 */
}
#endif /* CONFIG_NET_TCP */
#endif /* NET_TCP_HAVE_STACK */
/****************************************************************************
* Function: netclose_disconnect
@@ -332,7 +333,7 @@ static inline void netclose_txnotify(FAR struct socket *psock,
*
****************************************************************************/
#ifdef CONFIG_NET_TCP
#ifdef NET_TCP_HAVE_STACK
static inline int netclose_disconnect(FAR struct socket *psock)
{
struct tcp_close_s state;
@@ -451,7 +452,7 @@ static inline int netclose_disconnect(FAR struct socket *psock)
net_unlock();
return ret;
}
#endif /* CONFIG_NET_TCP */
#endif /* NET_TCP_HAVE_STACK */
/****************************************************************************
* Function: local_close
@@ -557,6 +558,7 @@ int psock_close(FAR struct socket *psock)
else
#endif
{
#ifdef NET_TCP_HAVE_STACK
FAR struct tcp_conn_s *conn = psock->s_conn;
/* Is this the last reference to the connection structure
@@ -592,6 +594,7 @@ int psock_close(FAR struct socket *psock)
conn->crefs--;
}
#endif /* NET_TCP_HAVE_STACK */
}
#endif /* CONFIG_NET_TCP || CONFIG_NET_LOCAL_STREAM */
}
@@ -617,6 +620,7 @@ int psock_close(FAR struct socket *psock)
else
#endif
{
#ifdef NET_UDP_HAVE_STACK
FAR struct udp_conn_s *conn = psock->s_conn;
/* Is this the last reference to the connection structure
@@ -636,6 +640,7 @@ int psock_close(FAR struct socket *psock)
conn->crefs--;
}
#endif /* NET_UDP_HAVE_STACK */
}
#endif /* CONFIG_NET_UDP || CONFIG_NET_LOCAL_DGRAM */
}
@@ -668,6 +673,44 @@ int psock_close(FAR struct socket *psock)
break;
#endif
#ifdef CONFIG_NET_USRSOCK
case SOCK_USRSOCK_TYPE:
{
FAR struct usrsock_conn_s *conn = psock->s_conn;
/* Is this the last reference to the connection structure (there
* could be more if the socket was dup'ed).
*/
if (conn->crefs <= 1)
{
/* Yes... inform user-space daemon of socket close. */
errcode = usrsock_close(conn);
/* Free the connection structure */
conn->crefs = 0;
usrsock_free(psock->s_conn);
if (errcode < 0)
{
/* Return with error code, but free resources. */
errcode = -errcode;
goto errout_with_psock;
}
}
else
{
/* No.. Just decrement the reference count */
conn->crefs--;
}
}
break;
#endif
default:
errcode = EBADF;
goto errout;
@@ -679,7 +722,7 @@ int psock_close(FAR struct socket *psock)
sock_release(psock);
return OK;
#ifdef CONFIG_NET_TCP
#if defined(NET_TCP_HAVE_STACK) || defined(CONFIG_NET_USRSOCK)
errout_with_psock:
sock_release(psock);
#endif
+4
View File
@@ -50,6 +50,8 @@
#include "tcp/tcp.h"
#include "socket/socket.h"
#ifdef NET_TCP_HAVE_STACK
/****************************************************************************
* Private Function Prototypes
****************************************************************************/
@@ -345,4 +347,6 @@ void net_lostconnection(FAR struct socket *psock, uint16_t flags)
net_unlock();
}
#endif /* NET_TCP_HAVE_STACK */
#endif /* CONFIG_NET && CONFIG_NET_TCP */

Some files were not shown because too many files have changed in this diff Show More