2015-08-04 01:31:07 +02:00
|
|
|
/****************************************************************************
|
2017-04-11 21:39:07 +02:00
|
|
|
* apps/wireless/ieee802154/i8sak/i8sak_main.c
|
2015-08-04 01:31:07 +02:00
|
|
|
* IEEE 802.15.4 Swiss Army Knife
|
|
|
|
*
|
2017-04-13 16:57:26 +02:00
|
|
|
* Copyright (C) 2014-2015, 2017 Gregory Nutt. All rights reserved.
|
2015-08-04 01:31:07 +02:00
|
|
|
* Copyright (C) 2014-2015 Sebastien Lorquet. All rights reserved.
|
2017-06-11 20:17:09 +02:00
|
|
|
* Copyright (C) 2017 Verge Inc. All rights reserved.
|
|
|
|
*
|
2015-08-04 01:31:07 +02:00
|
|
|
* Author: Sebastien Lorquet <sebastien@lorquet.fr>
|
2017-06-11 20:17:09 +02:00
|
|
|
* Author: Anthony Merlino <anthony@vergeaero.com>
|
|
|
|
* Author: Gregory Nuttx <gnutt@nuttx.org>
|
2015-08-04 01:31:07 +02:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* This app can be used to control an IEEE 802.15.4 device from command line.
|
|
|
|
* Example valid ieee802154 packets:
|
|
|
|
*
|
|
|
|
* Beacon request, seq number 01:
|
|
|
|
* xx xx 01
|
|
|
|
*
|
2017-03-24 21:51:12 +01:00
|
|
|
* Simple data packet
|
2015-08-04 01:31:07 +02:00
|
|
|
* from long address xx to long address yy, pan id pp for src and dest
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
2017-06-14 08:34:36 +02:00
|
|
|
#include <strings.h>
|
2015-08-04 01:31:07 +02:00
|
|
|
#include <errno.h>
|
|
|
|
#include <fcntl.h>
|
2017-06-14 08:34:36 +02:00
|
|
|
#include <queue.h>
|
2015-08-04 01:31:07 +02:00
|
|
|
#include <sys/ioctl.h>
|
2017-09-15 16:16:47 +02:00
|
|
|
#include <arpa/inet.h>
|
2015-08-04 01:31:07 +02:00
|
|
|
#include <nuttx/fs/ioctl.h>
|
2017-03-29 18:45:49 +02:00
|
|
|
|
2017-03-24 16:59:30 +01:00
|
|
|
#include <nuttx/wireless/ieee802154/ieee802154_mac.h>
|
2017-09-15 16:16:47 +02:00
|
|
|
#include <nuttx/wireless/ieee802154/ieee802154_device.h>
|
2017-04-21 15:49:55 +02:00
|
|
|
#include "wireless/ieee802154.h"
|
2015-08-04 01:31:07 +02:00
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
#include "i8sak.h"
|
|
|
|
|
2015-08-04 01:31:07 +02:00
|
|
|
/****************************************************************************
|
2017-06-14 08:34:36 +02:00
|
|
|
* Pre-processor Definitions
|
2015-08-04 01:31:07 +02:00
|
|
|
****************************************************************************/
|
2017-06-14 08:34:36 +02:00
|
|
|
/* Configuration ************************************************************/
|
2015-08-04 01:31:07 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
#if !defined(CONFIG_IEEE802154_I8SAK_NINSTANCES) || CONFIG_IEEE802154_I8SAK_NINSTANCES <= 0
|
|
|
|
# undef CONFIG_IEEE802154_I8SAK_NINSTANCES
|
|
|
|
# define CONFIG_IEEE802154_I8SAK_NINSTANCES 3
|
|
|
|
#endif
|
2015-08-04 01:31:07 +02:00
|
|
|
|
2017-03-24 21:51:12 +01:00
|
|
|
/****************************************************************************
|
2017-06-11 20:17:09 +02:00
|
|
|
* Private Types
|
2017-03-24 21:51:12 +01:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
/* Describes one command */
|
|
|
|
|
|
|
|
struct i8sak_command_s
|
2017-05-09 22:58:19 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
FAR const char *name;
|
|
|
|
CODE void (*handler)(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[]);
|
2017-05-09 22:58:19 +02:00
|
|
|
};
|
|
|
|
|
2017-06-11 20:17:09 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
/* Alphabetical, except for help */
|
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
static const struct i8sak_command_s g_i8sak_commands[] =
|
|
|
|
{
|
|
|
|
{"help", (CODE void *)NULL},
|
|
|
|
{"acceptassoc", (CODE void *)i8sak_acceptassoc_cmd},
|
|
|
|
{"assoc", (CODE void *)i8sak_assoc_cmd},
|
|
|
|
{"blaster", (CODE void *)i8sak_blaster_cmd},
|
2017-09-15 16:16:47 +02:00
|
|
|
{"get", (CODE void *)i8sak_get_cmd},
|
|
|
|
{"poll", (CODE void *)i8sak_poll_cmd},
|
2017-07-18 20:05:42 +02:00
|
|
|
{"regdump", (CODE void *)i8sak_regdump_cmd},
|
2017-09-15 16:16:47 +02:00
|
|
|
{"reset", (CODE void *)i8sak_reset_cmd},
|
|
|
|
{"scan", (CODE void *)i8sak_scan_cmd},
|
|
|
|
{"set", (CODE void *)i8sak_set_cmd},
|
|
|
|
{"sniffer", (CODE void *)i8sak_sniffer_cmd},
|
|
|
|
{"startpan", (CODE void *)i8sak_startpan_cmd},
|
|
|
|
{"tx", (CODE void *)i8sak_tx_cmd},
|
2017-06-14 08:34:36 +02:00
|
|
|
};
|
2017-06-11 20:17:09 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
#define NCOMMANDS (sizeof(g_i8sak_commands) / sizeof(struct i8sak_command_s))
|
2017-03-24 21:51:12 +01:00
|
|
|
|
2017-06-15 19:10:25 +02:00
|
|
|
static sq_queue_t g_i8sak_free;
|
|
|
|
static sq_queue_t g_i8sak_instances;
|
|
|
|
static struct i8sak_s g_i8sak_pool[CONFIG_IEEE802154_I8SAK_NINSTANCES];
|
|
|
|
static bool g_i8sak_initialized = false;
|
|
|
|
static bool g_activei8sak_set = false;
|
|
|
|
static FAR struct i8sak_s *g_activei8sak;
|
2015-08-04 01:31:07 +02:00
|
|
|
|
2017-05-08 22:25:09 +02:00
|
|
|
/****************************************************************************
|
2017-06-14 08:34:36 +02:00
|
|
|
* Private Function Prototypes
|
2017-05-08 22:25:09 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
static int i8sak_setup(FAR struct i8sak_s *i8sak, FAR const char *ifname);
|
2017-06-14 08:34:36 +02:00
|
|
|
static int i8sak_daemon(int argc, FAR char *argv[]);
|
|
|
|
static int i8sak_showusage(FAR const char *progname, int exitcode);
|
2017-09-15 16:16:47 +02:00
|
|
|
static void i8sak_switch_instance(FAR char *ifname);
|
2017-06-11 20:17:09 +02:00
|
|
|
|
2017-05-08 22:25:09 +02:00
|
|
|
/****************************************************************************
|
2017-06-14 08:34:36 +02:00
|
|
|
* Public Functions
|
2017-05-08 22:25:09 +02:00
|
|
|
****************************************************************************/
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2015-08-04 01:31:07 +02:00
|
|
|
/****************************************************************************
|
2017-06-14 08:34:36 +02:00
|
|
|
* Name : i8sak_str2payload
|
2015-08-04 01:31:07 +02:00
|
|
|
*
|
|
|
|
* Description :
|
2017-06-14 08:34:36 +02:00
|
|
|
* Parse string to get buffer of data. Buf is expected to be of size
|
|
|
|
* IEEE802154_MAX_MAC_PAYLOAD_SIZE or larger.
|
|
|
|
*
|
|
|
|
* Returns:
|
|
|
|
* Positive length value of frame payload
|
2015-08-04 01:31:07 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
int i8sak_str2payload(FAR const char *str, FAR uint8_t *buf)
|
2015-08-04 01:31:07 +02:00
|
|
|
{
|
2017-06-15 19:10:25 +02:00
|
|
|
int str_len;
|
|
|
|
int ret;
|
|
|
|
int i = 0;
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
str_len = strlen(str);
|
|
|
|
|
|
|
|
/* Each byte is represented by 2 chars */
|
2015-09-01 18:21:48 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
ret = str_len >> 1;
|
2017-05-08 22:25:09 +02:00
|
|
|
|
2017-06-15 18:51:25 +02:00
|
|
|
/* Check if the number of chars is a multiple of 2 and that the number of
|
2017-06-15 19:10:25 +02:00
|
|
|
* bytes does not exceed the max MAC frame payload supported.
|
|
|
|
*/
|
2017-06-14 08:34:36 +02:00
|
|
|
|
|
|
|
if ((str_len & 1) || (ret > IEEE802154_MAX_MAC_PAYLOAD_SIZE))
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Invalid payload\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Decode hex packet */
|
|
|
|
|
|
|
|
while (str_len > 0)
|
2017-05-09 22:58:19 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
int dat;
|
|
|
|
if (sscanf(str, "%2x", &dat) == 1)
|
2017-06-11 20:17:09 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
buf[i++] = dat;
|
|
|
|
str += 2;
|
|
|
|
str_len -= 2;
|
2017-06-11 20:17:09 +02:00
|
|
|
}
|
2017-06-14 08:34:36 +02:00
|
|
|
else
|
2017-06-11 20:17:09 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
fprintf(stderr, "ERROR: Invalid payload\n");
|
|
|
|
exit(EXIT_FAILURE);
|
2017-06-11 20:17:09 +02:00
|
|
|
}
|
2017-05-09 22:58:19 +02:00
|
|
|
}
|
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
return ret;
|
2017-06-11 20:17:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-06-14 08:34:36 +02:00
|
|
|
* Name: i8sak_str2long
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Convert a hex string to an integer value
|
2017-06-11 20:17:09 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
long i8sak_str2long(FAR const char *str)
|
2017-06-11 20:17:09 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
FAR char *endptr;
|
|
|
|
long value;
|
2017-06-11 20:17:09 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
value = strtol(str, &endptr, 0);
|
|
|
|
if (*endptr != '\0')
|
2017-05-09 22:58:19 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
fprintf(stderr, "ERROR: Garbage after numeric argument\n");
|
|
|
|
exit(EXIT_FAILURE);
|
2017-05-09 22:58:19 +02:00
|
|
|
}
|
2017-06-14 08:34:36 +02:00
|
|
|
|
|
|
|
if (value > INT_MAX || value < INT_MIN)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Integer value out of range\n");
|
|
|
|
return LONG_MAX;
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
|
|
|
|
return value;
|
2017-06-11 20:17:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-06-14 08:34:36 +02:00
|
|
|
* Name: i8sak_str2luint8
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Convert a string to an integer value
|
2017-06-11 20:17:09 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
uint8_t i8sak_str2luint8(FAR const char *str)
|
2017-06-11 20:17:09 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
long value = i8sak_str2long(str);
|
|
|
|
if (value < 0 || value > UINT8_MAX)
|
2017-06-11 20:17:09 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
fprintf(stderr, "ERROR: 8-bit value out of range\n");
|
|
|
|
exit(EXIT_FAILURE);
|
2017-05-09 22:58:19 +02:00
|
|
|
}
|
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
return (uint8_t)value;
|
2017-05-09 22:58:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-06-14 08:34:36 +02:00
|
|
|
* Name: i8sak_str2luint16
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Convert a string to an integer value
|
2017-05-09 22:58:19 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
uint16_t i8sak_str2luint16(FAR const char *str)
|
2017-05-09 22:58:19 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
long value = i8sak_str2long(str);
|
|
|
|
if (value < 0 || value > UINT16_MAX)
|
2017-05-15 21:14:18 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
fprintf(stderr, "ERROR: 16-bit value out of range\n");
|
|
|
|
exit(EXIT_FAILURE);
|
2017-05-15 21:14:18 +02:00
|
|
|
}
|
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
return (uint16_t)value;
|
2017-06-11 20:17:09 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
2017-06-14 08:34:36 +02:00
|
|
|
* Name: i8sak_char2nibble
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Convert an hexadecimal character to a 4-bit nibble.
|
2017-06-11 20:17:09 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
uint8_t i8sak_char2nibble(char ch)
|
2017-06-11 20:17:09 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
if (ch >= '0' && ch <= '9')
|
2017-05-09 22:58:19 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
return ch - '0';
|
|
|
|
}
|
|
|
|
else if (ch >= 'a' && ch <= 'f')
|
|
|
|
{
|
|
|
|
return ch - 'a' + 10;
|
|
|
|
}
|
|
|
|
else if (ch >= 'A' && ch <= 'F')
|
|
|
|
{
|
|
|
|
return ch - 'A' + 10;
|
|
|
|
}
|
|
|
|
else if (ch == '\0')
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Unexpected end hex\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Unexpected character in hex value: %02x\n", ch);
|
|
|
|
exit(EXIT_FAILURE);
|
2017-05-09 22:58:19 +02:00
|
|
|
}
|
|
|
|
}
|
2017-03-24 21:51:12 +01:00
|
|
|
|
2017-05-09 22:58:19 +02:00
|
|
|
/****************************************************************************
|
2017-06-14 08:34:36 +02:00
|
|
|
* Name: i8sak_str2eaddr
|
|
|
|
*
|
|
|
|
* Description:
|
2017-06-19 11:56:52 +02:00
|
|
|
* Convert a string 8-byte EADDR array.
|
2017-05-09 22:58:19 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-04-13 16:57:26 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
void i8sak_str2eaddr(FAR const char *str, FAR uint8_t *eaddr)
|
2017-05-09 22:58:19 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
FAR const char *src = str;
|
|
|
|
uint8_t bvalue;
|
|
|
|
char ch;
|
|
|
|
int i;
|
2017-06-11 20:17:09 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
for (i = 0; i < 8; i++)
|
|
|
|
{
|
|
|
|
ch = (char)*src++;
|
|
|
|
bvalue = i8sak_char2nibble(ch) << 4;
|
2017-06-11 20:17:09 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
ch = (char)*src++;
|
|
|
|
bvalue |= i8sak_char2nibble(ch);
|
2017-06-11 20:17:09 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
*eaddr++ = bvalue;
|
2017-06-11 20:17:09 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
if (i < 7)
|
|
|
|
{
|
|
|
|
ch = (char)*src++;
|
|
|
|
if (ch != ':')
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Missing colon separator: %s\n", str);
|
|
|
|
fprintf(stderr, " Expected xx:xx:xx:xx:xx:xx:xx:xx\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
2017-05-09 22:58:19 +02:00
|
|
|
}
|
2017-06-11 20:17:09 +02:00
|
|
|
}
|
2017-05-09 22:58:19 +02:00
|
|
|
|
2017-06-19 11:56:52 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* Name: i8sak_str2saddr
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Convert a string 2-byte SADDR array.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void i8sak_str2saddr(FAR const char *str, FAR uint8_t *saddr)
|
|
|
|
{
|
|
|
|
FAR const char *src = str;
|
|
|
|
uint8_t bvalue;
|
|
|
|
char ch;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
ch = (char)*src++;
|
|
|
|
bvalue = i8sak_char2nibble(ch) << 4;
|
|
|
|
|
|
|
|
ch = (char)*src++;
|
|
|
|
bvalue |= i8sak_char2nibble(ch);
|
|
|
|
|
|
|
|
*saddr++ = bvalue;
|
|
|
|
|
|
|
|
if (i < 1)
|
|
|
|
{
|
|
|
|
ch = (char)*src++;
|
|
|
|
if (ch != ':')
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Missing colon separator: %s\n", str);
|
|
|
|
fprintf(stderr, " Expected xx:xx\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: i8sak_str2panid
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Convert a string 2-byte PAN ID array.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
void i8sak_str2panid(FAR const char *str, FAR uint8_t *panid)
|
|
|
|
{
|
|
|
|
FAR const char *src = str;
|
|
|
|
uint8_t bvalue;
|
|
|
|
char ch;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < 2; i++)
|
|
|
|
{
|
|
|
|
ch = (char)*src++;
|
|
|
|
bvalue = i8sak_char2nibble(ch) << 4;
|
|
|
|
|
|
|
|
ch = (char)*src++;
|
|
|
|
bvalue |= i8sak_char2nibble(ch);
|
|
|
|
|
|
|
|
*panid++ = bvalue;
|
|
|
|
|
|
|
|
if (i < 1)
|
|
|
|
{
|
|
|
|
ch = (char)*src++;
|
|
|
|
if (ch != ':')
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: Missing colon separator: %s\n", str);
|
|
|
|
fprintf(stderr, " Expected xx:xx\n");
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-06-11 20:17:09 +02:00
|
|
|
/****************************************************************************
|
2017-06-14 08:34:36 +02:00
|
|
|
* Name: i8sak_str2bool
|
2017-06-11 20:17:09 +02:00
|
|
|
*
|
2017-06-14 08:34:36 +02:00
|
|
|
* Description:
|
|
|
|
* Convert a boolean name to a boolean value.
|
2017-06-11 20:17:09 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
2017-05-09 22:58:19 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
bool i8sak_str2bool(FAR const char *str)
|
2017-06-11 20:17:09 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
if (strcasecmp(str, "true") == 0)
|
2017-05-09 22:58:19 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else if (strcasecmp(str, "false") == 0)
|
|
|
|
{
|
|
|
|
return false;
|
2017-05-09 22:58:19 +02:00
|
|
|
}
|
2017-06-11 20:17:09 +02:00
|
|
|
else
|
2017-05-09 22:58:19 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
fprintf(stderr, "ERROR: Invalid boolean name: %s\n", str);
|
|
|
|
fprintf(stderr, " Expected true or false\n");
|
|
|
|
exit(EXIT_FAILURE);
|
2017-05-09 22:58:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-15 21:14:18 +02:00
|
|
|
/****************************************************************************
|
2017-06-14 08:34:36 +02:00
|
|
|
* Private Functions
|
2017-05-15 21:14:18 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
static void i8sak_switch_instance(FAR char *ifname)
|
2017-05-15 21:14:18 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
FAR struct i8sak_s *i8sak;
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-06-15 19:10:25 +02:00
|
|
|
/* Search list of i8sak instances for one associated with the provided
|
|
|
|
* device.
|
|
|
|
*/
|
2017-05-15 21:14:18 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
i8sak = (FAR struct i8sak_s *)sq_peek(&g_i8sak_instances);
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
while (i8sak != NULL)
|
2017-05-15 21:14:18 +02:00
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
if (strcmp(ifname, i8sak->ifname) == 0)
|
2017-05-15 21:14:18 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
break;
|
2017-05-15 21:14:18 +02:00
|
|
|
}
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
i8sak = (FAR struct i8sak_s *)sq_next((FAR sq_entry_t *)i8sak);
|
|
|
|
}
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
/* If there isn't a i8sak instance started for this device, allocate one */
|
|
|
|
|
|
|
|
if (i8sak == NULL)
|
|
|
|
{
|
|
|
|
i8sak = (FAR struct i8sak_s *)sq_remfirst(&g_i8sak_free);
|
|
|
|
if (i8sak == NULL)
|
2017-05-15 21:14:18 +02:00
|
|
|
{
|
2017-06-18 19:28:36 +02:00
|
|
|
fprintf(stderr, "ERROR: Failed to allocate i8sak instance\n");
|
2017-06-14 08:34:36 +02:00
|
|
|
exit(EXIT_FAILURE);
|
2017-05-15 21:14:18 +02:00
|
|
|
}
|
2017-06-14 08:34:36 +02:00
|
|
|
|
|
|
|
sq_addlast((FAR sq_entry_t *)i8sak, &g_i8sak_instances);
|
2017-05-15 21:14:18 +02:00
|
|
|
|
2017-06-26 02:01:16 +02:00
|
|
|
/* Update our "sticky" i8sak instance. Must come before call to setup so that
|
|
|
|
* the shared active global i8sak is correct.
|
|
|
|
*/
|
2017-05-09 22:58:19 +02:00
|
|
|
|
2017-06-26 02:01:16 +02:00
|
|
|
g_activei8sak = i8sak;
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
if (i8sak_setup(i8sak, ifname) < 0)
|
2017-06-26 02:01:16 +02:00
|
|
|
{
|
|
|
|
exit(EXIT_FAILURE);
|
|
|
|
}
|
2017-06-14 08:34:36 +02:00
|
|
|
}
|
2017-06-26 02:01:16 +02:00
|
|
|
else
|
2017-06-14 08:34:36 +02:00
|
|
|
{
|
2017-06-26 02:01:16 +02:00
|
|
|
g_activei8sak = i8sak;
|
2017-06-14 08:34:36 +02:00
|
|
|
}
|
2017-06-26 02:01:16 +02:00
|
|
|
|
|
|
|
g_activei8sak_set = true;
|
2017-06-14 08:34:36 +02:00
|
|
|
}
|
2017-03-24 21:51:12 +01:00
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
static int i8sak_setup(FAR struct i8sak_s *i8sak, FAR const char *ifname)
|
2017-06-14 08:34:36 +02:00
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
char daemonname[I8SAK_MAX_DAEMONNAME];
|
2017-06-15 19:10:25 +02:00
|
|
|
int i;
|
|
|
|
int ret;
|
2017-09-15 16:16:47 +02:00
|
|
|
int len;
|
|
|
|
int fd = 0;
|
2015-08-04 01:31:07 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
if (i8sak->initialized)
|
|
|
|
{
|
|
|
|
return OK;
|
|
|
|
}
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
i8sak->chan = 11;
|
|
|
|
i8sak->chpage = 0;
|
2017-03-24 21:51:12 +01:00
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
if (strlen(ifname) > I8SAK_MAX_IFNAME)
|
2015-08-04 01:31:07 +02:00
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
fprintf(stderr, "ERROR: ifname too long\n");
|
2017-06-14 08:34:36 +02:00
|
|
|
return ERROR;
|
2015-08-04 01:31:07 +02:00
|
|
|
}
|
2017-03-24 21:51:12 +01:00
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
strcpy(&i8sak->ifname[0], ifname);
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
i8sak->addrmode = IEEE802154_ADDRMODE_SHORT;
|
2017-03-24 21:51:12 +01:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
/* Initialize the default remote endpoint address */
|
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
i8sak->ep_addr.mode = IEEE802154_ADDRMODE_SHORT;
|
2017-06-19 11:56:52 +02:00
|
|
|
|
|
|
|
for (i = 0; i < IEEE802154_EADDRSIZE; i++)
|
2017-06-14 08:34:36 +02:00
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
i8sak->ep_addr.eaddr[i] =
|
|
|
|
(uint8_t)((CONFIG_IEEE802154_I8SAK_DEFAULT_EP_EADDR >> (i*8)) & 0xFF);
|
2017-06-14 08:34:36 +02:00
|
|
|
}
|
|
|
|
|
2017-06-19 11:56:52 +02:00
|
|
|
for (i = 0; i < IEEE802154_SADDRSIZE; i++)
|
2017-09-15 16:16:47 +02:00
|
|
|
{
|
|
|
|
i8sak->ep_addr.saddr[i] =
|
|
|
|
(uint8_t)((CONFIG_IEEE802154_I8SAK_DEFAULT_EP_SADDR >> (i*8)) & 0xFF);
|
|
|
|
}
|
2017-06-19 11:56:52 +02:00
|
|
|
|
|
|
|
for (i = 0; i < IEEE802154_PANIDSIZE; i++)
|
2017-09-15 16:16:47 +02:00
|
|
|
{
|
|
|
|
i8sak->ep_addr.panid[i] =
|
|
|
|
(uint8_t)((CONFIG_IEEE802154_I8SAK_DEFAULT_EP_PANID >> (i*8)) & 0xFF);
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
i8sak->ep_in6addr.sin6_family = AF_INET6;
|
|
|
|
i8sak->ep_in6addr.sin6_port = HTONS(CONFIG_IEEE802154_I8SAK_DEFAULT_PORT);
|
|
|
|
|
|
|
|
i8sak_update_ep_ip(i8sak);
|
|
|
|
|
|
|
|
i8sak->snifferport = HTONS(CONFIG_IEEE802154_I8SAK_DEFAULT_PORT);
|
|
|
|
#endif
|
2017-06-14 08:34:36 +02:00
|
|
|
|
2017-06-19 11:56:52 +02:00
|
|
|
/* Set the next association device to the default device address, so that
|
|
|
|
* the first device to request association gets that address.
|
|
|
|
*/
|
|
|
|
|
|
|
|
for (i = 0; i < IEEE802154_SADDRSIZE; i++)
|
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
i8sak->next_saddr[i] =
|
|
|
|
(uint8_t)(((CONFIG_IEEE802154_I8SAK_DEFAULT_EP_SADDR + 1) >> (i*8)) & 0xFF);
|
2017-06-19 11:56:52 +02:00
|
|
|
}
|
2017-06-14 08:34:36 +02:00
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
/* Check if argument starts with /dev/ */
|
|
|
|
|
|
|
|
if (strncmp(ifname, "/dev/", 5) == 0)
|
2015-08-04 01:31:07 +02:00
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
i8sak->mode = I8SAK_MODE_CHAR;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
i8sak->mode = I8SAK_MODE_NETIF;
|
2015-08-04 01:31:07 +02:00
|
|
|
}
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
if (i8sak->mode == I8SAK_MODE_CHAR)
|
|
|
|
{
|
|
|
|
fd = open(i8sak->ifname, O_RDWR);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot open %s, errno=%d\n", i8sak->ifname, errno);
|
|
|
|
i8sak_cmd_error(i8sak);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
else if (i8sak->mode == I8SAK_MODE_NETIF)
|
|
|
|
{
|
|
|
|
fd = socket(PF_INET6, SOCK_DGRAM, 0);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: failed to open socket, errno=%d\n", errno);
|
|
|
|
i8sak_cmd_error(i8sak);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
else
|
|
|
|
{
|
|
|
|
close(fd);
|
|
|
|
return ERROR;
|
|
|
|
}
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
close(fd);
|
|
|
|
|
|
|
|
sem_init(&i8sak->exclsem, 0, 1);
|
|
|
|
|
|
|
|
sem_init(&i8sak->updatesem, 0, 0);
|
|
|
|
sem_setprotocol(&i8sak->updatesem, SEM_PRIO_NONE);
|
|
|
|
|
|
|
|
sem_init(&i8sak->sigsem, 0, 0);
|
|
|
|
sem_setprotocol(&i8sak->sigsem, SEM_PRIO_NONE);
|
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
sem_init(&i8sak->eventsem, 0, 1);
|
|
|
|
|
|
|
|
i8sak->daemon_started = false;
|
|
|
|
i8sak->daemon_shutdown = false;
|
|
|
|
|
|
|
|
i8sak->eventlistener_run = false;
|
|
|
|
sq_init(&i8sak->eventreceivers);
|
|
|
|
sq_init(&i8sak->eventreceivers_free);
|
|
|
|
for (i = 0; i < CONFIG_I8SAK_NEVENTRECEIVERS; i++)
|
|
|
|
{
|
|
|
|
sq_addlast((FAR sq_entry_t *)&i8sak->eventreceiver_pool[i], &i8sak->eventreceivers_free);
|
|
|
|
}
|
|
|
|
|
|
|
|
i8sak->blasterperiod = 1000;
|
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
/* Create strings for task based on device. i.e. i8_ieee0 */
|
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
if (i8sak->mode == I8SAK_MODE_CHAR)
|
|
|
|
{
|
|
|
|
len = strlen(ifname);
|
|
|
|
snprintf(daemonname, I8SAK_DAEMONNAME_PREFIX_LEN + (len - 5),
|
|
|
|
I8SAK_DAEMONNAME_FMT, &ifname[5]);
|
|
|
|
}
|
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
else if (i8sak->mode == I8SAK_MODE_NETIF)
|
|
|
|
{
|
|
|
|
len = strlen(ifname);
|
|
|
|
snprintf(daemonname, I8SAK_DAEMONNAME_PREFIX_LEN + len,
|
|
|
|
I8SAK_DAEMONNAME_FMT, ifname);
|
|
|
|
}
|
|
|
|
#endif
|
2017-06-14 08:34:36 +02:00
|
|
|
|
|
|
|
i8sak->daemon_pid = task_create(daemonname, CONFIG_IEEE802154_I8SAK_PRIORITY,
|
|
|
|
CONFIG_IEEE802154_I8SAK_STACKSIZE, i8sak_daemon,
|
|
|
|
NULL);
|
|
|
|
if (i8sak->daemon_pid < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "failed to start daemon\n");
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Use the signal semaphore to wait for daemon to start before returning */
|
|
|
|
|
|
|
|
ret = sem_wait(&i8sak->sigsem);
|
|
|
|
if (ret < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "i8sak:interrupted while daemon starting\n");
|
|
|
|
return ERROR;
|
|
|
|
}
|
|
|
|
|
|
|
|
i8sak->initialized = true;
|
2017-05-09 22:58:19 +02:00
|
|
|
return OK;
|
|
|
|
}
|
2015-08-10 11:05:23 +02:00
|
|
|
|
2017-05-09 22:58:19 +02:00
|
|
|
/****************************************************************************
|
2017-06-14 08:34:36 +02:00
|
|
|
* Name : i8sak_daemon
|
2017-05-09 22:58:19 +02:00
|
|
|
*
|
|
|
|
* Description :
|
2017-06-14 08:34:36 +02:00
|
|
|
* Runs command in seperate task
|
2017-05-09 22:58:19 +02:00
|
|
|
****************************************************************************/
|
2017-03-24 21:51:12 +01:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
static int i8sak_daemon(int argc, FAR char *argv[])
|
2017-05-09 22:58:19 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
FAR struct i8sak_s *i8sak = g_activei8sak;
|
2017-05-09 22:58:19 +02:00
|
|
|
int ret;
|
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
fprintf(stderr, "i8sak: daemon started\n");
|
|
|
|
i8sak->daemon_started = true;
|
2017-05-09 22:58:19 +02:00
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
if (i8sak->mode == I8SAK_MODE_CHAR)
|
2017-06-14 08:34:36 +02:00
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
i8sak->fd = open(i8sak->ifname, O_RDWR);
|
|
|
|
if (i8sak->fd < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: cannot open %s, errno=%d\n", i8sak->ifname, errno);
|
|
|
|
i8sak->daemon_started = false;
|
|
|
|
ret = errno;
|
|
|
|
return ret;
|
|
|
|
}
|
2017-06-14 08:34:36 +02:00
|
|
|
}
|
2017-09-15 16:16:47 +02:00
|
|
|
#ifdef CONFIG_NET_6LOWPAN
|
|
|
|
else if (i8sak->mode == I8SAK_MODE_NETIF)
|
2017-06-14 08:34:36 +02:00
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
i8sak->fd = socket(PF_INET6, SOCK_DGRAM, 0);
|
|
|
|
if (i8sak->fd < 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "ERROR: failed to open socket, errno=%d\n", errno);
|
|
|
|
i8sak->daemon_started = false;
|
|
|
|
ret = errno;
|
|
|
|
return ret;
|
|
|
|
}
|
2017-06-14 08:34:36 +02:00
|
|
|
}
|
2017-09-15 16:16:47 +02:00
|
|
|
#endif
|
2017-05-09 22:58:19 +02:00
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
i8sak_eventlistener_start(i8sak);
|
2017-05-09 22:58:19 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
/* Signal the calling thread that the daemon is up and running */
|
2017-05-05 17:13:30 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
sem_post(&i8sak->sigsem);
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
while (!i8sak->daemon_shutdown)
|
2015-08-07 01:41:22 +02:00
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
ret = sem_wait(&i8sak->updatesem);
|
|
|
|
if (ret != OK)
|
2017-06-14 08:34:36 +02:00
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
continue;
|
2017-06-14 08:34:36 +02:00
|
|
|
}
|
2017-09-15 16:16:47 +02:00
|
|
|
|
|
|
|
if (i8sak->startblaster)
|
2017-06-14 08:34:36 +02:00
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
i8sak->blasterenabled = true;
|
|
|
|
i8sak->startblaster = false;
|
|
|
|
|
|
|
|
ret = pthread_create(&i8sak->blaster_threadid, NULL, i8sak_blaster_thread,
|
|
|
|
(void *)i8sak);
|
|
|
|
if (ret != 0)
|
2017-06-14 08:34:36 +02:00
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
fprintf(stderr, "failed to start blaster thread: %d\n", ret);
|
|
|
|
return ret;
|
2017-06-14 08:34:36 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
if (i8sak->startsniffer)
|
2017-06-14 08:34:36 +02:00
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
i8sak->snifferenabled = true;
|
|
|
|
i8sak->startsniffer = false;
|
|
|
|
|
|
|
|
ret = pthread_create(&i8sak->sniffer_threadid, NULL, i8sak_sniffer_thread,
|
|
|
|
(void *)i8sak);
|
|
|
|
if (ret != 0)
|
|
|
|
{
|
|
|
|
fprintf(stderr, "failed to start sniffer thread: %d\n", ret);
|
|
|
|
return ret;
|
|
|
|
}
|
2017-06-14 08:34:36 +02:00
|
|
|
}
|
2015-08-04 01:31:07 +02:00
|
|
|
}
|
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
i8sak_eventlistener_stop(i8sak);
|
2017-06-14 08:34:36 +02:00
|
|
|
i8sak->daemon_started = false;
|
|
|
|
close(i8sak->fd);
|
|
|
|
printf("i8sak: daemon closing\n");
|
|
|
|
return OK;
|
|
|
|
}
|
2015-08-04 01:31:07 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
2017-06-14 08:34:36 +02:00
|
|
|
* Name: i8sak_showusage
|
2017-05-09 22:58:19 +02:00
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* Show program usage.
|
|
|
|
*
|
2015-08-04 01:31:07 +02:00
|
|
|
****************************************************************************/
|
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
static int i8sak_showusage(FAR const char *progname, int exitcode)
|
2015-08-04 01:31:07 +02:00
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
fprintf(stderr, "Usage (Use the -h option on any command to get more info): %s\n"
|
|
|
|
" acceptassoc [-h|e]\n"
|
|
|
|
" assoc [-h|p|e|s|w|r|t]\n"
|
|
|
|
" blaster [-h|q|f|p]\n"
|
|
|
|
" get [-h] parameter"
|
2017-06-14 08:34:36 +02:00
|
|
|
" poll [-h]\n"
|
2017-07-18 20:05:42 +02:00
|
|
|
" regdump [-h]\n"
|
2017-09-15 16:16:47 +02:00
|
|
|
" reset [-h]\n"
|
|
|
|
" scan [-h|p|a|e] minch-maxch\n"
|
|
|
|
" set [-h] param val"
|
|
|
|
" sniffer [-h|d]\n"
|
|
|
|
" startpan [-h|b|s] xx:xx\n"
|
|
|
|
" tx [-h|d|m] <hex-payload>\n"
|
2017-06-14 08:34:36 +02:00
|
|
|
, progname);
|
2017-05-09 22:58:19 +02:00
|
|
|
exit(exitcode);
|
2015-08-04 01:31:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* i8_main
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_BUILD_KERNEL
|
|
|
|
int main(int argc, FAR char *argv[])
|
|
|
|
#else
|
|
|
|
int i8_main(int argc, char *argv[])
|
|
|
|
#endif
|
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
FAR const struct i8sak_command_s *i8sakcmd;
|
2017-06-15 19:10:25 +02:00
|
|
|
int argind;
|
|
|
|
int ret;
|
|
|
|
int i;
|
2017-06-11 20:17:09 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
if (!g_i8sak_initialized)
|
2017-06-11 20:17:09 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
sq_init(&g_i8sak_free);
|
|
|
|
sq_init(&g_i8sak_instances);
|
|
|
|
for (i = 0; i < CONFIG_IEEE802154_I8SAK_NINSTANCES; i++)
|
2017-06-11 20:17:09 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
sq_addlast((FAR sq_entry_t *)&g_i8sak_pool[i], &g_i8sak_free);
|
|
|
|
g_i8sak_pool[i].initialized = false;
|
2017-06-11 20:17:09 +02:00
|
|
|
}
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
g_i8sak_initialized = true;
|
2017-05-09 22:58:19 +02:00
|
|
|
}
|
2015-08-04 01:31:07 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
argind = 1;
|
2015-08-04 01:31:07 +02:00
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
/* Check if ifname was included */
|
2017-03-24 21:51:12 +01:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
if (argc > 1)
|
2015-08-04 01:31:07 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
/* Check if argument starts with /dev/ */
|
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
if ((strncmp(argv[argind], "/dev/", 5) == 0) ||
|
|
|
|
(strncmp(argv[argind], "wpan", 4) == 0))
|
2017-06-11 20:17:09 +02:00
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
i8sak_switch_instance(argv[argind]);
|
|
|
|
argind++;
|
2017-05-09 22:58:19 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
if (argc == 2)
|
2017-06-11 20:17:09 +02:00
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
/* Close silently to allow user to set ifname without any
|
2017-06-15 19:10:25 +02:00
|
|
|
* other operation.
|
|
|
|
*/
|
2017-06-11 20:17:09 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
return EXIT_SUCCESS;
|
|
|
|
}
|
2017-06-11 20:17:09 +02:00
|
|
|
}
|
2017-06-15 19:10:25 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
/* Argument must be command */
|
2017-06-11 20:17:09 +02:00
|
|
|
}
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
/* If ifname wasn't included, we need to check if our sticky feature has
|
2017-06-14 08:34:36 +02:00
|
|
|
* ever been set.
|
|
|
|
*/
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-09-15 16:16:47 +02:00
|
|
|
if (!g_activei8sak_set)
|
2015-08-10 11:05:23 +02:00
|
|
|
{
|
2017-09-15 16:16:47 +02:00
|
|
|
fprintf(stderr, "ERROR: Must include ifname the first time you run\n");
|
2017-06-14 08:34:36 +02:00
|
|
|
i8sak_showusage(argv[0], EXIT_FAILURE);
|
2015-08-04 01:31:07 +02:00
|
|
|
}
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
/* Find the command in the g_i8sak_command[] list */
|
2017-06-11 20:17:09 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
i8sakcmd = NULL;
|
|
|
|
for (i = 0; i < NCOMMANDS; i++)
|
|
|
|
{
|
|
|
|
FAR const struct i8sak_command_s *cmd = &g_i8sak_commands[i];
|
|
|
|
if (strcmp(argv[argind], cmd->name) == 0)
|
2017-06-11 20:17:09 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
i8sakcmd = cmd;
|
|
|
|
break;
|
2017-06-11 20:17:09 +02:00
|
|
|
}
|
2017-05-09 22:58:19 +02:00
|
|
|
}
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
if (i8sakcmd == NULL)
|
2015-08-04 01:31:07 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
i8sak_showusage(argv[0], EXIT_FAILURE);
|
2015-08-04 01:31:07 +02:00
|
|
|
}
|
2017-06-14 08:34:36 +02:00
|
|
|
|
|
|
|
/* Special case the help command which has no handler */
|
|
|
|
|
|
|
|
if (i8sakcmd->handler == NULL)
|
2017-05-09 22:58:19 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
i8sak_showusage(argv[0], EXIT_SUCCESS);
|
2017-05-09 22:58:19 +02:00
|
|
|
}
|
2017-06-14 08:34:36 +02:00
|
|
|
|
|
|
|
ret = sem_wait(&g_activei8sak->exclsem);
|
|
|
|
if (ret < 0)
|
2017-05-09 22:58:19 +02:00
|
|
|
{
|
2017-06-14 08:34:36 +02:00
|
|
|
fprintf(stderr, "ERROR: Failed to lock i8sak instance\n");
|
|
|
|
exit(EXIT_FAILURE);
|
2017-05-09 22:58:19 +02:00
|
|
|
}
|
2017-06-15 18:51:25 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
i8sakcmd->handler(g_activei8sak, argc - argind, &argv[argind]);
|
2017-05-09 22:58:19 +02:00
|
|
|
|
2017-06-14 08:34:36 +02:00
|
|
|
sem_post(&g_activei8sak->exclsem);
|
2017-06-11 20:17:09 +02:00
|
|
|
return EXIT_SUCCESS;
|
2015-08-04 01:31:07 +02:00
|
|
|
}
|