Merged in antmerlino/apps/i8sak-improvements (pull request #188)

I8sak improvements

* wireless/ieee802154: Adds support for getting/setting maxretries and promsicuous mode from i8sak

* wireless/ieee802154/i8sak: Fixes a build warning and handles a few cases where a fault can occur due to not catching missing arguments.

Approved-by: Gregory Nutt <gnutt@nuttx.org>
This commit is contained in:
Anthony Merlino 2019-07-26 01:54:30 +00:00 committed by Gregory Nutt
parent 87098590b5
commit 28f57f1007
8 changed files with 142 additions and 3 deletions

View File

@ -112,6 +112,9 @@ int ieee802154_gettxpwr(int fd, FAR int32_t *txpwr);
int ieee802154_setcca(int fd, FAR struct ieee802154_cca_s *cca);
int ieee802154_getcca(int fd, FAR struct ieee802154_cca_s *cca);
int ieee802154_setmaxretries(int fd, uint8_t retries);
int ieee802154_getmaxretries(int fd, FAR uint8_t *retries);
int ieee802154_getdevmode(int fd, FAR enum ieee802154_devmode_e *devmode);
int ieee802154_setassocpermit(int fd, bool assocpermit);
@ -193,6 +196,10 @@ int sixlowpan_settxpwr(int sock, FAR const char *ifname, int32_t txpwr);
int sixlowpan_gettxpwr(int sock, FAR const char *ifname,
FAR int32_t *txpwr);
int sixlowpan_setmaxretries(int sock, FAR const char *ifname, uint8_t retries);
int sixlowpan_getmaxretries(int sock, FAR const char *ifname,
FAR uint8_t *retries);
int sixlowpan_getdevmode(int fd, FAR const char *ifname,
FAR enum ieee802154_devmode_e *devmode);

View File

@ -83,9 +83,9 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
argind = 1;
while ((option = getopt(argc, argv, ":h")) != ERROR)
{
argind++;
switch (option)
{
argind++;
case 'h':
fprintf(stderr, "Gets various parameters and attributes\n"
"Usage: %s [-h] parameter\n"
@ -104,6 +104,8 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
" ep_addrmode = destination address mode"
" rxonidle = Receiver on when idle\n"
" txpwr = Transmit power\n"
" maxretries = macMaxFrameRetries\n"
" promisc = Promiscuous Mode\n"
, argv[0]);
/* Must manually reset optind if we are going to exit early */
@ -125,6 +127,14 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
}
}
/* Make sure that there is another argument */
if (argc <= argind)
{
fprintf(stderr, "ERROR: Must include an attribute to get\n");
i8sak_cmd_error(i8sak); /* This exits for us */
}
/* Check for i8sak level options. Not dependent on opening file/socket */
if (strcmp(argv[argind], "addrmode") == 0)
@ -251,6 +261,23 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
ieee802154_gettxpwr(fd, &u.attr.phy.txpwr);
printf("i8sak: Transmit Power: %d\n", (int)u.attr.phy.txpwr);
}
else if (strcmp(argv[argind], "maxretries") == 0)
{
ieee802154_getmaxretries(fd, &u.attr.mac.max_retries);
printf("i8sak: Max Frame Retries: %d\n", (int)u.attr.mac.max_retries);
}
else if (strcmp(argv[argind], "promisc") == 0)
{
ieee802154_getpromisc(fd, &u.attr.mac.promisc_mode);
if (u.attr.mac.promisc_mode)
{
printf("i8sak: Promiscuous Mode: true\n");
}
else
{
printf("i8sak: Promiscuous Mode: false\n");
}
}
else
{
fprintf(stderr, "ERROR: unsupported parameter: %s\n", argv[argind]);
@ -319,6 +346,23 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
sixlowpan_gettxpwr(fd, i8sak->ifname, &u.attr.phy.txpwr);
printf("i8sak: Transmit Power: %d\n", (int)u.attr.phy.txpwr);
}
else if (strcmp(argv[argind], "maxretries") == 0)
{
sixlowpan_getmaxretries(fd, i8sak->ifname, &u.attr.mac.max_retries);
printf("i8sak: Transmit Power: %d\n", (int)u.attr.mac.max_retries);
}
else if (strcmp(argv[argind], "promisc") == 0)
{
sixlowpan_getpromisc(fd, i8sak->ifname, &u.attr.mac.promisc_mode);
if (u.attr.mac.promisc_mode)
{
printf("i8sak: Promiscuous Mode: true\n");
}
else
{
printf("i8sak: Promiscuous Mode: false\n");
}
}
else
{
fprintf(stderr, "ERROR: unsupported parameter: %s\n", argv[argind]);

View File

@ -897,6 +897,14 @@ int i8sak_main(int argc, char *argv[])
i8sak_showusage(argv[0], EXIT_FAILURE);
}
/* Check to make sure the user supplied a command */
if (argc <= argind)
{
fprintf(stderr, "ERROR: Must include a command\n");
i8sak_showusage(argv[0], EXIT_FAILURE);
}
/* Find the command in the g_i8sak_command[] list */
i8sakcmd = NULL;

