Merged in merlin17/nuttx/ieee802154 (pull request #349)
Removes radio IOCTL. Starts bringing radio and MAC closer with well-defined interface. Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
commit
2e946f71b0
@ -47,7 +47,6 @@
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/fs/fs.h>
|
||||
#include <nuttx/wireless/ieee802154/ieee802154_radio.h>
|
||||
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
||||
#include <nuttx/wireless/ieee802154/mrf24j40.h>
|
||||
|
||||
@ -84,8 +83,6 @@
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#define RADIO_DEVNAME "/dev/mrf24j40"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
@ -287,18 +284,7 @@ static int stm32_mrf24j40_devsetup(FAR struct stm32_priv_s *priv)
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
#elif defined(CONFIG_IEEE802154_DEV)
|
||||
/* Register a character driver to access the IEEE 802.15.4 radio from
|
||||
* user-space
|
||||
*/
|
||||
|
||||
ret = radio802154dev_register(radio, RADIO_DEVNAME);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: Failed to register the radio device %s: %d\n",
|
||||
RADIO_DEVNAME, ret);
|
||||
return ret;
|
||||
}
|
||||
#endif /* CONFIG_IEEE802154_MAC */
|
||||
|
||||
return OK;
|
||||
|
@ -148,7 +148,6 @@ static void at86rf23x_irqwork_tx(FAR struct at86rf23x_dev_s *dev);
|
||||
static void at86rf23x_irqworker(FAR void *arg);
|
||||
static int at86rf23x_interrupt(int irq, FAR void *context, FAR void *arg);
|
||||
|
||||
/* IOCTL helpers */
|
||||
|
||||
static int at86rf23x_setchannel(FAR struct ieee802154_radio_s *ieee,
|
||||
uint8_t chan);
|
||||
@ -187,8 +186,6 @@ static int at86rf23x_energydetect(FAR struct ieee802154_radio_s *ieee,
|
||||
|
||||
/* Driver operations */
|
||||
|
||||
static int at86rf23x_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd,
|
||||
unsigned long arg);
|
||||
static int at86rf23x_rxenable(FAR struct ieee802154_radio_s *ieee,
|
||||
bool state, FAR struct ieee802154_packet_s *packet);
|
||||
static int at86rf23x_transmit(FAR struct ieee802154_radio_s *ieee,
|
||||
@ -1147,100 +1144,6 @@ static int at86rf23x_energydetect(FAR struct ieee802154_radio_s *ieee,
|
||||
return ERROR;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: at86rf23x_ioctl
|
||||
*
|
||||
* Description:
|
||||
* Control operations for the radio.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int at86rf23x_ioctl(FAR struct ieee802154_radio_s *ieee, int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
FAR struct at86rf23x_dev_s *dev =
|
||||
(FAR struct at86rf23x_dev_s *)ieee;
|
||||
FAR union ieee802154_radioarg_u *u; =
|
||||
(FAR union ieee802154_radioarg_u *)((uintptr_t)arg)
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case PHY802154IOC_SET_CHAN:
|
||||
ret = at86rf23x_setchannel(ieee, u.channel);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_CHAN:
|
||||
ret = at86rf23x_getchannel(ieee, &u.channel);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_PANID:
|
||||
ret = at86rf23x_setpanid(ieee, u.panid);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_PANID:
|
||||
ret = at86rf23x_getpanid(ieee, &u.panid);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_SADDR:
|
||||
ret = at86rf23x_setsaddr(ieee, u.saddr);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_SADDR:
|
||||
ret = at86rf23x_getsaddr(ieee, &u.saddr);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_EADDR:
|
||||
ret = at86rf23x_seteaddr(ieee, u.eaddr);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_EADDR:
|
||||
ret = at86rf23x_geteaddr(ieee, u.eaddr);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_PROMISC:
|
||||
ret = at86rf23x_setpromisc(ieee, u.promisc);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_PROMISC:
|
||||
ret = at86rf23x_getpromisc(ieee, &u.promisc);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_DEVMODE:
|
||||
ret = at86rf23x_setdevmode(ieee, u.devmode);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_DEVMODE:
|
||||
ret = at86rf23x_getdevmode(ieee, &u.devmode);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_TXPWR:
|
||||
ret = at86rf23x_settxpower(ieee, u.txpwr);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_TXPWR:
|
||||
ret = at86rf23x_gettxpower(ieee, &u.txpwr);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_CCA:
|
||||
ret = at86rf23x_setcca(ieee, &u.cca);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_CCA:
|
||||
ret = at86rf23x_getcca(ieee, &u.cca);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_ENERGYDETECT:
|
||||
ret = at86rf23x_energydetect(ieee, &u.energy);
|
||||
break;
|
||||
|
||||
case 1000:
|
||||
return at86rf23x_regdump(dev);
|
||||
|
||||
default:
|
||||
return -ENOTTY;
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: at86rf23x_initialize
|
||||
*
|
||||
|
@ -2,6 +2,7 @@
|
||||
* drivers/wireless/ieee802154/mrf24j40.c
|
||||
*
|
||||
* Copyright (C) 2015-2016 Sebastien Lorquet. All rights reserved.
|
||||
* Copyright (C) 2017 Verge Inc. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
* Author: Anthony Merlino <anthony@vergeaero.com>
|
||||
*
|
||||
@ -90,6 +91,10 @@
|
||||
#define MRF24J40_RXMODE_PROMISC 1
|
||||
#define MRF24J40_RXMODE_NOCRC 2
|
||||
|
||||
#define MRF24J40_MODE_DEVICE 0
|
||||
#define MRF24J40_MODE_COORD 1
|
||||
#define MRF24J40_MODE_PANCOORD 2
|
||||
|
||||
/* Definitions for PA control on high power modules */
|
||||
|
||||
#define MRF24J40_PA_AUTO 1
|
||||
@ -125,9 +130,8 @@ struct mrf24j40_radio_s
|
||||
struct work_s pollwork; /* For deferring poll work to the work queue */
|
||||
sem_t exclsem; /* Exclusive access to this struct */
|
||||
|
||||
uint16_t panid; /* PAN identifier, FFFF = not set */
|
||||
uint16_t saddr; /* short address, FFFF = not set */
|
||||
uint8_t eaddr[8]; /* extended address, FFFFFFFFFFFFFFFF = not set */
|
||||
struct ieee802154_addr_s addr;
|
||||
|
||||
uint8_t channel; /* 11 to 26 for the 2.4 GHz band */
|
||||
uint8_t devmode; /* device mode: device, coord, pancoord */
|
||||
uint8_t paenabled; /* enable usage of PA */
|
||||
@ -181,7 +185,6 @@ static int mrf24j40_gts_setup(FAR struct mrf24j40_radio_s *dev, uint8_t gts,
|
||||
static int mrf24j40_setup_fifo(FAR struct mrf24j40_radio_s *dev,
|
||||
FAR struct iob_s *frame, uint32_t fifo_addr);
|
||||
|
||||
/* IOCTL helpers */
|
||||
|
||||
static int mrf24j40_setchannel(FAR struct mrf24j40_radio_s *radio,
|
||||
uint8_t chan);
|
||||
@ -196,7 +199,7 @@ static int mrf24j40_setsaddr(FAR struct mrf24j40_radio_s *radio,
|
||||
static int mrf24j40_getsaddr(FAR struct mrf24j40_radio_s *radio,
|
||||
FAR uint16_t *saddr);
|
||||
static int mrf24j40_seteaddr(FAR struct mrf24j40_radio_s *radio,
|
||||
FAR uint8_t *eaddr);
|
||||
FAR const uint8_t *eaddr);
|
||||
static int mrf24j40_geteaddr(FAR struct mrf24j40_radio_s *radio,
|
||||
FAR uint8_t *eaddr);
|
||||
static int mrf24j40_setpromisc(FAR struct mrf24j40_radio_s *radio,
|
||||
@ -222,11 +225,14 @@ static int mrf24j40_energydetect(FAR struct mrf24j40_radio_s *radio,
|
||||
|
||||
static int mrf24j40_bind(FAR struct ieee802154_radio_s *radio,
|
||||
FAR struct ieee802154_radiocb_s *radiocb);
|
||||
static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *radio, int cmd,
|
||||
unsigned long arg);
|
||||
static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio);
|
||||
static int mrf24j40_txnotify_csma(FAR struct ieee802154_radio_s *radio);
|
||||
static int mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio);
|
||||
static int mrf24j40_get_attr(FAR struct ieee802154_radio_s *radio,
|
||||
enum ieee802154_pib_attr_e pib_attr,
|
||||
FAR union ieee802154_attr_val_u *attr_value);
|
||||
static int mrf24j40_set_attr(FAR struct ieee802154_radio_s *radio,
|
||||
enum ieee802154_pib_attr_e pib_attr,
|
||||
FAR const union ieee802154_attr_val_u *attr_value);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
@ -242,14 +248,14 @@ static int mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio);
|
||||
static const struct ieee802154_radioops_s mrf24j40_devops =
|
||||
{
|
||||
mrf24j40_bind,
|
||||
mrf24j40_ioctl,
|
||||
mrf24j40_rxenable,
|
||||
mrf24j40_txnotify_csma,
|
||||
mrf24j40_txnotify_gts,
|
||||
mrf24j40_get_attr,
|
||||
mrf24j40_set_attr
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
* Radio Interface Functions
|
||||
****************************************************************************/
|
||||
|
||||
static int mrf24j40_bind(FAR struct ieee802154_radio_s *radio,
|
||||
@ -299,6 +305,103 @@ static int mrf24j40_txnotify_csma(FAR struct ieee802154_radio_s *radio)
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: mrf24j40_txnotify_gts
|
||||
*
|
||||
* Description:
|
||||
* Driver callback invoked when new TX data is available. This is a
|
||||
* stimulus perform an out-of-cycle poll and, thereby, reduce the TX
|
||||
* latency.
|
||||
*
|
||||
* Parameters:
|
||||
* radio - Reference to the radio driver state structure
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio)
|
||||
{
|
||||
FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio;
|
||||
|
||||
/* Is our single work structure available? It may not be if there are
|
||||
* pending interrupt actions and we will have to ignore the Tx
|
||||
* availability action.
|
||||
*/
|
||||
|
||||
if (work_available(&dev->pollwork))
|
||||
{
|
||||
/* Schedule to serialize the poll on the worker thread. */
|
||||
|
||||
work_queue(HPWORK, &dev->pollwork, mrf24j40_dopoll_gts, dev, 0);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
static int mrf24j40_get_attr(FAR struct ieee802154_radio_s *radio,
|
||||
enum ieee802154_pib_attr_e pib_attr,
|
||||
FAR union ieee802154_attr_val_u *attr_value)
|
||||
{
|
||||
FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio;
|
||||
int ret;
|
||||
|
||||
switch (pib_attr)
|
||||
{
|
||||
case IEEE802154_PIB_MAC_EXTENDED_ADDR:
|
||||
{
|
||||
memcpy(&attr_value->mac.eaddr[0], &dev->addr.eaddr[0], 8);
|
||||
ret = IEEE802154_STATUS_SUCCESS;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ret = IEEE802154_STATUS_UNSUPPORTED_ATTRIBUTE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int mrf24j40_set_attr(FAR struct ieee802154_radio_s *radio,
|
||||
enum ieee802154_pib_attr_e pib_attr,
|
||||
FAR const union ieee802154_attr_val_u *attr_value)
|
||||
{
|
||||
FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio;
|
||||
int ret;
|
||||
|
||||
switch (pib_attr)
|
||||
{
|
||||
case IEEE802154_PIB_MAC_EXTENDED_ADDR:
|
||||
{
|
||||
mrf24j40_seteaddr(dev, &attr_value->mac.eaddr[0]);
|
||||
ret = IEEE802154_STATUS_SUCCESS;
|
||||
}
|
||||
break;
|
||||
case IEEE802154_PIB_MAC_PROMISCUOUS_MODE:
|
||||
{
|
||||
if (attr_value->mac.promisc_mode)
|
||||
{
|
||||
mrf24j40_setrxmode(dev, MRF24J40_RXMODE_PROMISC);
|
||||
}
|
||||
else
|
||||
{
|
||||
mrf24j40_setrxmode(dev, MRF24J40_RXMODE_NORMAL);
|
||||
}
|
||||
|
||||
ret = IEEE802154_STATUS_SUCCESS;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
ret = IEEE802154_STATUS_UNSUPPORTED_ATTRIBUTE;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Internal Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Function: mrf24j40_dopoll_csma
|
||||
*
|
||||
@ -353,43 +456,6 @@ static void mrf24j40_dopoll_csma(FAR void *arg)
|
||||
sem_post(&dev->exclsem);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: mrf24j40_txnotify_gts
|
||||
*
|
||||
* Description:
|
||||
* Driver callback invoked when new TX data is available. This is a
|
||||
* stimulus perform an out-of-cycle poll and, thereby, reduce the TX
|
||||
* latency.
|
||||
*
|
||||
* Parameters:
|
||||
* radio - Reference to the radio driver state structure
|
||||
*
|
||||
* Returned Value:
|
||||
* None
|
||||
*
|
||||
* Assumptions:
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int mrf24j40_txnotify_gts(FAR struct ieee802154_radio_s *radio)
|
||||
{
|
||||
FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio;
|
||||
|
||||
/* Is our single work structure available? It may not be if there are
|
||||
* pending interrupt actions and we will have to ignore the Tx
|
||||
* availability action.
|
||||
*/
|
||||
|
||||
if (work_available(&dev->pollwork))
|
||||
{
|
||||
/* Schedule to serialize the poll on the worker thread. */
|
||||
|
||||
work_queue(HPWORK, &dev->pollwork, mrf24j40_dopoll_gts, dev, 0);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Function: mrf24j40_dopoll_gts
|
||||
*
|
||||
@ -772,7 +838,7 @@ static int mrf24j40_setpanid(FAR struct mrf24j40_radio_s *dev,
|
||||
mrf24j40_setreg(dev->spi, MRF24J40_PANIDH, (uint8_t)(panid>>8));
|
||||
mrf24j40_setreg(dev->spi, MRF24J40_PANIDL, (uint8_t)(panid&0xFF));
|
||||
|
||||
dev->panid = panid;
|
||||
dev->addr.panid = panid;
|
||||
wlinfo("%04X\n", (unsigned)panid);
|
||||
|
||||
return OK;
|
||||
@ -789,7 +855,7 @@ static int mrf24j40_setpanid(FAR struct mrf24j40_radio_s *dev,
|
||||
static int mrf24j40_getpanid(FAR struct mrf24j40_radio_s *dev,
|
||||
FAR uint16_t *panid)
|
||||
{
|
||||
*panid = dev->panid;
|
||||
*panid = dev->addr.panid;
|
||||
|
||||
return OK;
|
||||
}
|
||||
@ -810,7 +876,7 @@ static int mrf24j40_setsaddr(FAR struct mrf24j40_radio_s *dev,
|
||||
mrf24j40_setreg(dev->spi, MRF24J40_SADRH, (uint8_t)(saddr>>8));
|
||||
mrf24j40_setreg(dev->spi, MRF24J40_SADRL, (uint8_t)(saddr&0xFF));
|
||||
|
||||
dev->saddr = saddr;
|
||||
dev->addr.saddr = saddr;
|
||||
wlinfo("%04X\n", (unsigned)saddr);
|
||||
return OK;
|
||||
}
|
||||
@ -826,7 +892,7 @@ static int mrf24j40_setsaddr(FAR struct mrf24j40_radio_s *dev,
|
||||
static int mrf24j40_getsaddr(FAR struct mrf24j40_radio_s *dev,
|
||||
FAR uint16_t *saddr)
|
||||
{
|
||||
*saddr = dev->saddr;
|
||||
*saddr = dev->addr.saddr;
|
||||
|
||||
return OK;
|
||||
}
|
||||
@ -841,14 +907,14 @@ static int mrf24j40_getsaddr(FAR struct mrf24j40_radio_s *dev,
|
||||
****************************************************************************/
|
||||
|
||||
static int mrf24j40_seteaddr(FAR struct mrf24j40_radio_s *dev,
|
||||
FAR uint8_t *eaddr)
|
||||
FAR const uint8_t *eaddr)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 8; i++)
|
||||
{
|
||||
mrf24j40_setreg(dev->spi, MRF24J40_EADR0 + i, eaddr[i]);
|
||||
dev->eaddr[i] = eaddr[i];
|
||||
dev->addr.eaddr[i] = eaddr[i];
|
||||
}
|
||||
|
||||
return OK;
|
||||
@ -865,39 +931,7 @@ static int mrf24j40_seteaddr(FAR struct mrf24j40_radio_s *dev,
|
||||
static int mrf24j40_geteaddr(FAR struct mrf24j40_radio_s *dev,
|
||||
FAR uint8_t *eaddr)
|
||||
{
|
||||
memcpy(eaddr, dev->eaddr, 8);
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mrf24j40_setpromisc
|
||||
*
|
||||
* Description:
|
||||
* Set the device into promiscuous mode, e.g do not filter any incoming
|
||||
* frame.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int mrf24j40_setpromisc(FAR struct mrf24j40_radio_s *dev,
|
||||
bool promisc)
|
||||
{
|
||||
return mrf24j40_setrxmode(dev, promisc ? MRF24J40_RXMODE_PROMISC :
|
||||
MRF24J40_RXMODE_NORMAL);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mrf24j40_getpromisc
|
||||
*
|
||||
* Description:
|
||||
* Get the device receive mode.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int mrf24j40_getpromisc(FAR struct mrf24j40_radio_s *dev,
|
||||
FAR bool *promisc)
|
||||
{
|
||||
*promisc = (dev->rxmode == MRF24J40_RXMODE_PROMISC);
|
||||
memcpy(eaddr, dev->addr.eaddr, 8);
|
||||
|
||||
return OK;
|
||||
}
|
||||
@ -927,17 +961,17 @@ static int mrf24j40_setdevmode(FAR struct mrf24j40_radio_s *dev,
|
||||
|
||||
reg = mrf24j40_getreg(dev->spi, MRF24J40_RXMCR);
|
||||
|
||||
if (mode == IEEE802154_MODE_PANCOORD)
|
||||
if (mode == MRF24J40_MODE_PANCOORD)
|
||||
{
|
||||
reg |= MRF24J40_RXMCR_PANCOORD;
|
||||
reg &= ~MRF24J40_RXMCR_COORD;
|
||||
}
|
||||
else if (mode == IEEE802154_MODE_COORD)
|
||||
else if (mode == MRF24J40_MODE_COORD)
|
||||
{
|
||||
reg |= MRF24J40_RXMCR_COORD;
|
||||
reg &= ~MRF24J40_RXMCR_PANCOORD;
|
||||
}
|
||||
else if (mode == IEEE802154_MODE_DEVICE)
|
||||
else if (mode == MRF24J40_MODE_DEVICE)
|
||||
{
|
||||
reg &= ~MRF24J40_RXMCR_PANCOORD;
|
||||
reg &= ~MRF24J40_RXMCR_COORD;
|
||||
@ -1175,106 +1209,6 @@ static int mrf24j40_regdump(FAR struct mrf24j40_radio_s *dev)
|
||||
return 0;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mrf24j40_ioctl
|
||||
*
|
||||
* Description:
|
||||
* Misc/unofficial device controls.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int mrf24j40_ioctl(FAR struct ieee802154_radio_s *radio, int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio;
|
||||
FAR union ieee802154_radioarg_u *u =
|
||||
(FAR union ieee802154_radioarg_u *)((uintptr_t)arg);
|
||||
int ret;
|
||||
|
||||
switch(cmd)
|
||||
{
|
||||
case PHY802154IOC_SET_CHAN:
|
||||
ret = mrf24j40_setchannel(dev, u->channel);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_CHAN:
|
||||
ret = mrf24j40_getchannel(dev, &u->channel);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_PANID:
|
||||
ret = mrf24j40_setpanid(dev, u->panid);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_PANID:
|
||||
ret = mrf24j40_getpanid(dev, &u->panid);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_SADDR:
|
||||
ret = mrf24j40_setsaddr(dev, u->saddr);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_SADDR:
|
||||
ret = mrf24j40_getsaddr(dev, &u->saddr);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_EADDR:
|
||||
ret = mrf24j40_seteaddr(dev, u->eaddr);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_EADDR:
|
||||
ret = mrf24j40_geteaddr(dev, u->eaddr);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_PROMISC:
|
||||
ret = mrf24j40_setpromisc(dev, u->promisc);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_PROMISC:
|
||||
ret = mrf24j40_getpromisc(dev, &u->promisc);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_DEVMODE:
|
||||
ret = mrf24j40_setdevmode(dev, u->devmode);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_DEVMODE:
|
||||
ret = mrf24j40_getdevmode(dev, &u->devmode);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_TXPWR:
|
||||
ret = mrf24j40_settxpower(dev, u->txpwr);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_TXPWR:
|
||||
ret = mrf24j40_gettxpower(dev, &u->txpwr);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_CCA:
|
||||
ret = mrf24j40_setcca(dev, &u->cca);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_CCA:
|
||||
ret = mrf24j40_getcca(dev, &u->cca);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_ENERGYDETECT:
|
||||
ret = mrf24j40_energydetect(dev, &u->energy);
|
||||
break;
|
||||
|
||||
case 1000:
|
||||
return mrf24j40_regdump(dev);
|
||||
|
||||
case 1001: dev->paenabled = (uint8_t)arg;
|
||||
wlinfo("PA %sabled\n", arg ? "en" : "dis");
|
||||
return OK;
|
||||
|
||||
default:
|
||||
return -ENOTTY;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mrf24j40_energydetect
|
||||
*
|
||||
@ -1336,8 +1270,6 @@ static int mrf24j40_csma_setup(FAR struct mrf24j40_radio_s *dev,
|
||||
uint8_t reg;
|
||||
int ret;
|
||||
|
||||
mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO);
|
||||
|
||||
/* Enable tx int */
|
||||
|
||||
reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON);
|
||||
@ -1534,22 +1466,31 @@ static void mrf24j40_irqwork_txgts(FAR struct mrf24j40_radio_s *dev,
|
||||
* Name: mrf24j40_rxenable
|
||||
*
|
||||
* Description:
|
||||
* Enable reception of a packet. The interrupt will signal the rx semaphore.
|
||||
* Enable/Disable receiver.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio)
|
||||
static int mrf24j40_rxenable(FAR struct ieee802154_radio_s *radio, bool enable)
|
||||
{
|
||||
FAR struct mrf24j40_radio_s *dev = (FAR struct mrf24j40_radio_s *)radio;
|
||||
uint8_t reg;
|
||||
|
||||
mrf24j40_pacontrol(dev, MRF24J40_PA_AUTO);
|
||||
if (enable)
|
||||
{
|
||||
/* Enable rx int */
|
||||
|
||||
/* Enable rx int */
|
||||
reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON);
|
||||
reg &= ~MRF24J40_INTCON_RXIE;
|
||||
mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable rx int */
|
||||
|
||||
reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON);
|
||||
reg &= ~MRF24J40_INTCON_RXIE;
|
||||
mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg);
|
||||
reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON);
|
||||
reg |= MRF24J40_INTCON_RXIE;
|
||||
mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg);
|
||||
}
|
||||
|
||||
return OK;
|
||||
}
|
||||
@ -1570,15 +1511,13 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev)
|
||||
uint32_t index;
|
||||
uint8_t reg;
|
||||
|
||||
/* wlinfo("!\n"); */
|
||||
|
||||
/* Disable rx int */
|
||||
|
||||
reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON);
|
||||
reg |= MRF24J40_INTCON_RXIE;
|
||||
mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg);
|
||||
|
||||
/* Disable packet reception */
|
||||
/* Disable packet reception. See pg. 109 of datasheet */
|
||||
|
||||
mrf24j40_setreg(dev->spi, MRF24J40_BBREG1, MRF24J40_BBREG1_RXDECINV);
|
||||
|
||||
@ -1597,7 +1536,6 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev)
|
||||
addr = MRF24J40_RXBUF_BASE;
|
||||
|
||||
iob->io_len= mrf24j40_getreg(dev->spi, addr++);
|
||||
/* wlinfo("len %3d\n", dev->radio.rxbuf->len); */
|
||||
|
||||
/* TODO: This needs to be changed. It is inefficient to do the SPI read byte
|
||||
* by byte */
|
||||
@ -1633,6 +1571,11 @@ static void mrf24j40_irqwork_rx(FAR struct mrf24j40_radio_s *dev)
|
||||
|
||||
mrf24j40_setreg(dev->spi, MRF24J40_BBREG1, 0);
|
||||
|
||||
/* Enable rx int */
|
||||
|
||||
reg = mrf24j40_getreg(dev->spi, MRF24J40_INTCON);
|
||||
reg &= ~MRF24J40_INTCON_RXIE;
|
||||
mrf24j40_setreg(dev->spi, MRF24J40_INTCON, reg);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
|
@ -89,7 +89,6 @@
|
||||
#define _CLIOCBASE (0x2400) /* Contactless modules ioctl commands */
|
||||
#define _USBCBASE (0x2500) /* USB-C controller ioctl commands */
|
||||
#define _MAC802154BASE (0x2600) /* 802.15.4 MAC ioctl commands */
|
||||
#define _PHY802154BASE (0x2700) /* 802.15.4 Radio ioctl commands */
|
||||
|
||||
/* boardctl() commands share the same number space */
|
||||
|
||||
@ -429,12 +428,6 @@
|
||||
#define _MAC802154IOCVALID(c) (_IOC_TYPE(c)==_MAC802154BASE)
|
||||
#define _MAC802154IOC(nr) _IOC(_MAC802154BASE,nr)
|
||||
|
||||
/* 802.15.4 Radio driver ioctl definitions **********************************/
|
||||
/* (see nuttx/ieee802154/wireless/ieee802154_radio.h */
|
||||
|
||||
#define _PHY802154IOCVALID(c) (_IOC_TYPE(c)==_PHY802154BASE)
|
||||
#define _PHY802154IOC(nr) _IOC(_PHY802154BASE,nr)
|
||||
|
||||
/* boardctl() command definitions *******************************************/
|
||||
|
||||
#define _BOARDIOCVALID(c) (_IOC_TYPE(c)==_BOARDBASE)
|
||||
|
@ -55,8 +55,6 @@
|
||||
# include <net/if.h>
|
||||
#endif
|
||||
|
||||
#include <nuttx/wireless/ieee802154/ieee802154_radio.h>
|
||||
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
|
||||
/****************************************************************************
|
||||
@ -227,7 +225,10 @@ enum ieee802154_status_e
|
||||
IEEE802154_STATUS_TRANSACTION_OVERFLOW,
|
||||
IEEE802154_STATUS_TX_ACTIVE,
|
||||
IEEE802154_STATUS_UNAVAILABLE_KEY,
|
||||
IEEE802154_STATUS_UNSUPPORTED_ATTRIBUTE
|
||||
IEEE802154_STATUS_UNSUPPORTED_ATTRIBUTE,
|
||||
IEEE802154_STATUS_FAILED /* This value is not outlined in the standard. It is
|
||||
* a catch-all for any failures that are not outlined
|
||||
* in the standard */
|
||||
};
|
||||
|
||||
/* IEEE 802.15.4 PHY/MAC PIB attributes IDs */
|
||||
@ -328,6 +329,8 @@ enum ieee802154_pib_attr_e
|
||||
IEEE802154_PIB_MAC_PANCOORD_SHORT_ADDR,
|
||||
};
|
||||
|
||||
#define IEEE802154_EADDR_LEN 8
|
||||
|
||||
/* IEEE 802.15.4 Device address
|
||||
* The addresses in ieee802154 have several formats:
|
||||
* No address : [none]
|
||||
@ -348,9 +351,10 @@ struct ieee802154_addr_s
|
||||
|
||||
enum ieee802154_addr_mode_e mode;
|
||||
|
||||
uint16_t panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */
|
||||
uint16_t saddr; /* short address */
|
||||
uint8_t eaddr[8]; /* extended address */
|
||||
uint16_t panid; /* PAN identifier, can be
|
||||
* IEEE802154_PAN_UNSPEC */
|
||||
uint16_t saddr; /* short address */
|
||||
uint8_t eaddr[IEEE802154_EADDR_LEN]; /* extended address */
|
||||
};
|
||||
|
||||
#define IEEE802154_ADDRSTRLEN 22 /* (2*2+1+8*2, PPPP/EEEEEEEEEEEEEEEE) */
|
||||
@ -451,15 +455,54 @@ struct ieee802154_pend_addr_s
|
||||
struct ieee802154_addr_s addr[7]; /* Array of at most 7 addresses */
|
||||
};
|
||||
|
||||
#ifdef CONFIG_IEEE802154_RANGING
|
||||
#define IEEE802154_TXDESC_FIELDS \
|
||||
uint8_t handle; \
|
||||
uint32_t timestamp; \
|
||||
uint8_t status;
|
||||
#else
|
||||
#define IEEE802154_TXDESC_FIELDS \
|
||||
uint8_t handle; \
|
||||
uint32_t timestamp; \
|
||||
uint8_t status;
|
||||
bool rng_rcvd; \
|
||||
uint32_t rng_counter_start; \
|
||||
uint32_t rng_counter_stop; \
|
||||
uint32_t rng_tracking_interval; \
|
||||
uint32_t rng_offset;\
|
||||
uint8_t rng_fom;
|
||||
#endif
|
||||
|
||||
struct ieee802154_txdesc_s
|
||||
{
|
||||
IEEE802154_TXDESC_FIELDS
|
||||
|
||||
/* TODO: Add slotting information for GTS transactions */
|
||||
};
|
||||
|
||||
struct ieee802154_rxdesc_s
|
||||
{
|
||||
uint8_t lqi;
|
||||
uint8_t rssi;
|
||||
};
|
||||
|
||||
struct ieee802154_cca_s
|
||||
{
|
||||
uint8_t use_ed : 1; /* CCA using ED */
|
||||
uint8_t use_cs : 1; /* CCA using carrier sense */
|
||||
uint8_t edth; /* Energy detection threshold for CCA */
|
||||
uint8_t csth; /* Carrier sense threshold for CCA */
|
||||
};
|
||||
|
||||
/* Primitive Support Types ***************************************************/
|
||||
|
||||
union ieee802154_attr_val_u
|
||||
union ieee802154_macattr_u
|
||||
{
|
||||
uint8_t eaddr[8];
|
||||
uint8_t eaddr[IEEE802154_EADDR_LEN];
|
||||
uint16_t saddr;
|
||||
uint16_t pan_id;
|
||||
uint16_t panid;
|
||||
|
||||
uint8_t coord_eaddr[8];
|
||||
uint8_t coord_eaddr[IEEE802154_EADDR_LEN];
|
||||
uint16_t coord_saddr;
|
||||
|
||||
bool is_assoc;
|
||||
@ -500,6 +543,25 @@ union ieee802154_attr_val_u
|
||||
uint8_t dsn;
|
||||
};
|
||||
|
||||
union ieee802154_phyattr_u
|
||||
{
|
||||
uint8_t channel;
|
||||
int32_t txpwr
|
||||
/* TODO: Fill this out as we implement supported get/set commands */
|
||||
};
|
||||
|
||||
union ieee802154_secattr_u
|
||||
{
|
||||
/* TODO: Fill this out as we implement supported get/set commands */
|
||||
};
|
||||
|
||||
union ieee802154_attr_val_u
|
||||
{
|
||||
union ieee802154_macattr_u mac;
|
||||
union ieee802154_phyattr_u phy;
|
||||
union ieee802154_secattr_u sec;
|
||||
};
|
||||
|
||||
struct ieee802154_gts_info_s
|
||||
{
|
||||
uint8_t length : 4; /* Number of SF slots for GTS */
|
||||
@ -881,20 +943,6 @@ struct ieee802154_commstatus_ind_s
|
||||
#endif
|
||||
};
|
||||
|
||||
/*****************************************************************************
|
||||
* Primitive: MLME-GET.request
|
||||
*
|
||||
* Description:
|
||||
* Requests information about a given PIB attribute.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
struct ieee802154_get_req_s
|
||||
{
|
||||
enum ieee802154_pib_attr_e pib_attr;
|
||||
FAR union ieee802154_attr_val_u *attr_value;
|
||||
};
|
||||
|
||||
/*****************************************************************************
|
||||
* Primitive: MLME-GTS.request
|
||||
*
|
||||
@ -1089,6 +1137,20 @@ struct ieee802154_scan_conf_s
|
||||
#warning Figure out how to handle missing primitive semantics. See standard.
|
||||
};
|
||||
|
||||
/*****************************************************************************
|
||||
* Primitive: MLME-GET.request
|
||||
*
|
||||
* Description:
|
||||
* Requests information about a given PIB attribute.
|
||||
*
|
||||
*****************************************************************************/
|
||||
|
||||
struct ieee802154_get_req_s
|
||||
{
|
||||
enum ieee802154_pib_attr_e pib_attr;
|
||||
union ieee802154_attr_val_u attr_value;
|
||||
};
|
||||
|
||||
/*****************************************************************************
|
||||
* Primitive: MLME-SET.request
|
||||
*
|
||||
|
@ -48,150 +48,18 @@
|
||||
#include <stdbool.h>
|
||||
#include <semaphore.h>
|
||||
|
||||
#ifdef CONFIG_NET_6LOWPAN
|
||||
# include <net/if.h>
|
||||
#endif
|
||||
|
||||
#include <nuttx/fs/ioctl.h>
|
||||
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-Processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/* Configuration ************************************************************/
|
||||
|
||||
/* IEEE 802.15.4 Radio Interface **********************************************/
|
||||
|
||||
/* This layer only knows radio frames. There are no 802.15.4 specific bits
|
||||
* at this layer. */
|
||||
|
||||
/* Device modes */
|
||||
|
||||
#define IEEE802154_MODE_DEVICE 0x00
|
||||
#define IEEE802154_MODE_COORD 0x01 /* avail in mrf24j40, but why? */
|
||||
#define IEEE802154_MODE_PANCOORD 0x02
|
||||
|
||||
/* IEEE 802.15.4 Radio Character Driver IOCTL ********************************/
|
||||
|
||||
#define PHY802154IOC_SET_CHAN _PHY802154IOC(0x0001)
|
||||
#define PHY802154IOC_GET_CHAN _PHY802154IOC(0x0002)
|
||||
|
||||
#define PHY802154IOC_SET_PANID _PHY802154IOC(0x0003)
|
||||
#define PHY802154IOC_GET_PANID _PHY802154IOC(0x0004)
|
||||
|
||||
#define PHY802154IOC_SET_SADDR _PHY802154IOC(0x0005)
|
||||
#define PHY802154IOC_GET_SADDR _PHY802154IOC(0x0006)
|
||||
|
||||
#define PHY802154IOC_SET_EADDR _PHY802154IOC(0x0007)
|
||||
#define PHY802154IOC_GET_EADDR _PHY802154IOC(0x0008)
|
||||
|
||||
#define PHY802154IOC_SET_PROMISC _PHY802154IOC(0x0009)
|
||||
#define PHY802154IOC_GET_PROMISC _PHY802154IOC(0x000A)
|
||||
|
||||
#define PHY802154IOC_SET_DEVMODE _PHY802154IOC(0x000B)
|
||||
#define PHY802154IOC_GET_DEVMODE _PHY802154IOC(0x000C)
|
||||
|
||||
#define PHY802154IOC_SET_TXPWR _PHY802154IOC(0x000D)
|
||||
#define PHY802154IOC_GET_TXPWR _PHY802154IOC(0x000E)
|
||||
|
||||
#define PHY802154IOC_SET_CCA _PHY802154IOC(0x000F)
|
||||
#define PHY802154IOC_GET_CCA _PHY802154IOC(0x0010)
|
||||
|
||||
#define PHY802154IOC_ENERGYDETECT _PHY802154IOC(0x0011)
|
||||
|
||||
#define EADDR_SIZE 8 /* Extended address size */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/* Structures used with IEEE802.15.4 radio interface operations *************/
|
||||
|
||||
struct ieee802154_cca_s
|
||||
{
|
||||
uint8_t use_ed : 1; /* CCA using ED */
|
||||
uint8_t use_cs : 1; /* CCA using carrier sense */
|
||||
uint8_t edth; /* Energy detection threshold for CCA */
|
||||
uint8_t csth; /* Carrier sense threshold for CCA */
|
||||
};
|
||||
|
||||
struct ieee802154_packet_s
|
||||
{
|
||||
uint8_t len;
|
||||
uint8_t data[127];
|
||||
uint8_t lqi;
|
||||
uint8_t rssi;
|
||||
};
|
||||
|
||||
/* IOCTL command data argument **********************************************/
|
||||
|
||||
/* A pointer to this structure is passed as the argument of each IOCTL
|
||||
* command.
|
||||
*/
|
||||
|
||||
union ieee802154_radioarg_u
|
||||
{
|
||||
uint8_t channel; /* PHY802154IOC_GET/SET_CHAN */
|
||||
uint16_t panid; /* PHY802154IOC_GET/SET_PANID */
|
||||
uint16_t saddr; /* PHY802154IOC_GET/SET_SADDR */
|
||||
uint8_t eaddr[EADDR_SIZE]; /* PHY802154IOC_GET/SET_EADDR */
|
||||
bool promisc; /* PHY802154IOC_GET/SET_EADDR */
|
||||
uint8_t devmode; /* PHY802154IOC_GET/SET_DEVMODE */
|
||||
int32_t txpwr; /* PHY802154IOC_GET/SET_TXPWR */
|
||||
bool energy; /* PHY802154IOC_ENERGYDETECT */
|
||||
struct ieee802154_cca_s cca; /* PHY802154IOC_GET/SET_CCA */
|
||||
};
|
||||
|
||||
#ifdef CONFIG_NET_6LOWPAN
|
||||
/* For the case of network IOCTLs, the network IOCTL to the MAC network
|
||||
* driver will include a device name like "wpan0" as the destination of
|
||||
* the IOCTL command. The MAC layer will forward only the payload union
|
||||
* to the radio IOCTL method.
|
||||
*/
|
||||
|
||||
struct ieee802154_netradio_s
|
||||
{
|
||||
char ifr_name[IFNAMSIZ]; /* Interface name, e.g. "wpan0" */
|
||||
union ieee802154_radioarg_u u; /* Data payload */
|
||||
};
|
||||
#endif
|
||||
|
||||
/* IEEE802.15.4 Radio Interface Operations **********************************/
|
||||
|
||||
/* This is a work-around to allow the MAC upper layer have a struct with
|
||||
* identical members but with a different name. */
|
||||
|
||||
#ifdef CONFIG_IEEE802154_RANGING
|
||||
#define IEEE802154_TXDESC_FIELDS \
|
||||
uint8_t handle; \
|
||||
uint32_t timestamp; \
|
||||
uint8_t status;
|
||||
#else
|
||||
#define IEEE802154_TXDESC_FIELDS \
|
||||
uint8_t handle; \
|
||||
uint32_t timestamp; \
|
||||
uint8_t status;
|
||||
bool rng_rcvd; \
|
||||
uint32_t rng_counter_start; \
|
||||
uint32_t rng_counter_stop; \
|
||||
uint32_t rng_tracking_interval; \
|
||||
uint32_t rng_offset;\
|
||||
uint8_t rng_fom;
|
||||
#endif
|
||||
|
||||
struct ieee802154_txdesc_s
|
||||
{
|
||||
IEEE802154_TXDESC_FIELDS
|
||||
|
||||
/* TODO: Add slotting information for GTS transactions */
|
||||
};
|
||||
|
||||
struct ieee802154_rxdesc_s
|
||||
{
|
||||
uint8_t lqi;
|
||||
uint8_t rssi;
|
||||
};
|
||||
|
||||
struct ieee802154_radiocb_s
|
||||
{
|
||||
CODE int (*poll_csma) (FAR const struct ieee802154_radiocb_s *radiocb,
|
||||
@ -213,11 +81,14 @@ struct ieee802154_radioops_s
|
||||
{
|
||||
CODE int (*bind) (FAR struct ieee802154_radio_s *radio,
|
||||
FAR struct ieee802154_radiocb_s *radiocb);
|
||||
CODE int (*ioctl)(FAR struct ieee802154_radio_s *radio, int cmd,
|
||||
unsigned long arg);
|
||||
CODE int (*rxenable)(FAR struct ieee802154_radio_s *radio);
|
||||
CODE int (*txnotify_csma)(FAR struct ieee802154_radio_s *radio);
|
||||
CODE int (*txnotify_gts)(FAR struct ieee802154_radio_s *radio);
|
||||
CODE int (*get_attr) (FAR struct ieee802154_radio_s *radio,
|
||||
enum ieee802154_pib_attr_e pib_attr,
|
||||
FAR union ieee802154_attr_val_u *attr_value);
|
||||
CODE int (*set_attr) (FAR struct ieee802154_radio_s *radio,
|
||||
enum ieee802154_pib_attr_e pib_attr,
|
||||
FAR const union ieee802154_attr_val_u *attr_value);
|
||||
};
|
||||
|
||||
struct ieee802154_radio_s
|
||||
@ -237,28 +108,6 @@ extern "C"
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154dev_register
|
||||
*
|
||||
* Description:
|
||||
* Register a character driver to access the IEEE 802.15.4 radio from
|
||||
* user-space
|
||||
*
|
||||
* Input Parameters:
|
||||
* radio - Pointer to the radio struct to be registerd.
|
||||
* devname - The name of the IEEE 802.15.4 radio to be registered.
|
||||
*
|
||||
* Returned Values:
|
||||
* Zero (OK) is returned on success. Otherwise a negated errno value is
|
||||
* returned to indicate the nature of the failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_IEEE802154_DEV
|
||||
int radio802154dev_register(FAR struct ieee802154_radio_s *radio,
|
||||
FAR char *devname);
|
||||
#endif
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
@ -65,11 +65,6 @@
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_WIRELESS_IEEE802154
|
||||
#ifdef CONFIG_IEEE802154_DEV
|
||||
/* Include ieee802.15.4 radio IOCTL definitions */
|
||||
|
||||
# include <nuttx/wireless/ieee802154/ ieee802154_radio.h>
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_IEEE802154_MAC
|
||||
/* Include ieee802.15.4 MAC IOCTL definitions */
|
||||
|
@ -74,7 +74,6 @@
|
||||
|
||||
#if defined(CONFIG_NETDEV_IOCTL) && defined(CONFIG_NET_6LOWPAN)
|
||||
# include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
||||
# include <nuttx/wireless/ieee802154/ieee802154_radio.h>
|
||||
#endif
|
||||
|
||||
#include "arp/arp.h"
|
||||
@ -353,22 +352,7 @@ static int netdev_iee802154_ioctl(FAR struct socket *psock, int cmd,
|
||||
|
||||
if (arg != 0ul)
|
||||
{
|
||||
/* Verify that this is either a valid IEEE802.15.4 radio IOCTL command
|
||||
* or a valid IEEE802.15.4 MAC IOCTL command.
|
||||
*/
|
||||
|
||||
if (_PHY802154IOCVALID(cmd))
|
||||
{
|
||||
/* Get the IEEE802.15.4 network device to receive the radio IOCTL
|
||||
* commdand
|
||||
*/
|
||||
|
||||
FAR struct ieee802154_netradio_s *radio =
|
||||
(FAR struct ieee802154_netradio_s *)((uintptr_t)arg);
|
||||
|
||||
ifname = radio->ifr_name;
|
||||
}
|
||||
else if (_MAC802154IOCVALID(cmd))
|
||||
if (_MAC802154IOCVALID(cmd))
|
||||
{
|
||||
/* Get the IEEE802.15.4 MAC device to receive the radio IOCTL
|
||||
* commdand
|
||||
|
@ -57,7 +57,6 @@
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/net/sixlowpan.h>
|
||||
#include <nuttx/wireless/ieee802154/ieee802154_radio.h>
|
||||
|
||||
#include "sixlowpan/sixlowpan_internal.h"
|
||||
|
||||
@ -165,7 +164,7 @@ bool sixlowpan_ismacbased(const net_ipv6addr_t ipaddr,
|
||||
* Name: sixlowpan_src_panid
|
||||
*
|
||||
* Description:
|
||||
* Get the source PAN ID from the IEEE802.15.4 radio.
|
||||
* Get the source PAN ID from the IEEE802.15.4 MAC layer.
|
||||
*
|
||||
* Input parameters:
|
||||
* ieee - A reference IEEE802.15.4 MAC network device structure.
|
||||
@ -181,18 +180,20 @@ int sixlowpan_src_panid(FAR struct ieee802154_driver_s *ieee,
|
||||
FAR uint16_t *panid)
|
||||
{
|
||||
FAR struct net_driver_s *dev = &ieee->i_dev;
|
||||
struct ieee802154_netradio_s arg;
|
||||
struct ieee802154_netmac_s arg;
|
||||
int ret;
|
||||
|
||||
memcpy(arg.ifr_name, ieee->i_dev.d_ifname, IFNAMSIZ);
|
||||
ret = dev->d_ioctl(dev, PHY802154IOC_GET_PANID, (unsigned long)((uintptr_t)&arg));
|
||||
arg.u.getreq.pib_attr = IEEE802154_PIB_MAC_PAN_ID;
|
||||
ret = dev->d_ioctl(dev, MAC802154IOC_MLME_GET_REQUEST,
|
||||
(unsigned long)((uintptr_t)&arg));
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_GET_PANID failed: %d\n", ret);
|
||||
wlerr("ERROR: MAC802154IOC_MLME_GET_REQUEST failed: %d\n", ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
*panid = arg.u.panid;
|
||||
*panid = arg.u.getreq.attr_value->panid;
|
||||
return OK;
|
||||
}
|
||||
|
||||
|
@ -60,14 +60,6 @@ config IEEE802154_NTXDESC
|
||||
|
||||
endif # IEEE802154_MAC
|
||||
|
||||
config IEEE802154_DEV
|
||||
bool "Debug character driver for ieee802.15.4 radio interfaces"
|
||||
default n
|
||||
depends on WIRELESS_IEEE802154
|
||||
---help---
|
||||
Enables a device driver to expose ieee802.15.4 radio controls
|
||||
to user space as IOCTLs.
|
||||
|
||||
config IEEE802154_NETDEV
|
||||
bool "IEEE802154 6loWPAN Network Device"
|
||||
default n
|
||||
|
@ -37,8 +37,6 @@ ifeq ($(CONFIG_WIRELESS_IEEE802154),y)
|
||||
|
||||
# Include IEEE 802.15.4 support
|
||||
|
||||
CSRCS = radio802154_ioctl.c
|
||||
|
||||
# Include wireless devices build support
|
||||
|
||||
ifeq ($(CONFIG_IEEE802154_MAC),y)
|
||||
|
@ -2,7 +2,9 @@
|
||||
* wireless/ieee802154/mac802154.c
|
||||
*
|
||||
* Copyright (C) 2016 Sebastien Lorquet. All rights reserved.
|
||||
* Copyright (C) 2017 Verge Inc. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
* Author: Anthony Merlino <anthony@vergeaero.com>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
@ -51,6 +53,7 @@
|
||||
#include <nuttx/drivers/iob.h>
|
||||
|
||||
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
||||
#include <nuttx/wireless/ieee802154/ieee802154_radio.h>
|
||||
|
||||
#include "mac802154.h"
|
||||
|
||||
@ -445,14 +448,15 @@ static int mac802154_defaultmib(FAR struct ieee802154_privmac_s *priv)
|
||||
|
||||
priv->coord_addr.mode = IEEE802154_ADDRMODE_NONE;
|
||||
priv->coord_addr.saddr = IEEE802154_SADDR_UNSPEC;
|
||||
memcpy(&priv->coord_addr.eaddr[0], IEEE802154_EADDR_UNSPEC, 8);
|
||||
memcpy(&priv->coord_addr.eaddr[0], IEEE802154_EADDR_UNSPEC,
|
||||
IEEE802154_EADDR_LEN);
|
||||
|
||||
/* Reset the device's address */
|
||||
|
||||
priv->addr.mode = IEEE802154_ADDRMODE_NONE;
|
||||
priv->addr.panid = IEEE802154_PAN_UNSPEC;
|
||||
priv->addr.saddr = IEEE802154_SADDR_UNSPEC;
|
||||
memcpy(&priv->addr.eaddr[0], IEEE802154_EADDR_UNSPEC, 8);
|
||||
memcpy(&priv->addr.eaddr[0], IEEE802154_EADDR_UNSPEC, IEEE802154_EADDR_LEN);
|
||||
|
||||
|
||||
/* These attributes are effected and determined based on the PHY. Need to
|
||||
@ -875,85 +879,78 @@ int mac802154_ioctl(MACHANDLE mac, int cmd, unsigned long arg)
|
||||
{
|
||||
case MAC802154IOC_MLME_ASSOC_REQUEST:
|
||||
{
|
||||
mac802154_req_associate(mac, &macarg->assocreq);
|
||||
ret = mac802154_req_associate(mac, &macarg->assocreq);
|
||||
}
|
||||
break;
|
||||
case MAC802154IOC_MLME_ASSOC_RESPONSE:
|
||||
{
|
||||
mac802154_resp_associate(mac, &macarg->assocresp);
|
||||
ret = mac802154_resp_associate(mac, &macarg->assocresp);
|
||||
}
|
||||
break;
|
||||
case MAC802154IOC_MLME_DISASSOC_REQUEST:
|
||||
{
|
||||
mac802154_req_disassociate(mac, &macarg->disassocreq);
|
||||
ret = mac802154_req_disassociate(mac, &macarg->disassocreq);
|
||||
}
|
||||
break;
|
||||
case MAC802154IOC_MLME_GET_REQUEST:
|
||||
{
|
||||
mac802154_req_get(mac, macarg->getreq.pib_attr,
|
||||
macarg->getreq.attr_value);
|
||||
ret = mac802154_req_get(mac, macarg->getreq.pib_attr,
|
||||
&macarg->getreq.attr_value);
|
||||
}
|
||||
break;
|
||||
case MAC802154IOC_MLME_GTS_REQUEST:
|
||||
{
|
||||
mac802154_req_gts(mac, &macarg->gtsreq);
|
||||
ret = mac802154_req_gts(mac, &macarg->gtsreq);
|
||||
}
|
||||
break;
|
||||
case MAC802154IOC_MLME_ORPHAN_RESPONSE:
|
||||
{
|
||||
mac802154_resp_orphan(mac, &macarg->orphanresp);
|
||||
ret = mac802154_resp_orphan(mac, &macarg->orphanresp);
|
||||
}
|
||||
break;
|
||||
case MAC802154IOC_MLME_RESET_REQUEST:
|
||||
{
|
||||
mac802154_req_reset(mac, macarg->resetreq.rst_pibattr);
|
||||
ret = mac802154_req_reset(mac, macarg->resetreq.rst_pibattr);
|
||||
}
|
||||
break;
|
||||
case MAC802154IOC_MLME_RXENABLE_REQUEST:
|
||||
{
|
||||
mac802154_req_rxenable(mac, &macarg->rxenabreq);
|
||||
ret = mac802154_req_rxenable(mac, &macarg->rxenabreq);
|
||||
}
|
||||
break;
|
||||
case MAC802154IOC_MLME_SCAN_REQUEST:
|
||||
{
|
||||
mac802154_req_scan(mac, &macarg->scanreq);
|
||||
ret = mac802154_req_scan(mac, &macarg->scanreq);
|
||||
}
|
||||
break;
|
||||
case MAC802154IOC_MLME_SET_REQUEST:
|
||||
{
|
||||
mac802154_req_set(mac, &macarg->setreq);
|
||||
ret = mac802154_req_set(mac, macarg->setreq.pib_attr,
|
||||
&macarg->setreq.attr_value);
|
||||
}
|
||||
break;
|
||||
case MAC802154IOC_MLME_START_REQUEST:
|
||||
{
|
||||
mac802154_req_start(mac, &macarg->startreq);
|
||||
ret = mac802154_req_start(mac, &macarg->startreq);
|
||||
}
|
||||
break;
|
||||
case MAC802154IOC_MLME_SYNC_REQUEST:
|
||||
{
|
||||
mac802154_req_sync(mac, &macarg->syncreq);
|
||||
ret = mac802154_req_sync(mac, &macarg->syncreq);
|
||||
}
|
||||
break;
|
||||
case MAC802154IOC_MLME_POLL_REQUEST:
|
||||
{
|
||||
mac802154_req_poll(mac, &macarg->pollreq);
|
||||
ret = mac802154_req_poll(mac, &macarg->pollreq);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
wlerr("ERROR: Unrecognized cmd: %d\n", cmd);
|
||||
ret = -ENOTTY;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
/* No, other IOCTLs must be aimed at the IEEE802.15.4 radio layer */
|
||||
|
||||
else
|
||||
{
|
||||
DEBUGASSERT(priv->radio != NULL &&
|
||||
priv->radio->ops != NULL &&
|
||||
priv->radio->ops->ioctl != NULL);
|
||||
|
||||
ret = priv->radio->ops->ioctl(priv->radio, cmd, arg);
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
@ -1109,8 +1106,10 @@ int mac802154_req_data(MACHANDLE mac,
|
||||
}
|
||||
else if (meta->dest_addr.mode == IEEE802154_ADDRMODE_EXTENDED)
|
||||
{
|
||||
memcpy(&frame->io_data[mhr_len], &meta->dest_addr.eaddr, 8);
|
||||
mhr_len += 8;
|
||||
memcpy(&frame->io_data[mhr_len], &meta->dest_addr.eaddr,
|
||||
IEEE802154_EADDR_LEN);
|
||||
|
||||
mhr_len += IEEE802154_EADDR_LEN;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1166,8 +1165,10 @@ int mac802154_req_data(MACHANDLE mac,
|
||||
}
|
||||
else if (meta->src_addr_mode == IEEE802154_ADDRMODE_EXTENDED)
|
||||
{
|
||||
memcpy(&frame->io_data[mhr_len], &priv->addr.eaddr, 8);
|
||||
mhr_len += 8;
|
||||
memcpy(&frame->io_data[mhr_len], &priv->addr.eaddr,
|
||||
IEEE802154_EADDR_LEN);
|
||||
|
||||
mhr_len += IEEE802154_EADDR_LEN;
|
||||
}
|
||||
}
|
||||
|
||||
@ -1482,38 +1483,39 @@ int mac802154_req_get(MACHANDLE mac, enum ieee802154_pib_attr_e pib_attr,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mac802154_req_set(MACHANDLE mac, FAR struct ieee802154_set_req_s *req)
|
||||
int mac802154_req_set(MACHANDLE mac, enum ieee802154_pib_attr_e pib_attr,
|
||||
FAR const union ieee802154_attr_val_u *attr_value)
|
||||
{
|
||||
FAR struct ieee802154_privmac_s *priv =
|
||||
(FAR struct ieee802154_privmac_s *)mac;
|
||||
union ieee802154_radioarg_u radio_arg;
|
||||
int ret;
|
||||
|
||||
switch (req->pib_attr)
|
||||
switch (pib_attr)
|
||||
{
|
||||
case IEEE802154_PIB_MAC_EXTENDED_ADDR:
|
||||
{
|
||||
/* Set the attribute in the structure to the new value */
|
||||
/* Set the MAC copy of the address in the table */
|
||||
|
||||
memcpy(&priv->addr.eaddr[0], &req->attr_value.eaddr[0], 8);
|
||||
memcpy(&priv->addr.eaddr[0], &attr_value->mac.eaddr[0],
|
||||
IEEE802154_EADDR_LEN);
|
||||
|
||||
/* Tell the radio about the attribute */
|
||||
|
||||
/* The radio device needs to be updated as well */
|
||||
|
||||
memcpy(&radio_arg.eaddr[0], &priv->addr.eaddr[0], 8);
|
||||
ret = priv->radio->ops->ioctl(priv->radio, PHY802154IOC_SET_EADDR,
|
||||
(unsigned long)&radio_arg);
|
||||
|
||||
priv->radio->ops->set_attr(priv->radio, pib_attr, attr_value);
|
||||
|
||||
ret = IEEE802154_STATUS_SUCCESS;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
{
|
||||
ret = -IEEE802154_STATUS_UNSUPPORTED_ATTRIBUTE;
|
||||
/* The attribute may be handled soley in the radio driver, so pass
|
||||
* it along.
|
||||
*/
|
||||
|
||||
ret = priv->radio->ops->set_attr(priv->radio, pib_attr, attr_value);
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
@ -269,7 +269,8 @@ int mac802154_req_get(MACHANDLE mac, enum ieee802154_pib_attr_e pib_attr,
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int mac802154_req_set(MACHANDLE mac, FAR struct ieee802154_set_req_s *req);
|
||||
int mac802154_req_set(MACHANDLE mac, enum ieee802154_pib_attr_e pib_attr,
|
||||
FAR const union ieee802154_attr_val_u *attr_value);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: mac802154_req_start
|
||||
|
@ -54,7 +54,6 @@
|
||||
#include <nuttx/net/net.h>
|
||||
#include <nuttx/net/ip.h>
|
||||
#include <nuttx/net/sixlowpan.h>
|
||||
#include <nuttx/wireless/ieee802154/ieee802154_radio.h>
|
||||
#include <nuttx/wireless/ieee802154/ieee802154_loopback.h>
|
||||
|
||||
#include "mac802154.h"
|
||||
@ -594,32 +593,6 @@ static int lo_ioctl(FAR struct net_driver_s *dev, int cmd,
|
||||
|
||||
else
|
||||
#endif
|
||||
if (_PHY802154IOCVALID(cmd))
|
||||
{
|
||||
FAR struct ieee802154_netradio_s *netradio =
|
||||
(FAR struct ieee802154_netradio_s *)arg;
|
||||
|
||||
/* Pick out radio settings of interest. There is, of course, no
|
||||
* radio in this loopback.
|
||||
*/
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case PHY802154IOC_SET_PANID:
|
||||
priv->lo_panid = netradio->u.panid;
|
||||
ret = OK;
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_PANID:
|
||||
netradio->u.panid = priv->lo_panid;
|
||||
ret = OK;
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
#endif
|
||||
|
@ -1381,20 +1381,6 @@ static int macnet_ioctl(FAR struct net_driver_s *dev, int cmd,
|
||||
}
|
||||
}
|
||||
|
||||
/* No, check for IOCTLs aimed at the IEEE802.15.4 radio layer */
|
||||
|
||||
else if (_PHY802154IOCVALID(cmd))
|
||||
{
|
||||
FAR struct ieee802154_netradio_s *netradio =
|
||||
(FAR struct ieee802154_netradio_s *)arg;
|
||||
|
||||
if (netradio != NULL)
|
||||
{
|
||||
unsigned long radioarg = (unsigned int)((uintptr_t)&netradio->u);
|
||||
ret = priv->md_mac.macops.ioctl(priv->md_mac, cmd, radioarg);
|
||||
}
|
||||
}
|
||||
|
||||
/* Okay, we have no idea what this command is.. just give to the
|
||||
* IEEE802.15.4 MAC layer without modification.
|
||||
*/
|
||||
|
@ -1,512 +0,0 @@
|
||||
/****************************************************************************
|
||||
* wireless/ieee802154/radio802154_device.c
|
||||
*
|
||||
* Copyright (C) 2014-2015 Gregory Nutt. All rights reserved.
|
||||
* Copyright (C) 2014-2015 Sebastien Lorquet. All rights reserved.
|
||||
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
||||
* Author: Anthony Merlino <anthony@vergeaero.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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <nuttx/arch.h>
|
||||
#include <nuttx/kmalloc.h>
|
||||
#include <nuttx/wireless/ieee802154/ieee802154_radio.h>
|
||||
|
||||
#include "radio802154_ioctl.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
struct radio802154_devwrapper_s
|
||||
{
|
||||
FAR struct ieee802154_radio_s *child;
|
||||
sem_t devsem; /* Device access serialization semaphore */
|
||||
bool opened; /* This device can only be opened once */
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
static void radio802154dev_semtake(FAR struct radio802154_devwrapper_s *dev);
|
||||
static int radio802154dev_open(FAR struct file *filep);
|
||||
static int radio802154dev_close(FAR struct file *filep);
|
||||
static ssize_t radio802154dev_read(FAR struct file *filep, FAR char *buffer,
|
||||
size_t len);
|
||||
static ssize_t radio802154dev_write(FAR struct file *filep,
|
||||
FAR const char *buffer, size_t len);
|
||||
static int radio802154dev_ioctl(FAR struct file *filep, int cmd,
|
||||
unsigned long arg);
|
||||
|
||||
/****************************************************************************
|
||||
* Private Data
|
||||
****************************************************************************/
|
||||
|
||||
static const struct file_operations radio802154dev_fops =
|
||||
{
|
||||
radio802154dev_open , /* open */
|
||||
radio802154dev_close, /* close */
|
||||
radio802154dev_read , /* read */
|
||||
radio802154dev_write, /* write */
|
||||
NULL, /* seek */
|
||||
radio802154dev_ioctl /* ioctl */
|
||||
#ifndef CONFIG_DISABLE_POLL
|
||||
, NULL /* poll */
|
||||
#endif
|
||||
#ifndef CONFIG_DISABLE_PSEUDOFS_OPERATIONS
|
||||
, NULL /* unlink */
|
||||
#endif
|
||||
};
|
||||
|
||||
/****************************************************************************
|
||||
* Private Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154dev_semtake
|
||||
*
|
||||
* Description:
|
||||
* Acquire the semaphore used for access serialization.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static void radio802154dev_semtake(FAR struct radio802154_devwrapper_s *dev)
|
||||
{
|
||||
/* Take the semaphore (perhaps waiting) */
|
||||
|
||||
while (sem_wait(&dev->devsem) != 0)
|
||||
{
|
||||
/* The only case that an error should occur here is if
|
||||
* the wait was awakened by a signal.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(errno == EINTR);
|
||||
}
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154dev_semgive
|
||||
*
|
||||
* Description:
|
||||
* Release the semaphore used for access serialization.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static inline void radio802154dev_semgive(FAR struct radio802154_devwrapper_s *dev)
|
||||
{
|
||||
sem_post(&dev->devsem);
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154dev_open
|
||||
*
|
||||
* Description:
|
||||
* Open the 802.15.4 radio character device.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int radio802154dev_open(FAR struct file *filep)
|
||||
{
|
||||
FAR struct inode *inode;
|
||||
FAR struct radio802154_devwrapper_s *dev;
|
||||
|
||||
DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
|
||||
inode = filep->f_inode;
|
||||
dev = inode->i_private;
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
/* Get exclusive access to the driver data structures */
|
||||
|
||||
radio802154dev_semtake(dev);
|
||||
|
||||
if (dev->opened)
|
||||
{
|
||||
/* Already opened */
|
||||
|
||||
return -EMFILE;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Enable interrupts (only rx for now)*/
|
||||
|
||||
//mrf24j40_setreg(dev->spi, MRF24J40_INTCON, ~(MRF24J40_INTCON_RXIE) );
|
||||
//dev->lower->enable(dev->lower, TRUE);
|
||||
|
||||
dev->opened = true;
|
||||
}
|
||||
|
||||
radio802154dev_semgive(dev);
|
||||
return OK;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154dev_close
|
||||
*
|
||||
* Description:
|
||||
* Close the 802.15.4 radio character device.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int radio802154dev_close(FAR struct file *filep)
|
||||
{
|
||||
FAR struct inode *inode;
|
||||
FAR struct radio802154_devwrapper_s *dev;
|
||||
int ret = OK;
|
||||
|
||||
DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
|
||||
inode = filep->f_inode;
|
||||
dev = inode->i_private;
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
/* Get exclusive access to the driver data structures */
|
||||
|
||||
radio802154dev_semtake(dev);
|
||||
|
||||
if (!dev->opened)
|
||||
{
|
||||
/* Driver has not been opened */
|
||||
|
||||
ret = -EIO;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Disable interrupts */
|
||||
|
||||
//mrf24j40_setreg(dev->spi, MRF24J40_INTCON, 0xFF );
|
||||
//dev->lower->enable(dev->lower, FALSE);
|
||||
|
||||
dev->opened = false;
|
||||
}
|
||||
|
||||
radio802154dev_semgive(dev);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154dev_read
|
||||
*
|
||||
* Description:
|
||||
* Return the last received packet.
|
||||
* TODO: Return a packet from the receive queue. The buffer must be a pointer to a
|
||||
* struct ieee802154_packet_s structure, with a correct length.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t radio802154dev_read(FAR struct file *filep, FAR char *buffer, size_t len)
|
||||
{
|
||||
FAR struct inode *inode;
|
||||
FAR struct radio802154_devwrapper_s *dev;
|
||||
FAR struct ieee802154_packet_s *buf;
|
||||
int ret = OK;
|
||||
|
||||
DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
|
||||
inode = filep->f_inode;
|
||||
dev = inode->i_private;
|
||||
DEBUGASSERT(dev != NULL && buffer != NULL);
|
||||
buf = (FAR struct ieee802154_packet_s*)buffer;
|
||||
|
||||
/* Get exclusive access to the driver data structures */
|
||||
|
||||
if (len < sizeof(struct ieee802154_packet_s))
|
||||
{
|
||||
ret = -EINVAL;
|
||||
goto done;
|
||||
}
|
||||
|
||||
#warning Receive needs to be redone!
|
||||
#if 0
|
||||
ret = dev->child->ops->rxenable(dev->child, 1, buf);
|
||||
if (ret < 0)
|
||||
{
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* if no packet is received, this will produce -EAGAIN
|
||||
* The user is responsible for sleeping until sth arrives
|
||||
*/
|
||||
|
||||
#if 0
|
||||
ret = sem_trywait(&dev->child->rxsem);
|
||||
#else
|
||||
ret = sem_wait(&dev->child->rxsem);
|
||||
#endif
|
||||
if (ret < 0)
|
||||
{
|
||||
ret = -errno;
|
||||
goto done;
|
||||
}
|
||||
|
||||
/* Disable read until we have process the current read */
|
||||
|
||||
dev->child->ops->rxenable(dev->child, 0, NULL);
|
||||
ret = buf->len;
|
||||
|
||||
#endif
|
||||
|
||||
done:
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154dev_write
|
||||
*
|
||||
* Description:
|
||||
* Send a packet immediately.
|
||||
* TODO: Put a packet in the send queue. The packet will be sent as soon
|
||||
* as possible. The buffer must point to a struct radio802154_packet_s
|
||||
* with the correct length.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static ssize_t radio802154dev_write(FAR struct file *filep,
|
||||
FAR const char *buffer, size_t len)
|
||||
{
|
||||
FAR struct inode *inode;
|
||||
FAR struct radio802154_devwrapper_s *dev;
|
||||
FAR struct ieee802154_packet_s *packet;
|
||||
FAR struct timespec timeout;
|
||||
int ret = OK;
|
||||
|
||||
DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
|
||||
inode = filep->f_inode;
|
||||
dev = inode->i_private;
|
||||
DEBUGASSERT(dev != NULL);
|
||||
|
||||
/* Get exclusive access to the driver data structures */
|
||||
|
||||
/* TODO: Make this an option or have a new method of doing timeout from
|
||||
* ioctrl.
|
||||
*/
|
||||
|
||||
timeout.tv_sec = 1;
|
||||
timeout.tv_nsec = 0;
|
||||
|
||||
/* Sanity checks */
|
||||
|
||||
if (len < sizeof(struct ieee802154_packet_s))
|
||||
{
|
||||
ret = -EINVAL;
|
||||
//goto done;
|
||||
|
||||
/* TODO Double check I like having assert here. It is a bigger problem
|
||||
* if buffers are to small.
|
||||
*/
|
||||
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
packet = (FAR struct ieee802154_packet_s*) buffer;
|
||||
if (packet->len > 125) /* Max len 125, 2 FCS bytes auto added by mrf */
|
||||
{
|
||||
ret = -EPERM;
|
||||
//goto done;
|
||||
DEBUGASSERT(0);
|
||||
}
|
||||
|
||||
/* Copy packet to normal device TX fifo.
|
||||
* Beacons and GTS transmission will be handled via IOCTLs
|
||||
*/
|
||||
|
||||
#warning Fix this when transmit interface is complete
|
||||
#if 0
|
||||
ret = dev->child->ops->transmit(dev->child, packet);
|
||||
if (ret != packet->len)
|
||||
{
|
||||
ret = -EPERM;
|
||||
goto done;
|
||||
}
|
||||
|
||||
if (sem_timedwait(&dev->child->txsem, &timeout))
|
||||
{
|
||||
wlerr("Radio Device timedout on Tx\n");
|
||||
}
|
||||
#endif
|
||||
|
||||
done:
|
||||
|
||||
/* Okay, tx interrupt received. check transmission status to decide success. */
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154dev_ioctl
|
||||
*
|
||||
* Description:
|
||||
* Control the MRF24J40 device. This is where the real operations happen.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
static int radio802154dev_ioctl(FAR struct file *filep, int cmd,
|
||||
unsigned long arg)
|
||||
{
|
||||
FAR struct inode *inode;
|
||||
FAR struct radio802154_devwrapper_s *dev;
|
||||
FAR struct ieee802154_radio_s *child;
|
||||
int ret = OK;
|
||||
|
||||
DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
|
||||
inode = filep->f_inode;
|
||||
dev = inode->i_private;
|
||||
DEBUGASSERT(dev != NULL && dev->child != NULL);
|
||||
child = dev->child;
|
||||
|
||||
/* Get exclusive access to the driver data structures */
|
||||
|
||||
switch (cmd)
|
||||
{
|
||||
case PHY802154IOC_SET_CHAN:
|
||||
ret = radio802154_setchannel(child, (uint8_t)arg);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_CHAN:
|
||||
ret = radio802154_getchannel(child, (FAR uint8_t*)arg);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_PANID:
|
||||
ret = radio802154_setpanid(child, (uint16_t)arg);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_PANID:
|
||||
ret = radio802154_getpanid(child, (FAR uint16_t*)arg);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_SADDR:
|
||||
ret = radio802154_setsaddr(child, (uint16_t)arg);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_SADDR:
|
||||
ret = radio802154_getsaddr(child, (FAR uint16_t*)arg);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_EADDR:
|
||||
ret = radio802154_seteaddr(child, (FAR uint8_t*)arg);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_EADDR:
|
||||
ret = radio802154_geteaddr(child, (FAR uint8_t*)arg);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_PROMISC:
|
||||
ret = radio802154_setpromisc(child, (bool)arg);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_PROMISC:
|
||||
ret = radio802154_getpromisc(child, (FAR bool*)arg);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_DEVMODE:
|
||||
ret = radio802154_setdevmode(child, (uint8_t)arg);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_DEVMODE:
|
||||
ret = radio802154_getdevmode(child, (FAR uint8_t*)arg);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_TXPWR:
|
||||
ret = radio802154_settxpower(child, (int32_t)arg);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_TXPWR:
|
||||
ret = radio802154_gettxpower(child, (FAR int32_t*)arg);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_SET_CCA:
|
||||
ret = radio802154_setcca(child, (FAR struct ieee802154_cca_s*)arg);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_GET_CCA:
|
||||
ret = radio802154_getcca(child, (FAR struct ieee802154_cca_s*)arg);
|
||||
break;
|
||||
|
||||
case PHY802154IOC_ENERGYDETECT:
|
||||
ret = radio802154_energydetect(child, (FAR uint8_t*)arg);
|
||||
break;
|
||||
|
||||
default:
|
||||
ret = child->ops->ioctl(child, cmd,arg);
|
||||
break;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154dev_register
|
||||
*
|
||||
* Description:
|
||||
* Register a character driver to access the IEEE 802.15.4 radio from
|
||||
* user-space
|
||||
*
|
||||
* Input Parameters:
|
||||
* radio - Pointer to the radio struct to be registerd.
|
||||
* devname - The name of the IEEE 802.15.4 radio to be registered.
|
||||
*
|
||||
* Returned Values:
|
||||
* Zero (OK) is returned on success. Otherwise a negated errno value is
|
||||
* returned to indicate the nature of the failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154dev_register(FAR struct ieee802154_radio_s *radio,
|
||||
FAR char *devname)
|
||||
{
|
||||
FAR struct radio802154_devwrapper_s *dev;
|
||||
|
||||
dev = kmm_zalloc(sizeof(struct radio802154_devwrapper_s));
|
||||
if (dev == NULL)
|
||||
{
|
||||
return -ENOMEM;
|
||||
}
|
||||
|
||||
dev->child = radio;
|
||||
|
||||
sem_init(&dev->devsem, 0, 1); /* Allow the device to be opened once before blocking */
|
||||
|
||||
return register_driver(devname, &radio802154dev_fops, 0666, dev);
|
||||
}
|
@ -1,487 +0,0 @@
|
||||
/****************************************************************************
|
||||
* wireless/ieee802154/radio802154_ioctl.c
|
||||
*
|
||||
* 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
|
||||
* 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.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
#include <debug.h>
|
||||
|
||||
#include <nuttx/wireless/ieee802154/ieee802154_radio.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define RADIO_IOCTL(r,c,a) \
|
||||
(r)->ops->ioctl((r),(c),(unsigned long)((uintptr_t)(a)))
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_setchannel
|
||||
*
|
||||
* Description:
|
||||
* Define the current radio channel the device is operating on.
|
||||
* In the 2.4 GHz, there are 16 channels, each 2 MHz wide, 5 MHz spacing:
|
||||
* Chan MHz Chan MHz Chan MHz Chan MHz
|
||||
* 11 2405 15 2425 19 2445 23 2465
|
||||
* 12 2410 16 2430 20 2450 24 2470
|
||||
* 13 2415 17 2435 21 2455 25 2475
|
||||
* 14 2420 18 2440 22 2460 26 2480
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_setchannel(FAR struct ieee802154_radio_s *radio,
|
||||
uint8_t chan)
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
arg.channel = chan;
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_SET_CHAN, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_SET_CHAN failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_getchannel
|
||||
*
|
||||
* Description:
|
||||
* Define the current radio channel the device is operating on.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_getchannel(FAR struct ieee802154_radio_s *radio,
|
||||
FAR uint8_t *chan)
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_GET_CHAN, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_GET_CHAN failed: %d\n", ret);
|
||||
}
|
||||
|
||||
*chan = arg.channel;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_setpanid
|
||||
*
|
||||
* Description:
|
||||
* Define the PAN ID the device is operating on.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_setpanid(FAR struct ieee802154_radio_s *radio,
|
||||
uint16_t panid)
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
arg.panid = panid;
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_SET_PANID, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_SET_PANID failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_getpanid
|
||||
*
|
||||
* Description:
|
||||
* Define the current PAN ID the device is operating on.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_getpanid(FAR struct ieee802154_radio_s *radio,
|
||||
FAR uint16_t *panid)
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_GET_PANID, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_GET_PANID failed: %d\n", ret);
|
||||
}
|
||||
|
||||
*panid = arg.panid;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_setsaddr
|
||||
*
|
||||
* Description:
|
||||
* Define the device short address. The following addresses are special:
|
||||
* FFFEh : Broadcast
|
||||
* FFFFh : Unspecified
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_setsaddr(FAR struct ieee802154_radio_s *radio,
|
||||
uint16_t saddr)
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
arg.saddr = saddr;
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_SET_SADDR, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_SET_SADDR failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_getsaddr
|
||||
*
|
||||
* Description:
|
||||
* Define the current short address the device is using.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_getsaddr(FAR struct ieee802154_radio_s *radio,
|
||||
FAR uint16_t *saddr)
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_GET_SADDR, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_GET_SADDR failed: %d\n", ret);
|
||||
}
|
||||
|
||||
*saddr = arg.saddr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_seteaddr
|
||||
*
|
||||
* Description:
|
||||
* Define the device extended address. The following addresses are special:
|
||||
* FFFFFFFFFFFFFFFFh : Unspecified
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_seteaddr(FAR struct ieee802154_radio_s *radio,
|
||||
FAR uint8_t *eaddr)
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
memcpy(arg.eaddr, eaddr, EADDR_SIZE); /* REVISIT */
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_SET_EADDR, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_SET_EADDR failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_geteaddr
|
||||
*
|
||||
* Description:
|
||||
* Define the current extended address the device is using.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_geteaddr(FAR struct ieee802154_radio_s *radio,
|
||||
FAR uint8_t *eaddr)
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_GET_EADDR, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_GET_EADDR failed: %d\n", ret);
|
||||
}
|
||||
|
||||
memcpy(eaddr, arg.eaddr, EADDR_SIZE); /* REVISIT */
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_setpromisc
|
||||
*
|
||||
* Description:
|
||||
* Set the device into promiscuous mode, e.g do not filter any incoming
|
||||
* frame.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_setpromisc(FAR struct ieee802154_radio_s *radio,
|
||||
bool promisc)
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
arg.promisc = promisc;
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_SET_PROMISC, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_SET_PROMISC failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_getpromisc
|
||||
*
|
||||
* Description:
|
||||
* Get the device receive mode.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_getpromisc(FAR struct ieee802154_radio_s *radio,
|
||||
FAR bool *promisc)
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_GET_PROMISC, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_GET_PROMISC failed: %d\n", ret);
|
||||
}
|
||||
|
||||
*promisc = arg.promisc;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_setdevmode
|
||||
*
|
||||
* Description:
|
||||
* Define the device behaviour: normal end device or coordinator
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_setdevmode(FAR struct ieee802154_radio_s *radio,
|
||||
uint8_t mode)
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
arg.devmode = mode;
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_SET_DEVMODE, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_SET_DEVMODE failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_setdevmode
|
||||
*
|
||||
* Description:
|
||||
* Return the current device mode
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_getdevmode(FAR struct ieee802154_radio_s *radio,
|
||||
FAR uint8_t *mode)
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_GET_DEVMODE, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_GET_DEVMODE failed: %d\n", ret);
|
||||
}
|
||||
|
||||
*mode = arg.devmode;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_settxpower
|
||||
*
|
||||
* Description:
|
||||
* Define the transmit power. Value is passed in mBm, it is rounded to
|
||||
* the nearest value. Some MRF modules have a power amplifier, this routine
|
||||
* does not care about this. We only change the CHIP output power.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_settxpower(FAR struct ieee802154_radio_s *radio,
|
||||
int32_t txpwr)
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
arg.txpwr = txpwr;
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_SET_TXPWR, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_SET_TXPWR failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_gettxpower
|
||||
*
|
||||
* Description:
|
||||
* Return the actual transmit power, in mBm.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_gettxpower(FAR struct ieee802154_radio_s *radio,
|
||||
FAR int32_t *txpwr)
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_GET_TXPWR, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_GET_TXPWR failed: %d\n", ret);
|
||||
}
|
||||
|
||||
*txpwr = arg.txpwr;
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_setcca
|
||||
*
|
||||
* Description:
|
||||
* Define the Clear Channel Assessement method.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_setcca(FAR struct ieee802154_radio_s *radio,
|
||||
FAR struct ieee802154_cca_s *cca)
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
memcpy(&arg.cca, cca, sizeof(struct ieee802154_cca_s));
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_SET_CCA, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_SET_CCA failed: %d\n", ret);
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_getcca
|
||||
*
|
||||
* Description:
|
||||
* Return the Clear Channel Assessement method.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_getcca(FAR struct ieee802154_radio_s *radio,
|
||||
FAR struct ieee802154_cca_s *cca)
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_GET_CCA, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_GET_CCA failed: %d\n", ret);
|
||||
}
|
||||
|
||||
memcpy(cca, &arg.cca, sizeof(struct ieee802154_cca_s));
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_energydetect
|
||||
*
|
||||
* Description:
|
||||
* Measure the RSSI level for the current channel.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_energydetect(FAR struct ieee802154_radio_s *radio,
|
||||
FAR uint8_t *energy)
|
||||
|
||||
{
|
||||
union ieee802154_radioarg_u arg;
|
||||
int ret;
|
||||
|
||||
ret = RADIO_IOCTL(radio, PHY802154IOC_ENERGYDETECT, &arg);
|
||||
if (ret < 0)
|
||||
{
|
||||
wlerr("ERROR: PHY802154IOC_ENERGYDETECT failed: %d\n", ret);
|
||||
}
|
||||
|
||||
*energy = arg.energy;
|
||||
return ret;
|
||||
}
|
@ -1,255 +0,0 @@
|
||||
/****************************************************************************
|
||||
* wireless/ieee802154/radio802154_ioctl.h
|
||||
*
|
||||
* 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
|
||||
* 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 __WIRELESS_IEEE802154_RADIO802154_IOCTL_H
|
||||
#define __WIRELESS_IEEE802154_RADIO802154_IOCTL_H 1
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
#include <nuttx/wireless/ieee802154/ieee802154_radio.h>
|
||||
|
||||
#include "radio802154_ioctl.h"
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_setchannel
|
||||
*
|
||||
* Description:
|
||||
* Define the current radio channel the device is operating on.
|
||||
* In the 2.4 GHz, there are 16 channels, each 2 MHz wide, 5 MHz spacing:
|
||||
* Chan MHz Chan MHz Chan MHz Chan MHz
|
||||
* 11 2405 15 2425 19 2445 23 2465
|
||||
* 12 2410 16 2430 20 2450 24 2470
|
||||
* 13 2415 17 2435 21 2455 25 2475
|
||||
* 14 2420 18 2440 22 2460 26 2480
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_setchannel(FAR struct ieee802154_radio_s *radio,
|
||||
uint8_t chan);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_getchannel
|
||||
*
|
||||
* Description:
|
||||
* Define the current radio channel the device is operating on.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_getchannel(FAR struct ieee802154_radio_s *radio,
|
||||
FAR uint8_t *chan);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_setpanid
|
||||
*
|
||||
* Description:
|
||||
* Define the PAN ID the device is operating on.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_setpanid(FAR struct ieee802154_radio_s *radio,
|
||||
uint16_t panid);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_getpanid
|
||||
*
|
||||
* Description:
|
||||
* Define the current PAN ID the device is operating on.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_getpanid(FAR struct ieee802154_radio_s *radio,
|
||||
FAR uint16_t *panid);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_setsaddr
|
||||
*
|
||||
* Description:
|
||||
* Define the device short address. The following addresses are special:
|
||||
* FFFEh : Broadcast
|
||||
* FFFFh : Unspecified
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_setsaddr(FAR struct ieee802154_radio_s *radio,
|
||||
uint16_t saddr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_getsaddr
|
||||
*
|
||||
* Description:
|
||||
* Define the current short address the device is using.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_getsaddr(FAR struct ieee802154_radio_s *radio,
|
||||
FAR uint16_t *saddr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_seteaddr
|
||||
*
|
||||
* Description:
|
||||
* Define the device extended address. The following addresses are special:
|
||||
* FFFFFFFFFFFFFFFFh : Unspecified
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_seteaddr(FAR struct ieee802154_radio_s *radio,
|
||||
FAR uint8_t *eaddr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_geteaddr
|
||||
*
|
||||
* Description:
|
||||
* Define the current extended address the device is using.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_geteaddr(FAR struct ieee802154_radio_s *radio,
|
||||
FAR uint8_t *eaddr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_setpromisc
|
||||
*
|
||||
* Description:
|
||||
* Set the device into promiscuous mode, e.g do not filter any incoming
|
||||
* frame.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_setpromisc(FAR struct ieee802154_radio_s *radio,
|
||||
bool promisc);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_getpromisc
|
||||
*
|
||||
* Description:
|
||||
* Get the device receive mode.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_getpromisc(FAR struct ieee802154_radio_s *radio,
|
||||
FAR bool *promisc);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_setdevmode
|
||||
*
|
||||
* Description:
|
||||
* Define the device behaviour: normal end device or coordinator
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_setdevmode(FAR struct ieee802154_radio_s *radio,
|
||||
uint8_t mode);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_setdevmode
|
||||
*
|
||||
* Description:
|
||||
* Return the current device mode
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_getdevmode(FAR struct ieee802154_radio_s *radio,
|
||||
FAR uint8_t *mode);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_settxpower
|
||||
*
|
||||
* Description:
|
||||
* Define the transmit power. Value is passed in mBm, it is rounded to
|
||||
* the nearest value. Some MRF modules have a power amplifier, this routine
|
||||
* does not care about this. We only change the CHIP output power.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_settxpower(FAR struct ieee802154_radio_s *radio,
|
||||
int32_t txpwr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_gettxpower
|
||||
*
|
||||
* Description:
|
||||
* Return the actual transmit power, in mBm.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_gettxpower(FAR struct ieee802154_radio_s *radio,
|
||||
FAR int32_t *txpwr);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_setcca
|
||||
*
|
||||
* Description:
|
||||
* Define the Clear Channel Assessement method.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_setcca(FAR struct ieee802154_radio_s *radio,
|
||||
FAR struct ieee802154_cca_s *cca);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_getcca
|
||||
*
|
||||
* Description:
|
||||
* Return the Clear Channel Assessement method.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_getcca(FAR struct ieee802154_radio_s *radio,
|
||||
FAR struct ieee802154_cca_s *cca);
|
||||
|
||||
/****************************************************************************
|
||||
* Name: radio802154_energydetect
|
||||
*
|
||||
* Description:
|
||||
* Measure the RSSI level for the current channel.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int radio802154_energydetect(FAR struct ieee802154_radio_s *radio,
|
||||
FAR uint8_t *energy);
|
||||
|
||||
#endif /* __WIRELESS_IEEE802154_RADIO802154_IOCTL_H */
|
Loading…
Reference in New Issue
Block a user