Skip to content
Merged
4 changes: 3 additions & 1 deletion wireless/ieee802154/i8sak/i8sak.h
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ struct i8sak_s

bool initialized : 1;
bool daemon_shutdown : 1;
bool daemon_failed : 1;
bool verbose : 1;
bool acceptall : 1;
bool assoc : 1;
Expand Down Expand Up @@ -188,8 +189,9 @@ struct i8sak_s
* Public Function Prototypes
****************************************************************************/

int i8sak_requestdaemon(FAR struct i8sak_s *i8sak);
void i8sak_requestdaemon(FAR struct i8sak_s *i8sak);
int i8sak_releasedaemon(FAR struct i8sak_s *i8sak);
void i8sak_cmd_abort(FAR struct i8sak_s *i8sak, i8sak_eventcallback_t cb);

uint8_t i8sak_char2nibble (char ch);
long i8sak_str2long (FAR const char *str);
Expand Down
12 changes: 10 additions & 2 deletions wireless/ieee802154/i8sak/i8sak_acceptassoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,11 @@ static void acceptassoc_eventcb(FAR struct ieee802154_primitive_s *primitive,
****************************************************************************/

/****************************************************************************
* Name : i8_acceptassoc
* Name: i8sak_acceptassoc_cmd
*
* Description :
* Description:
* Start accepting association requests.
*
****************************************************************************/

void i8sak_acceptassoc_cmd(FAR struct i8sak_s *i8sak, int argc,
Expand Down Expand Up @@ -146,6 +147,13 @@ void i8sak_acceptassoc_cmd(FAR struct i8sak_s *i8sak, int argc,

i8sak_requestdaemon(i8sak);

/* Replace the receiver of a previous acceptassoc */

if (i8sak_eventlistener_removereceiver(i8sak, acceptassoc_eventcb) == OK)
{
i8sak_releasedaemon(i8sak);
}

/* Register new callback for receiving the association notifications */

memset(&filter, 0, sizeof(struct i8sak_eventfilter_s));
Expand Down
17 changes: 12 additions & 5 deletions wireless/ieee802154/i8sak/i8sak_assoc.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ static void assoc_eventcb(FAR struct ieee802154_primitive_s *primitive,
****************************************************************************/

/****************************************************************************
* Name : i8sak_assoc
* Name: i8sak_assoc_cmd
*
* Description :
* Description:
* Request association with the Coordinator
*
****************************************************************************/

void i8sak_assoc_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
Expand Down Expand Up @@ -209,7 +210,14 @@ void i8sak_assoc_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
memset(&filter, 0, sizeof(struct i8sak_eventfilter_s));
filter.confevents.assoc = true;

i8sak_eventlistener_addreceiver(i8sak, assoc_eventcb, &filter, false);
ret = i8sak_eventlistener_addreceiver(i8sak, assoc_eventcb, &filter,
false);
if (ret < 0)
{
i8sak_releasedaemon(i8sak);
close(fd);
return;
}

/* Loop for the specified retry count if the association fails.
*/
Expand Down Expand Up @@ -253,8 +261,7 @@ void i8sak_assoc_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
if (ret != OK)
{
i8sak->assoc = false;
i8sak_cmd_error(i8sak);
break;
i8sak_cmd_abort(i8sak, assoc_eventcb);
}

/* Check if the association was successful */
Expand Down
45 changes: 30 additions & 15 deletions wireless/ieee802154/i8sak/i8sak_blaster.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,23 +70,19 @@ static inline void i8sak_blaster_start(FAR struct i8sak_s *i8sak)
****************************************************************************/

/****************************************************************************
* Name : i8sak_blaster
* Name: i8sak_blaster_cmd
*
* Description :
* Description:
* Continuously transmit a packet
*
****************************************************************************/

void i8sak_blaster_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
{
bool start = argc < 2;
bool quit = false;
int option;

i8sak_requestdaemon(i8sak);

if (argc < 2)
{
i8sak_blaster_start(i8sak);
}

while ((option = getopt(argc, argv, "hqp:f:")) != ERROR)
{
switch (option)
Expand All @@ -106,18 +102,18 @@ void i8sak_blaster_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
optind = -1;
return;
case 'q': /* Quit blaster */
i8sak->blasterenabled = false;
quit = true;
break;

case 'p': /* Inline change blaster period */
i8sak->blasterperiod = atoi(optarg);
i8sak_blaster_start(i8sak);
start = true;
break;

case 'f': /* Inline change blaster frame */
i8sak->payload_len = i8sak_str2payload(optarg,
&i8sak->payload[0]);
i8sak_blaster_start(i8sak);
start = true;
break;

case ':':
Expand All @@ -138,13 +134,30 @@ void i8sak_blaster_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
i8sak_cmd_error(i8sak); /* This exits for us */
}
}

/* The blaster holds the daemon while it runs */

if (quit)
{
if (i8sak->blasterenabled)
{
i8sak->blasterenabled = false;
i8sak_releasedaemon(i8sak);
}
}
else if (start && !i8sak->blasterenabled)
{
i8sak_requestdaemon(i8sak);
i8sak_blaster_start(i8sak);
}
}

/****************************************************************************
* Name : i8sak_blaster_thread
* Name: i8sak_blaster_thread
*
* Description :
* Description:
* Send frames periodically
*
****************************************************************************/

pthread_addr_t i8sak_blaster_thread(pthread_addr_t arg)
Expand All @@ -159,7 +172,9 @@ pthread_addr_t i8sak_blaster_thread(pthread_addr_t arg)
sizeof(struct sockaddr_in6)) < 0)
{
fprintf(stderr, "ERROR: failure to bind sock: %d\n", errno);
exit(1);
i8sak->blasterenabled = false;
i8sak_releasedaemon(i8sak);
return NULL;
}
}
#endif
Expand Down
29 changes: 24 additions & 5 deletions wireless/ieee802154/i8sak/i8sak_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <signal.h>
#include <fcntl.h>
#include <net/if.h>
#include <nuttx/fs/ioctl.h>
Expand All @@ -50,11 +51,28 @@
* Private Functions
****************************************************************************/