View File

@ -83,11 +83,11 @@ void i8sak_set_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
argind = 1;
while ((option = getopt(argc, argv, ":h")) != ERROR)
{
argind++;
switch (option)
{
argind++;
case 'h':
fprintf(stderr, "Gets various parameters and attributes\n"
fprintf(stderr, "Sets various parameters and attributes\n"
"Usage: %s [-h] parameter\n"
" -h = this help menu\n"
" \n"
@ -103,6 +103,8 @@ void i8sak_set_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
" ep_port 1-65535 = port to send to\n"
" rxonidle = Receiver on when idle\n"
" txpwr = Transmit Power\n"
" maxretries = macMaxFrameRetries\n"
" promisc = Promiscuous Mode\n"
, argv[0]);
/* Must manually reset optind if we are going to exit early */
@ -240,6 +242,14 @@ void i8sak_set_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
{
ieee802154_settxpwr(fd, i8sak_str2long(argv[argind + 1]));
}
else if (strcmp(argv[argind], "maxretries") == 0)
{
ieee802154_setmaxretries(fd, i8sak_str2luint8(argv[argind + 1]));
}
else if (strcmp(argv[argind], "promisc") == 0)
{
ieee802154_setpromisc(fd, i8sak_str2bool(argv[argind + 1]));
}
else
{
fprintf(stderr, "ERROR: unsupported parameter: %s\n", argv[argind]);
@ -284,6 +294,14 @@ void i8sak_set_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
{
sixlowpan_settxpwr(fd, i8sak->ifname, i8sak_str2long(argv[argind + 1]));
}
else if (strcmp(argv[argind], "maxretries") == 0)
{
sixlowpan_setmaxretries(fd, i8sak->ifname, i8sak_str2luint8(argv[argind + 1]));
}
else if (strcmp(argv[argind], "promisc") == 0)
{
sixlowpan_setpromisc(fd, i8sak->ifname, i8sak_str2bool(argv[argind + 1]));
}
else
{
fprintf(stderr, "ERROR: unsupported parameter: %s\n", argv[argind]);

View File

@ -195,3 +195,17 @@ int ieee802154_gettxpwr(int fd, FAR int32_t *txpwr)
return ret;
}
int ieee802154_getmaxretries(int fd, FAR uint8_t *retries)
{
struct ieee802154_get_req_s req;
int ret;
req.attr = IEEE802154_ATTR_MAC_MAX_FRAME_RETRIES;
ret = ieee802154_get_req(fd, &req);
*retries = req.attrval.mac.max_retries;
return ret;
}

View File

@ -148,3 +148,13 @@ int ieee802154_settxpwr(int fd, int32_t txpwr)
return ieee802154_set_req(fd, &req);
}
int ieee802154_setmaxretries(int fd, uint8_t retries)
{
struct ieee802154_set_req_s req;
req.attr = IEEE802154_ATTR_MAC_MAX_FRAME_RETRIES;
req.attrval.mac.max_retries = retries;
return ieee802154_set_req(fd, &req);
}

View File

@ -188,6 +188,19 @@ int sixlowpan_getdevmode(int sock, FAR const char *ifname,
return ret;
}
int sixlowpan_getpromisc(int sock, FAR const char *ifname, FAR bool *promisc)
{
struct ieee802154_get_req_s req;
int ret;
req.attr = IEEE802154_ATTR_MAC_PROMISCUOUS_MODE;
ret = sixlowpan_get_req(sock, ifname, &req);
*promisc = req.attrval.mac.promisc_mode;
return ret;
}
int sixlowpan_gettxpwr(int sock, FAR const char *ifname, FAR int32_t *txpwr)
{
struct ieee802154_get_req_s req;
@ -200,3 +213,18 @@ int sixlowpan_gettxpwr(int sock, FAR const char *ifname, FAR int32_t *txpwr)
return ret;
}
int sixlowpan_getmaxretries(int sock, FAR const char *ifname, FAR uint8_t *retries)
{
struct ieee802154_get_req_s req;
int ret;
req.attr = IEEE802154_ATTR_MAC_MAX_FRAME_RETRIES;
ret = sixlowpan_get_req(sock, ifname, &req);
*retries = req.attrval.mac.max_retries;
return ret;
}

View File

@ -155,3 +155,13 @@ int sixlowpan_settxpwr(int sock, FAR const char *ifname, int32_t txpwr)
return sixlowpan_set_req(sock, ifname, &req);
}
int sixlowpan_setmaxretries(int sock, FAR const char *ifname, uint8_t retries)
{
struct ieee802154_set_req_s req;
req.attr = IEEE802154_ATTR_MAC_MAX_FRAME_RETRIES;
req.attrval.mac.max_retries = retries;
return sixlowpan_set_req(sock, ifname, &req);
}