wireless/ieee802154: i8sak adds event handling from MAC char driver
This commit is contained in:
parent
e8f3d7f46b
commit
6c7e1faa36
@ -54,12 +54,9 @@
|
|||||||
/* libmac *******************************************************************/
|
/* libmac *******************************************************************/
|
||||||
/* Character driver IOCTL helpers */
|
/* Character driver IOCTL helpers */
|
||||||
|
|
||||||
#if 0
|
|
||||||
int ieee802154_mcps_register(int fd,
|
int ieee802154_enableevents(int fd, bool enable);
|
||||||
FAR struct ieee802154_mcps_register_s *info);
|
|
||||||
int ieee802154_mlme_register(int fd,
|
|
||||||
FAR struct ieee802154_mlme_register_s *info);
|
|
||||||
#endif
|
|
||||||
int ieee802154_assoc_req(int fd, FAR struct ieee802154_assoc_req_s *req);
|
int ieee802154_assoc_req(int fd, FAR struct ieee802154_assoc_req_s *req);
|
||||||
int ieee802154_assoc_resp(int fd, FAR struct ieee802154_assoc_resp_s *resp);
|
int ieee802154_assoc_resp(int fd, FAR struct ieee802154_assoc_resp_s *resp);
|
||||||
int ieee802154_disassoc_req(int fd,
|
int ieee802154_disassoc_req(int fd,
|
||||||
|
@ -6,7 +6,9 @@
|
|||||||
config IEEE802154_I8SAK
|
config IEEE802154_I8SAK
|
||||||
bool "IEEE 802.15.4 Swiss Army Knife"
|
bool "IEEE 802.15.4 Swiss Army Knife"
|
||||||
default n
|
default n
|
||||||
|
select IEEE802154_MAC_DEV
|
||||||
select IEEE802154_LIBUTILS
|
select IEEE802154_LIBUTILS
|
||||||
|
select IEEE802154_LIBMAC
|
||||||
---help---
|
---help---
|
||||||
Enable the IEEE 802.15.4 Swiss Army Knife
|
Enable the IEEE 802.15.4 Swiss Army Knife
|
||||||
|
|
||||||
|
@ -90,6 +90,7 @@ typedef void (*cmd3_t)(FAR const char *devname, FAR const char *arg1,
|
|||||||
|
|
||||||
static int i8_tx(int fd);
|
static int i8_tx(int fd);
|
||||||
static int i8_parse_payload(FAR const char *str);
|
static int i8_parse_payload(FAR const char *str);
|
||||||
|
static pthread_addr_t i8_eventlistener(pthread_addr_t arg);
|
||||||
|
|
||||||
static void i8_tx_cmd(FAR const char *devname, FAR const char *payload);
|
static void i8_tx_cmd(FAR const char *devname, FAR const char *payload);
|
||||||
static void i8_sniffer_cmd(FAR const char *devname);
|
static void i8_sniffer_cmd(FAR const char *devname);
|
||||||
@ -121,6 +122,7 @@ int g_blaster_period = 0;
|
|||||||
|
|
||||||
bool g_sniffer_daemon_started = false;
|
bool g_sniffer_daemon_started = false;
|
||||||
bool g_blaster_daemon_started = false;
|
bool g_blaster_daemon_started = false;
|
||||||
|
bool g_eventlistener_run = false;
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Public Data
|
* Public Data
|
||||||
@ -189,6 +191,10 @@ static int i8_sniffer_daemon(int argc, FAR char *argv[])
|
|||||||
|
|
||||||
g_sniffer_daemon_started = true;
|
g_sniffer_daemon_started = true;
|
||||||
|
|
||||||
|
/* We don't care about any events, so disable them */
|
||||||
|
|
||||||
|
ret = ieee802154_enableevents(fd, false);
|
||||||
|
|
||||||
/* Enable promiscuous mode */
|
/* Enable promiscuous mode */
|
||||||
|
|
||||||
ret = ieee802154_setpromisc(fd, true);
|
ret = ieee802154_setpromisc(fd, true);
|
||||||
@ -227,6 +233,8 @@ done:
|
|||||||
|
|
||||||
ret = ieee802154_setpromisc(fd, false);
|
ret = ieee802154_setpromisc(fd, false);
|
||||||
|
|
||||||
|
ret = ieee802154_enableevents(fd, true);
|
||||||
|
|
||||||
printf("sniffer_daemon: closing");
|
printf("sniffer_daemon: closing");
|
||||||
close(fd);
|
close(fd);
|
||||||
g_sniffer_daemon_started = false;
|
g_sniffer_daemon_started = false;
|
||||||
@ -288,6 +296,7 @@ static void i8_blaster_cmd(FAR const char *devname, FAR const char *period_ms,
|
|||||||
static int i8_blaster_daemon(int argc, FAR char *argv[])
|
static int i8_blaster_daemon(int argc, FAR char *argv[])
|
||||||
{
|
{
|
||||||
int ret, fd;
|
int ret, fd;
|
||||||
|
pthread_t eventthread;
|
||||||
|
|
||||||
fd = open(argv[1], O_RDWR);
|
fd = open(argv[1], O_RDWR);
|
||||||
if (fd < 0)
|
if (fd < 0)
|
||||||
@ -300,6 +309,16 @@ static int i8_blaster_daemon(int argc, FAR char *argv[])
|
|||||||
printf("blaster_daemon: starting\n");
|
printf("blaster_daemon: starting\n");
|
||||||
g_blaster_daemon_started = true;
|
g_blaster_daemon_started = true;
|
||||||
|
|
||||||
|
/* Start a thread to handle any events that occur */
|
||||||
|
|
||||||
|
g_eventlistener_run = true;
|
||||||
|
ret = pthread_create(&eventthread, NULL, i8_eventlistener, (void *)&fd);
|
||||||
|
if (ret != 0)
|
||||||
|
{
|
||||||
|
printf("blaster_daemon: Failed to create eventlistener thread: %d\n", ret);
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
while(1)
|
while(1)
|
||||||
{
|
{
|
||||||
ret = i8_tx(fd);
|
ret = i8_tx(fd);
|
||||||
@ -315,7 +334,11 @@ static int i8_blaster_daemon(int argc, FAR char *argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
done:
|
done:
|
||||||
|
/* Tell the eventthread to stop */
|
||||||
|
|
||||||
printf("blaster_daemon: closing\n");
|
printf("blaster_daemon: closing\n");
|
||||||
|
g_eventlistener_run = false;
|
||||||
|
pthread_join(eventthread, NULL);
|
||||||
close(fd);
|
close(fd);
|
||||||
g_blaster_daemon_started = false;
|
g_blaster_daemon_started = false;
|
||||||
return OK;
|
return OK;
|
||||||
@ -365,6 +388,41 @@ static void i8_tx_cmd(FAR const char *devname, FAR const char *str)
|
|||||||
close(fd);
|
close(fd);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Name : i8_eventlistener
|
||||||
|
*
|
||||||
|
* Description :
|
||||||
|
* Listen for events from the MAC layer
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
static pthread_addr_t i8_eventlistener(pthread_addr_t arg)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
struct ieee802154_notif_s notif;
|
||||||
|
int fd = *(int *)arg;
|
||||||
|
|
||||||
|
while (g_eventlistener_run)
|
||||||
|
{
|
||||||
|
ret = ioctl(fd, MAC802154IOC_GET_EVENT, (unsigned long)((uintptr_t)¬if));
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
fprintf(stderr, "MAC802154IOC_GET_EVENTS failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (notif.notiftype)
|
||||||
|
{
|
||||||
|
case IEEE802154_NOTIFY_CONF_DATA:
|
||||||
|
printf("Data Confirmation Status %d\n", notif.u.dataconf.status);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
printf("Unhandled notification: %d\n", notif.notiftype);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
/****************************************************************************
|
/****************************************************************************
|
||||||
* Name : i8_parse_payload
|
* Name : i8_parse_payload
|
||||||
*
|
*
|
||||||
|
@ -45,7 +45,7 @@ CSRCS = ieee802154_assocreq.c ieee802154_assocresp.c ieee802154_disassocreq.c
|
|||||||
CSRCS += ieee802154_getreq.c ieee802154_gtsreq.c ieee802154_orphanresp.c
|
CSRCS += ieee802154_getreq.c ieee802154_gtsreq.c ieee802154_orphanresp.c
|
||||||
CSRCS += ieee802154_resetreq.c ieee802154_rxenabreq.c ieee802154_scanreq.c
|
CSRCS += ieee802154_resetreq.c ieee802154_rxenabreq.c ieee802154_scanreq.c
|
||||||
CSRCS += ieee802154_setreq.c ieee802154_startreq.c ieee802154_syncreq.c
|
CSRCS += ieee802154_setreq.c ieee802154_startreq.c ieee802154_syncreq.c
|
||||||
CSRCS += ieee802154_pollreq.c
|
CSRCS += ieee802154_pollreq.c ieee802154_enableevents.c
|
||||||
# Add Get/Set Attribute helpers
|
# Add Get/Set Attribute helpers
|
||||||
CSRCS += ieee802154_setchan.c ieee802154_getchan.c
|
CSRCS += ieee802154_setchan.c ieee802154_getchan.c
|
||||||
CSRCS += ieee802154_setpanid.c ieee802154_getpanid.c
|
CSRCS += ieee802154_setpanid.c ieee802154_getpanid.c
|
||||||
|
69
wireless/ieee802154/libmac/ieee802154_enableevents.c
Normal file
69
wireless/ieee802154/libmac/ieee802154_enableevents.c
Normal file
@ -0,0 +1,69 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
* apps/wireless/ieee802154/libmac/ieee802154_enableevents.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 <sys/ioctl.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <errno.h>
|
||||||
|
|
||||||
|
#include <nuttx/fs/ioctl.h>
|
||||||
|
|
||||||
|
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
||||||
|
#include <nuttx/wireless/ieee802154/ieee802154_ioctl.h>
|
||||||
|
#include "wireless/ieee802154.h"
|
||||||
|
|
||||||
|
/****************************************************************************
|
||||||
|
* Public Functions
|
||||||
|
****************************************************************************/
|
||||||
|
|
||||||
|
int ieee802154_enableevents(int fd, bool enable)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = ioctl(fd, MAC802154IOC_ENABLE_EVENTS, (unsigned long)enable);
|
||||||
|
if (ret < 0)
|
||||||
|
{
|
||||||
|
ret = -errno;
|
||||||
|
fprintf(stderr, "MAC802154IOC_ENABLE_EVENTS failed: %d\n", ret);
|
||||||
|
}
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user