Merged in merlin17/nuttx/ieee802154 (pull request #318)

Ieee802154

Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
Anthony Merlino
2017-04-15 17:33:57 +00:00
committed by Gregory Nutt
5 changed files with 849 additions and 318 deletions
File diff suppressed because it is too large Load Diff
@@ -83,22 +83,27 @@
* Request and Response primitives.
*/
#define MAC802154IOC_MLME_ASSOC_REQUEST _MAC802154IOC(0x0001)
#define MAC802154IOC_MLME_ASSOC_RESPONSE _MAC802154IOC(0x0002)
#define MAC802154IOC_MLME_DISASSOC_REQUEST _MAC802154IOC(0x0003)
#define MAC802154IOC_MLME_GET_REQUEST _MAC802154IOC(0x0004)
#define MAC802154IOC_MLME_GTS_REQUEST _MAC802154IOC(0x0005)
#define MAC802154IOC_MLME_ORPHAN_RESPONSE _MAC802154IOC(0x0006)
#define MAC802154IOC_MLME_RESET_REQUEST _MAC802154IOC(0x0007)
#define MAC802154IOC_MLME_RXENABLE_REQUEST _MAC802154IOC(0x0008)
#define MAC802154IOC_MLME_SCAN_REQUEST _MAC802154IOC(0x0009)
#define MAC802154IOC_MLME_SET_REQUEST _MAC802154IOC(0x000A)
#define MAC802154IOC_MLME_START_REQUEST _MAC802154IOC(0x000B)
#define MAC802154IOC_MLME_SYNC_REQUEST _MAC802154IOC(0x000C)
#define MAC802154IOC_MLME_POLL_REQUEST _MAC802154IOC(0x000D)
#define MAC802154IOC_MLME_DPS_REQUEST _MAC802154IOC(0x000E)
#define MAC802154IOC_MLME_SOUNDING_REQUEST _MAC802154IOC(0x000F)
#define MAC802154IOC_MLME_CALIBRATE_REQUEST _MAC802154IOC(0x0010)
#define MAC802154IOC_MCPS_REGISTER _MAC802154IOC(0x0001)
#define MAC802154IOC_MLME_REGISER _MAC802154IOC(0x0002);
#define MAC802154IOC_MLME_ASSOC_REQUEST _MAC802154IOC(0x0003)
#define MAC802154IOC_MLME_ASSOC_RESPONSE _MAC802154IOC(0x0004)
#define MAC802154IOC_MLME_DISASSOC_REQUEST _MAC802154IOC(0x0005)
#define MAC802154IOC_MLME_GET_REQUEST _MAC802154IOC(0x0006)
#define MAC802154IOC_MLME_GTS_REQUEST _MAC802154IOC(0x0007)
#define MAC802154IOC_MLME_ORPHAN_RESPONSE _MAC802154IOC(0x0008)
#define MAC802154IOC_MLME_RESET_REQUEST _MAC802154IOC(0x0009)
#define MAC802154IOC_MLME_RXENABLE_REQUEST _MAC802154IOC(0x000A)
#define MAC802154IOC_MLME_SCAN_REQUEST _MAC802154IOC(0x000B)
#define MAC802154IOC_MLME_SET_REQUEST _MAC802154IOC(0x000C)
#define MAC802154IOC_MLME_START_REQUEST _MAC802154IOC(0x000D)
#define MAC802154IOC_MLME_SYNC_REQUEST _MAC802154IOC(0x000E)
#define MAC802154IOC_MLME_POLL_REQUEST _MAC802154IOC(0x000F)
#define MAC802154IOC_MLME_DPS_REQUEST _MAC802154IOC(0x0010)
#define MAC802154IOC_MLME_SOUNDING_REQUEST _MAC802154IOC(0x0011)
#define MAC802154IOC_MLME_CALIBRATE_REQUEST _MAC802154IOC(0x0012)
/* IEEE 802.15.4 MAC Interface **********************************************/
@@ -141,19 +146,19 @@
#define IEEE802154_FRAMECTRL_VERSION 0x3000 /* Source addressing mode, bits 12-13 */
#define IEEE802154_FRAMECTRL_SADDR 0xC000 /* Source addressing mode, bits 14-15 */
#define IEEE802154_FRAMECTRL_SHIFT_FTYPE 0 /* Frame type, bits 0-2 */
#define IEEE802154_FRAMECTRL_SHIFT_SEC 3 /* Security Enabled, bit 3 */
#define IEEE802154_FRAMECTRL_SHIFT_PEND 4 /* Frame pending, bit 4 */
#define IEEE802154_FRAMECTRL_SHIFT_ACKREQ 5 /* Acknowledge request, bit 5 */
#define IEEE802154_FRAMECTRL_SHIFT_PANIDCOMP 6 /* PAN ID Compression, bit 6 */
#define IEEE802154_FRAMECTRL_SHIFT_DADDR 10 /* Dest addressing mode, bits 10-11 */
#define IEEE802154_FRAMECTRL_SHIFT_VERSION 12 /* Source addressing mode, bits 12-13 */
#define IEEE802154_FRAMECTRL_SHIFT_SADDR 14 /* Source addressing mode, bits 14-15 */
#define IEEE802154_FRAMECTRL_SHIFT_FTYPE 0 /* Frame type, bits 0-2 */
#define IEEE802154_FRAMECTRL_SHIFT_SEC 3 /* Security Enabled, bit 3 */
#define IEEE802154_FRAMECTRL_SHIFT_PEND 4 /* Frame pending, bit 4 */
#define IEEE802154_FRAMECTRL_SHIFT_ACKREQ 5 /* Acknowledge request, bit 5 */
#define IEEE802154_FRAMECTRL_SHIFT_PANIDCOMP 6 /* PAN ID Compression, bit 6 */
#define IEEE802154_FRAMECTRL_SHIFT_DADDR 10 /* Dest addressing mode, bits 10-11 */
#define IEEE802154_FRAMECTRL_SHIFT_VERSION 12 /* Source addressing mode, bits 12-13 */
#define IEEE802154_FRAMECTRL_SHIFT_SADDR 14 /* Source addressing mode, bits 14-15 */
/* IEEE 802.15.4 PHY constants */
#define IEEE802154_MAX_PHY_PACKET_SIZE 127
#define IEEE802154_TURN_AROUND_TIME 12 /*symbol periods*/
#define IEEE802154_TURN_AROUND_TIME 12 /*symbol periods*/
/* IEEE 802.15.4 MAC constants */
@@ -170,8 +175,13 @@
(IEEE802154_MAX_PHY_PACKET_SIZE - IEEE802154_MAX_BEACON_OVERHEAD)
#define IEEE802154_MAX_LOST_BEACONS 4
#define IEEE802514_MIN_MPDU_OVERHEAD 9
#define IEEE802154_MAX_MPDU_UNSEC_OVERHEAD 25
#define IEEE802154_MIN_MPDU_OVERHEAD 9
#define IEEE802154_MAX_UNSEC_MHR_OVERHEAD 23
#define IEEE802154_MFR_LENGTH 2
#define IEEE802154_MAX_MPDU_UNSEC_OVERHEAD \
(IEEE802154_MAX_UNSEC_MHR_OVERHEAD + IEEE802154_MFR_LENGTH)
#define IEEE802154_MAX_SAFE_MAC_PAYLOAD_SIZE \
(IEEE802154_MAX_PHY_PACKET_SIZE - IEEE802154_MAX_MPDU_UNSEC_OVERHEAD)
@@ -339,59 +349,18 @@ struct ieee802154_addr_s
{
/* Address mode. Short or Extended */
enum ieee802154_addr_mode_e ia_mode;
enum ieee802154_addr_mode_e mode;
uint16_t ia_panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */
uint16_t panid; /* PAN identifier, can be IEEE802154_PAN_UNSPEC */
union
{
uint16_t _ia_saddr; /* short address */
uint8_t _ia_eaddr[8]; /* extended address */
} ia_addr;
#define ia_saddr ia_addr._ia_saddr
#define ia_eaddr ia_addr._ia_eaddr
uint16_t saddr; /* short address */
uint8_t eaddr[8]; /* extended address */
};
};
#define IEEE802154_ADDRSTRLEN 22 /* (2*2+1+8*2, PPPP/EEEEEEEEEEEEEEEE) */
struct ieee802154_framecontrol_s
{
/* Frame type
*
* Should be a value from: ieee802154_frametype_e
*
* Bits 0-1
*/
uint16_t frame_type : 3;
uint16_t security_en : 1; /* Security Enabled flag, bit 3 */
uint16_t frame_pending : 1; /* Frame Pending flag, bit 4 */
uint16_t ack_req : 1; /* Acknowledge Request flag, bit 5 */
uint16_t panid_comp : 1; /* PAN ID Compression flag, bit 6 */
uint16_t reserved : 3; /* Reserved, bits 7-9 */
/* Destination Addressing Mode
*
* Should be a value from: ieee802154_addr_mode_e
*
* Bits 10-11
*/
uint16_t dest_addr_mode : 2;
uint16_t frame_version : 2; /* Frame Version, bits 12-13 */
/* Source Addressing Mode
*
* Should be a value from: ieee802154_addr_mode_e
*
* Bits 14-15
*/
uint16_t src_addr_mode : 2;
};
#ifdef CONFIG_IEEE802154_SECURITY
struct ieee802154_security_s
{
@@ -444,7 +413,7 @@ struct ieee802154_frame_s
struct ieee802154_data_req_s
{
enum ieee802154_addr_mode_e src_addr_mode; /* Source Address Mode */
struct ieee802154_addr_s dest__addr; /* Destination Address */
struct ieee802154_addr_s dest_addr; /* Destination Address */
/* Number of bytes contained in the MAC Service Data Unit (MSDU)
* to be transmitted by the MAC sublayer enitity
@@ -497,7 +466,7 @@ struct ieee802154_data_req_s
};
#define SIZEOF_IEEE802154_DATA_REQ_S(n) \
(sizeof(struct ieee802154_data_req_s) + (n))
(sizeof(struct ieee802154_data_req_s) + (n) - 1)
struct ieee802154_data_conf_s
{
@@ -911,17 +880,17 @@ struct ieee802154_maccb_s
CODE void (*conf_disassociate)(MACHANDLE mac, int status);
/* PIvoata returned */
/* PIB data returned */
CODE void (*conf_get)(MACHANDLE mac, int status, int attribute,
FAR uint8_t *value, int valuelen);
/* GTvoanagement completed */
/* GTS management completed */
CODE void (*conf_gts)(MACHANDLE mac, FAR uint8_t *characteristics,
int status);
/* MAveset completed */
/* MAC reset completed */
CODE void (*conf_reset)(MACHANDLE mac, int status);
@@ -157,19 +157,51 @@ struct ieee802154_netradio_s
#endif
/* IEEE802.15.4 Radio Interface Operations **********************************/
struct ieee802154_trans_s
{
uint8_t retry_count; /* The number of retries remaining */
uint8_t msdu_handle; /* The msdu handle identifying the transaction */
uint16_t psdu_length; /* The length of the PSDU */
/* The PHY Service Data Unit (PSDU) buffer representing the frame to be
* transmitted. This must be at the end of the struct to allow the array
* to continue and make the struct "variable length". Users should allocate
* memory using the SIZEOF_MAC802154_TRANSACTION_S macro below */
uint8_t psdu[CONFIG_IEEE802154_MTU];
};
struct ieee802154_radio_s; /* Forward reference */
struct ieee802154_phyif_s
{
CODE int (*poll_csma) (FAR struct ieee802154_phyif_s *phyif,
FAR struct ieee802154_txdesc_s *tx_desc,
uint8_t *buf);
CODE int (*poll_gts) (FAR struct ieee802154_phyif_s *phyif,
FAR struct ieee802154_txdesc_s *tx_desc,
uint8_t *buf);
/* Driver-specific information */
void * priv;
};
struct ieee802154_radioops_s
{
CODE int (*bind) (FAR struct ieee802154_radio_s *dev,
FAR const struct ieee802154_phyif_s *phyif);
CODE int (*ioctl)(FAR struct ieee802154_radio_s *ieee, int cmd,
unsigned long arg);
CODE int (*rxenable)(FAR struct ieee802154_radio_s *dev, bool state,
FAR struct ieee802154_packet_s *packet);
CODE int (*transmit)(FAR struct ieee802154_radio_s *dev,
FAR struct ieee802154_packet_s *packet);
/* TODO beacon/sf order */
};
struct ieee802154_radio_s
File diff suppressed because it is too large Load Diff
+136 -18
View File
@@ -77,15 +77,33 @@ struct mac802154_devwrapper_s
FAR struct mac802154_open_s *md_open;
FAR struct mac802154dev_dwait_s *md_dwait;
#ifndef CONFIG_DISABLE_SIGNALS
/* MCPS Service notification information */
struct mac802154dev_notify_s md_mcps_notify;
pid_t md_mcps_pid;
/* MLME Service notification information */
struct mac802154dev_notify_s md_mlme_notify;
pid_t md_mlme_pid;
#endif
};
struct mac802154dev_notify_s
{
uint8_t mn_signo; /* Signal number to use in the notification */
};
/* This structure describes the state of one open mac driver instance */
struct mac802154_open_s
struct mac802154dev_open_s
{
/* Supports a singly linked list */
FAR struct mac802154_open_s *md_flink;
FAR struct mac802154dev_open_s *md_flink;
/* The following will be true if we are closing */
@@ -96,7 +114,7 @@ struct mac802154dev_dwait_s
{
uint8_t mw_handle; /* The msdu handle identifying the frame */
sem_t mw_sem; /* The semaphore used to signal the completion */
int status; /* The success/error of the transaction */
int mw_status; /* The success/error of the transaction */
/* Supports a singly linked list */
@@ -181,7 +199,7 @@ static int mac802154dev_open(FAR struct file *filep)
{
FAR struct inode *inode;
FAR struct mac802154_devwrapper_s *dev;
FAR struct mac802154_open_s *opriv;
FAR struct mac802154dev_open_s *opriv;
int ret;
DEBUGASSERT(filep != NULL && filep->f_inode != NULL);
@@ -201,8 +219,8 @@ static int mac802154dev_open(FAR struct file *filep)
/* Allocate a new open struct */
opriv = (FAR struct mac802154_open_s *)
kmm_zalloc(sizeof(struct mac802154_open_s));
opriv = (FAR struct mac802154dev_open_s *)
kmm_zalloc(sizeof(struct mac802154dev_open_s));
if (!opriv)
{
@@ -238,9 +256,9 @@ static int mac802154dev_close(FAR struct file *filep)
{
FAR struct inode *inode;
FAR struct mac802154_devwrapper_s *dev;
FAR struct mac802154_open_s *opriv;
FAR struct mac802154_open_s *curr;
FAR struct mac802154_open_s *prev;
FAR struct mac802154dev_open_s *opriv;
FAR struct mac802154dev_open_s *curr;
FAR struct mac802154dev_open_s *prev;
irqstate_t flags;
bool closing;
int ret;
@@ -431,7 +449,13 @@ static ssize_t mac802154dev_write(FAR struct file *filep,
/* Wait for the DATA.confirm callback to be called for our handle */
sem_wait(&dwait.mw_sem);
if(sem_wait(dwait.mw_sem) < 0)
{
/* This should only happen if the wait was canceled by an signal */
DEBUGASSERT(errno == EINTR);
return -EINTR;
}
/* The unlinking of the wait struct happens inside the callback. This
* is more efficient since it will already have to find the struct in
@@ -476,6 +500,57 @@ static int mac802154dev_ioctl(FAR struct file *filep, int cmd,
switch (cmd)
{
#ifndef CONFIG_DISABLE_SIGNALS
/* Command: MAC802154IOC_MLME_REGISTER, MAC802154IOC_MCPS_REGISTER
* Description: Register to receive a signal whenever there is a
* event primitive sent from the MAC layer.
* Argument: A read-only pointer to an instance of struct
* mac802154dev_notify_s
* Return: Zero (OK) on success. Minus one will be returned on
* failure with the errno value set appropriately.
*/
case MAC802154IOC_MLME_REGISTER:
{
FAR struct mac802154dev_notify_s *notify =
(FAR struct mac802154dev_notify_s *)((uintptr_t)arg);
if (notify)
{
/* Save the notification events */
dev->md_mlme_notify.mn_signo = notify->mn_signo;
dev->md_mlme_pid = getpid();
return OK;
}
}
break;
case MAC802154IOC_MCPS_REGISTER:
{
FAR struct mac802154dev_notify_s *notify =
(FAR struct mac802154dev_notify_s *)((uintptr_t)arg);
if (notify)
{
/* Save the notification events */
dev->md_mcps_notify.mn_signo = notify->mn_signo;
dev->md_mcps_pid = getpid();
return OK;
}
}
break;
#endif
case MAC802154IOC_MLME_ASSOC_REQUEST:
{
FAR struct ieee802154_assoc_req_s *req =
(FAR struct ieee802154_assoc_req_s *)((uintptr_t)arg);
}
break;
default:
wlerr("ERROR: Unrecognized command %ld\n", cmd);
ret = -EINVAL;
@@ -501,20 +576,63 @@ void mac802154dev_conf_data(MACHANDLE mac,
*/
#warning Missing logic
/* Get exclusive access to the driver structure */
ret = mac802154dev_takesem(&dev->md_exclsem);
if (ret < 0)
{
wlerr("ERROR: mac802154dev_takesem failed: %d\n", ret);
return;
}
/* Get exclusive access to the driver structure. We don't care about any
* signals so if we see one, just go back to trying to get access again */
while(mac802154dev_takesem(&dev->md_exclsem) != OK);
/* Search to see if there is a dwait pending for this transaction */
for (prev = NULL, curr = dev->md_dwait;
curr && curr->mw_handle != conf->msdu_handle;
prev = curr, curr = curr->mw_flink);
/* If a dwait is found */
if (curr)
{
/* Unlink the structure from the list. The struct should be allocated on
* the calling write's stack, so we don't need to worry about deallocating
* here */
if (prev)
{
prev->mw_flink = curr->mw_flink;
}
else
{
dev->md_dwait = curr->mw_flink;
}
/* Copy the transmission status into the dwait struct */
curr->mw_status = conf->msdu_handle;
/* Wake the thread waiting for the data transmission */
sem_post(&curr->mw_sem);
/* Release the driver */
mac802154dev_givesem(&dev->md_exclsem);
}
#ifndef CONFIG_DISABLE_SIGNALS
/* Send a signal to the registered application */
#ifdef CONFIG_CAN_PASS_STRUCTS
/* Copy the status as the signal data to be optionally used by app */
union sigval value;
value.sival_int = (int)conf->status;
(void)sigqueue(dev->md_mcps_pid, dev->md_mcps_notify.mn_signo, value);
#else
(void)sigqueue(dev->md_mcps_pid, dev->md_mcps_notify.mn_signo,
value.sival_ptr);
#endif
#endif
}
/****************************************************************************