#ifdef CONFIG_ENABLE_ALL_SIGNALS
/****************************************************************************
* Name : i8sak_eventthread
* Name: i8sak_eventthread_wakeup
*
* Description :
* Description:
* An empty handler for SIGINT. i8sak_eventlistener_stop() sends SIGINT
* to break the event thread out of MAC802154IOC_GET_EVENT; an ignored
* signal does not interrupt it.
*
****************************************************************************/

static void i8sak_eventthread_wakeup(int signo)
{
}
#endif

/****************************************************************************
* Name: i8sak_eventthread
*
* Description:
* Listen for events from the MAC layer
*
****************************************************************************/

static pthread_addr_t i8sak_eventthread(pthread_addr_t arg)
Expand All @@ -71,6 +89,8 @@ static pthread_addr_t i8sak_eventthread(pthread_addr_t arg)
#ifdef CONFIG_DISABLE_ALL_SIGNALS
pthread_setcancelstate(PTHREAD_CANCEL_ENABLE, NULL);
pthread_setcanceltype(PTHREAD_CANCEL_DEFERRED, NULL);
#elif defined(CONFIG_ENABLE_ALL_SIGNALS)
signal(SIGINT, i8sak_eventthread_wakeup);
#endif

if (i8sak->mode == I8SAK_MODE_CHAR)
Expand Down Expand Up @@ -268,7 +288,7 @@ int i8sak_eventlistener_stop(FAR struct i8sak_s *i8sak)
#ifdef CONFIG_DISABLE_ALL_SIGNALS
pthread_cancel(i8sak->eventlistener_threadid);
#else
pthread_kill(i8sak->eventlistener_threadid, 2);
pthread_kill(i8sak->eventlistener_threadid, SIGINT);
#endif

ret = pthread_join(i8sak->eventlistener_threadid, &value);
Expand Down Expand Up @@ -408,6 +428,5 @@ int i8sak_eventlistener_removereceiver(FAR struct i8sak_s *i8sak,
}

sem_post(&i8sak->eventsem);
fprintf(stderr, "failed to remove receiver");
return ERROR;
return -ENOENT;
}
5 changes: 3 additions & 2 deletions wireless/ieee802154/i8sak/i8sak_get.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,12 @@ union i8sak_get_u
****************************************************************************/

/****************************************************************************
* Name : i8sak_get_cmd
* Name: i8sak_get_cmd
*
* Description :
* Description:
* Get various parameters. These can be either i8sak app level options
* or attributes fetched via IOCTL to the network/MAC/or radio level.
*
****************************************************************************/

void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
Expand Down
Loading
Loading