apps: wireless: ieee802154: nxstyle fixes

fix for errors reported by the nxstyle tool

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
This commit is contained in:
Alin Jerpelea 2022-03-07 15:11:14 +00:00 committed by Xiang Xiao
parent 6ccf6db273
commit 73258b3b39
8 changed files with 167 additions and 105 deletions

View File

@ -37,8 +37,8 @@
****************************************************************************/ ****************************************************************************/
/* libmac *******************************************************************/ /* libmac *******************************************************************/
/* Character driver IOCTL helpers */
/* Character driver IOCTL helpers */
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);
@ -148,7 +148,8 @@ int sixlowpan_calibrate_req(int sock, FAR const char *ifname,
#endif #endif
int sixlowpan_setchan(int sock, FAR const char *ifname, uint8_t chan); int sixlowpan_setchan(int sock, FAR const char *ifname, uint8_t chan);
int sixlowpan_getchan(int sock, FAR const char *ifname, FAR uint8_t *chan); int sixlowpan_getchan(int sock, FAR const char *ifname,
FAR uint8_t *chan);
int sixlowpan_setpanid(int sock, FAR const char *ifname, int sixlowpan_setpanid(int sock, FAR const char *ifname,
FAR const uint8_t *panid); FAR const uint8_t *panid);
@ -165,9 +166,11 @@ int sixlowpan_seteaddr(int sock, FAR const char *ifname,
int sixlowpan_geteaddr(int sock, FAR const char *ifname, int sixlowpan_geteaddr(int sock, FAR const char *ifname,
FAR uint8_t *eaddr); FAR uint8_t *eaddr);
int sixlowpan_getcoordsaddr(int fd, FAR const char *ifname, FAR uint8_t *saddr); int sixlowpan_getcoordsaddr(int fd, FAR const char *ifname,
FAR uint8_t *saddr);
int sixlowpan_getcoordeaddr(int fd, FAR const char *ifname, FAR uint8_t *eaddr); int sixlowpan_getcoordeaddr(int fd, FAR const char *ifname,
FAR uint8_t *eaddr);
int sixlowpan_setpromisc(int sock, FAR const char *ifname, bool promisc); int sixlowpan_setpromisc(int sock, FAR const char *ifname, bool promisc);
int sixlowpan_getpromisc(int sock, FAR const char *ifname, int sixlowpan_getpromisc(int sock, FAR const char *ifname,
@ -181,23 +184,26 @@ int sixlowpan_settxpwr(int sock, FAR const char *ifname, int32_t txpwr);
int sixlowpan_gettxpwr(int sock, FAR const char *ifname, int sixlowpan_gettxpwr(int sock, FAR const char *ifname,
FAR int32_t *txpwr); FAR int32_t *txpwr);
int sixlowpan_setmaxretries(int sock, FAR const char *ifname, uint8_t retries); int sixlowpan_setmaxretries(int sock, FAR const char *ifname,
uint8_t retries);
int sixlowpan_getmaxretries(int sock, FAR const char *ifname, int sixlowpan_getmaxretries(int sock, FAR const char *ifname,
FAR uint8_t *retries); FAR uint8_t *retries);
int sixlowpan_setfcslen(int sock, FAR const char *ifname, uint8_t fcslen); int sixlowpan_setfcslen(int sock, FAR const char *ifname, uint8_t fcslen);
int sixlowpan_getfcslen(int sock, FAR const char *ifname, FAR uint8_t *fcslen); int sixlowpan_getfcslen(int sock, FAR const char *ifname,
FAR uint8_t *fcslen);
int sixlowpan_getdevmode(int fd, FAR const char *ifname, int sixlowpan_getdevmode(int fd, FAR const char *ifname,
FAR enum ieee802154_devmode_e *devmode); FAR enum ieee802154_devmode_e *devmode);
int sixlowpan_setassocpermit(int sock, FAR const char *ifname, bool assocpermit); int sixlowpan_setassocpermit(int sock, FAR const char *ifname,
bool assocpermit);
#endif /* CONFIG_NET_6LOWPAN*/ #endif /* CONFIG_NET_6LOWPAN */
/* libutils *****************************************************************/ /* libutils *****************************************************************/
int ieee802154_addrtostr(FAR char *buf, int len, int ieee802154_addrtostr(FAR char *buf, int len,
FAR struct ieee802154_addr_s *addr); FAR struct ieee802154_addr_s *addr);
#endif /*__APPS_INCLUDE_WIRELESS_IEEE802154_H */ #endif /* __APPS_INCLUDE_WIRELESS_IEEE802154_H */

View File

@ -114,7 +114,8 @@ void i8sak_acceptassoc_cmd(FAR struct i8sak_s *i8sak, int argc,
fd = open(i8sak->ifname, O_RDWR); fd = open(i8sak->ifname, O_RDWR);
if (fd < 0) if (fd < 0)
{ {
fprintf(stderr, "ERROR: cannot open %s, errno=%d\n", i8sak->ifname, errno); fprintf(stderr, "ERROR: cannot open %s, errno=%d\n",
i8sak->ifname, errno);
i8sak_cmd_error(i8sak); i8sak_cmd_error(i8sak);
} }
@ -170,7 +171,8 @@ static void acceptassoc_eventcb(FAR struct ieee802154_primitive_s *primitive,
*/ */
if (i8sak->acceptall || if (i8sak->acceptall ||
IEEE802154_EADDRCMP(primitive->u.assocind.devaddr, i8sak->ep_addr.eaddr)) IEEE802154_EADDRCMP(primitive->u.assocind.devaddr,
i8sak->ep_addr.eaddr))
{ {
/* Assign the short address */ /* Assign the short address */

View File

@ -83,7 +83,7 @@ static pthread_addr_t i8sak_eventthread(pthread_addr_t arg)
#endif #endif
while (i8sak->eventlistener_run) while (i8sak->eventlistener_run)
{ {
if (i8sak->mode == I8SAK_MODE_CHAR) if (i8sak->mode == I8SAK_MODE_CHAR)
{ {
ret = ioctl(i8sak->fd, MAC802154IOC_GET_EVENT, ret = ioctl(i8sak->fd, MAC802154IOC_GET_EVENT,
@ -164,13 +164,15 @@ static pthread_addr_t i8sak_eventthread(pthread_addr_t arg)
/* Link the receiver back into the free list */ /* Link the receiver back into the free list */
sq_addlast((FAR sq_entry_t *)receiver, &i8sak->eventreceivers_free); sq_addlast((FAR sq_entry_t *)receiver,
&i8sak->eventreceivers_free);
} }
} }
receiver = (FAR struct i8sak_eventreceiver_s *)sq_next( receiver = (FAR struct i8sak_eventreceiver_s *)sq_next(
(FAR sq_entry_t *)receiver); (FAR sq_entry_t *)receiver);
} }
sem_post(&i8sak->eventsem); sem_post(&i8sak->eventsem);
} }
@ -219,7 +221,8 @@ int i8sak_eventlistener_start(FAR struct i8sak_s *i8sak)
i8sak->eventlistener_run = true; i8sak->eventlistener_run = true;
ret = pthread_create(&i8sak->eventlistener_threadid, NULL, i8sak_eventthread, ret = pthread_create(&i8sak->eventlistener_threadid,
NULL, i8sak_eventthread,
(void *)i8sak); (void *)i8sak);
if (ret != 0) if (ret != 0)
{ {
@ -266,8 +269,9 @@ int i8sak_eventlistener_stop(FAR struct i8sak_s *i8sak)
* Name: i8sak_eventlistener_addreceiver * Name: i8sak_eventlistener_addreceiver
* *
* Description: * Description:
* Add an event receiver. An event receiver consists of a callback and flags * Add an event receiver.
* for which events should be sent to the callback. * An event receiver consists of a callback and flags for which events
* should be sent to the callback.
* *
* Parameters: * Parameters:
* handle - handle to the i8sak instance struct * handle - handle to the i8sak instance struct
@ -304,7 +308,7 @@ int i8sak_eventlistener_addreceiver(FAR struct i8sak_s *i8sak,
/* Allocate a receiver struct from the static pool */ /* Allocate a receiver struct from the static pool */
receiver = (FAR struct i8sak_eventreceiver_s *)sq_remfirst( receiver = (FAR struct i8sak_eventreceiver_s *)sq_remfirst(
&i8sak->eventreceivers_free); &i8sak->eventreceivers_free);
if (receiver == NULL) if (receiver == NULL)
{ {
fprintf(stderr, "failed to add receiver: %d\n", ENOMEM); fprintf(stderr, "failed to add receiver: %d\n", ENOMEM);
@ -376,7 +380,8 @@ int i8sak_eventlistener_removereceiver(FAR struct i8sak_s *i8sak,
/* Link the receiver back into the free list */ /* Link the receiver back into the free list */
sq_addlast((FAR sq_entry_t *)receiver, &i8sak->eventreceivers_free); sq_addlast((FAR sq_entry_t *)receiver,
&i8sak->eventreceivers_free);
sem_post(&i8sak->eventsem); sem_post(&i8sak->eventsem);

View File

@ -18,7 +18,7 @@
* *
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
@ -91,6 +91,7 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
" maxretries = macMaxFrameRetries\n" " maxretries = macMaxFrameRetries\n"
" promisc = Promiscuous Mode\n" " promisc = Promiscuous Mode\n"
, argv[0]); , argv[0]);
/* Must manually reset optind if we are going to exit early */ /* Must manually reset optind if we are going to exit early */
optind = -1; optind = -1;
@ -98,12 +99,14 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
case ':': case ':':
fprintf(stderr, "ERROR: missing argument\n"); fprintf(stderr, "ERROR: missing argument\n");
/* Must manually reset optind if we are going to exit early */ /* Must manually reset optind if we are going to exit early */
optind = -1; optind = -1;
i8sak_cmd_error(i8sak); /* This exits for us */ i8sak_cmd_error(i8sak); /* This exits for us */
case '?': case '?':
fprintf(stderr, "ERROR: unknown argument\n"); fprintf(stderr, "ERROR: unknown argument\n");
/* Must manually reset optind if we are going to exit early */ /* Must manually reset optind if we are going to exit early */
optind = -1; optind = -1;
@ -170,7 +173,8 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
#ifdef CONFIG_NET_6LOWPAN #ifdef CONFIG_NET_6LOWPAN
else if (strcmp(argv[argind], "ep_port") == 0) else if (strcmp(argv[argind], "ep_port") == 0)
{ {
printf("i8sak: Endpoint Port: %d\n", NTOHS(i8sak->ep_in6addr.sin6_port)); printf("i8sak: Endpoint Port: %d\n",
NTOHS(i8sak->ep_in6addr.sin6_port));
} }
else if (strcmp(argv[argind], "snifferport") == 0) else if (strcmp(argv[argind], "snifferport") == 0)
{ {
@ -248,7 +252,8 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
else if (strcmp(argv[argind], "maxretries") == 0) else if (strcmp(argv[argind], "maxretries") == 0)
{ {
ieee802154_getmaxretries(fd, &u.attr.mac.max_retries); ieee802154_getmaxretries(fd, &u.attr.mac.max_retries);
printf("i8sak: Max Frame Retries: %d\n", (int)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) else if (strcmp(argv[argind], "promisc") == 0)
{ {
@ -264,7 +269,8 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
} }
else else
{ {
fprintf(stderr, "ERROR: unsupported parameter: %s\n", argv[argind]); fprintf(stderr,
"ERROR: unsupported parameter: %s\n", argv[argind]);
} }
} }
#ifdef CONFIG_NET_6LOWPAN #ifdef CONFIG_NET_6LOWPAN
@ -273,7 +279,8 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
fd = socket(PF_INET6, SOCK_DGRAM, 0); fd = socket(PF_INET6, SOCK_DGRAM, 0);
if (fd < 0) if (fd < 0)
{ {
fprintf(stderr, "ERROR: failed to open socket, errno=%d\n", errno); fprintf(stderr,
"ERROR: failed to open socket, errno=%d\n", errno);
i8sak_cmd_error(i8sak); i8sak_cmd_error(i8sak);
} }
@ -309,7 +316,8 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
} }
else if (strcmp(argv[argind], "coordeaddr") == 0) else if (strcmp(argv[argind], "coordeaddr") == 0)
{ {
sixlowpan_getcoordeaddr(fd, i8sak->ifname, u.attr.mac.coordeaddr); sixlowpan_getcoordeaddr(fd, i8sak->ifname,
u.attr.mac.coordeaddr);
printf("i8sak: Coordinator Extended Address: " printf("i8sak: Coordinator Extended Address: "
PRINTF_FORMAT_EADDR(u.attr.mac.coordeaddr)); PRINTF_FORMAT_EADDR(u.attr.mac.coordeaddr));
} }
@ -332,12 +340,15 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
} }
else if (strcmp(argv[argind], "maxretries") == 0) else if (strcmp(argv[argind], "maxretries") == 0)
{ {
sixlowpan_getmaxretries(fd, i8sak->ifname, &u.attr.mac.max_retries); sixlowpan_getmaxretries(fd, i8sak->ifname,
printf("i8sak: Max Retries: %d\n", (int)u.attr.mac.max_retries); &u.attr.mac.max_retries);
printf("i8sak: Max Retries: %d\n",
(int)u.attr.mac.max_retries);
} }
else if (strcmp(argv[argind], "promisc") == 0) else if (strcmp(argv[argind], "promisc") == 0)
{ {
sixlowpan_getpromisc(fd, i8sak->ifname, &u.attr.mac.promisc_mode); sixlowpan_getpromisc(fd, i8sak->ifname,
&u.attr.mac.promisc_mode);
if (u.attr.mac.promisc_mode) if (u.attr.mac.promisc_mode)
{ {
printf("i8sak: Promiscuous Mode: true\n"); printf("i8sak: Promiscuous Mode: true\n");
@ -349,7 +360,8 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
} }
else else
{ {
fprintf(stderr, "ERROR: unsupported parameter: %s\n", argv[argind]); fprintf(stderr, "ERROR: unsupported parameter: %s\n",
argv[argind]);
} }
} }
#endif #endif

View File

@ -18,7 +18,7 @@
* *
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
@ -62,6 +62,7 @@ void i8sak_regdump_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
"Usage: %s [-h]\n" "Usage: %s [-h]\n"
" -h = this help menu\n" " -h = this help menu\n"
, argv[0]); , argv[0]);
/* Must manually reset optind if we are going to exit early */ /* Must manually reset optind if we are going to exit early */
optind = -1; optind = -1;
@ -69,12 +70,14 @@ void i8sak_regdump_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
case ':': case ':':
fprintf(stderr, "ERROR: missing argument\n"); fprintf(stderr, "ERROR: missing argument\n");
/* Must manually reset optind if we are going to exit early */ /* Must manually reset optind if we are going to exit early */
optind = -1; optind = -1;
i8sak_cmd_error(i8sak); /* This exits for us */ i8sak_cmd_error(i8sak); /* This exits for us */
case '?': case '?':
fprintf(stderr, "ERROR: unknown argument\n"); fprintf(stderr, "ERROR: unknown argument\n");
/* Must manually reset optind if we are going to exit early */ /* Must manually reset optind if we are going to exit early */
optind = -1; optind = -1;
@ -93,6 +96,7 @@ void i8sak_regdump_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
i8sak->ifname, errno); i8sak->ifname, errno);
i8sak_cmd_error(i8sak); i8sak_cmd_error(i8sak);
} }
ieee802154_get_req(fd, &req); ieee802154_get_req(fd, &req);
} }
#ifdef CONFIG_NET_6LOWPAN #ifdef CONFIG_NET_6LOWPAN

View File

@ -18,7 +18,7 @@
* *
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
@ -61,6 +61,7 @@ void i8sak_reset_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
"Usage: %s [-h]\n" "Usage: %s [-h]\n"
" -h = this help menu\n" " -h = this help menu\n"
, argv[0]); , argv[0]);
/* Must manually reset optind if we are going to exit early */ /* Must manually reset optind if we are going to exit early */
optind = -1; optind = -1;
@ -68,12 +69,14 @@ void i8sak_reset_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
case ':': case ':':
fprintf(stderr, "ERROR: missing argument\n"); fprintf(stderr, "ERROR: missing argument\n");
/* Must manually reset optind if we are going to exit early */ /* Must manually reset optind if we are going to exit early */
optind = -1; optind = -1;
i8sak_cmd_error(i8sak); /* This exits for us */ i8sak_cmd_error(i8sak); /* This exits for us */
case '?': case '?':
fprintf(stderr, "ERROR: unknown argument\n"); fprintf(stderr, "ERROR: unknown argument\n");
/* Must manually reset optind if we are going to exit early */ /* Must manually reset optind if we are going to exit early */
optind = -1; optind = -1;

View File

@ -18,7 +18,7 @@
* *
****************************************************************************/ ****************************************************************************/
/**************************************************************************** /****************************************************************************
* Included Files * Included Files
****************************************************************************/ ****************************************************************************/
@ -72,24 +72,28 @@ void i8sak_set_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
{ {
case 'h': case 'h':
fprintf(stderr, "Sets various parameters and attributes\n" fprintf(stderr, "Sets various parameters and attributes\n"
"Usage: %s [-h] parameter\n" "Usage: %s [-h] parameter\n"
" -h = this help menu\n" " -h = this help menu\n"
"\n" "\n"
"Parameters:\n" "Parameters:\n"
" chan 0-255 = RF channel (only some channels valid per radio)\n" " chan 0-255 = RF channel "
" panid xx:xx = PAN Identifier\n" "(only some channels valid per radio)\n"
" saddr xx:xx = this node's short address\n" " panid xx:xx = PAN Identifier\n"
" eaddr xx:xx:xx:xx:xx:xx:xx:xx = this node's extended address\n" " saddr xx:xx = this node's short address\n"
" addrmode s|e = source addressing mode\n" " eaddr xx:xx:xx:xx:xx:xx:xx:xx = this node's "
" ep_saddr xx:xx = i8sak endpoint short address\n" "extended address\n"
" ep_eaddr xx:xx:xx:xx:xx:xx:xx:xx = i8sak endpoint extended address\n" " addrmode s|e = source addressing mode\n"
" ep_addrmode s|e = destination addressing mode\n" " ep_saddr xx:xx = i8sak endpoint short address\n"
" ep_port 1-65535 = port to send to\n" " ep_eaddr xx:xx:xx:xx:xx:xx:xx:xx = i8sak "
" rxonidle = Receiver on when idle\n" "endpoint extended address\n"
" txpwr = Transmit Power\n" " ep_addrmode s|e = destination addressing mode\n"
" maxretries = macMaxFrameRetries\n" " ep_port 1-65535 = port to send to\n"
" promisc = Promiscuous Mode\n" " rxonidle = Receiver on when idle\n"
, argv[0]); " txpwr = Transmit Power\n"
" maxretries = macMaxFrameRetries\n"
" promisc = Promiscuous Mode\n"
, argv[0]);
/* Must manually reset optind if we are going to exit early */ /* Must manually reset optind if we are going to exit early */
optind = -1; optind = -1;
@ -97,12 +101,14 @@ void i8sak_set_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
case ':': case ':':
fprintf(stderr, "ERROR: missing argument\n"); fprintf(stderr, "ERROR: missing argument\n");
/* Must manually reset optind if we are going to exit early */ /* Must manually reset optind if we are going to exit early */
optind = -1; optind = -1;
i8sak_cmd_error(i8sak); /* This exits for us */ i8sak_cmd_error(i8sak); /* This exits for us */
case '?': case '?':
fprintf(stderr, "ERROR: unknown argument\n"); fprintf(stderr, "ERROR: unknown argument\n");
/* Must manually reset optind if we are going to exit early */ /* Must manually reset optind if we are going to exit early */
optind = -1; optind = -1;
@ -183,7 +189,8 @@ void i8sak_set_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
#ifdef CONFIG_NET_6LOWPAN #ifdef CONFIG_NET_6LOWPAN
else if (strcmp(argv[argind], "ep_port") == 0) else if (strcmp(argv[argind], "ep_port") == 0)
{ {
i8sak->ep_in6addr.sin6_port = HTONS(i8sak_str2luint16(argv[argind + 1])); i8sak->ep_in6addr.sin6_port =
HTONS(i8sak_str2luint16(argv[argind + 1]));
} }
#endif #endif
@ -232,7 +239,8 @@ void i8sak_set_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
} }
else if (strcmp(argv[argind], "maxretries") == 0) else if (strcmp(argv[argind], "maxretries") == 0)
{ {
ieee802154_setmaxretries(fd, i8sak_str2luint8(argv[argind + 1])); ieee802154_setmaxretries(fd,
i8sak_str2luint8(argv[argind + 1]));
} }
else if (strcmp(argv[argind], "promisc") == 0) else if (strcmp(argv[argind], "promisc") == 0)
{ {
@ -240,7 +248,8 @@ void i8sak_set_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
} }
else else
{ {
fprintf(stderr, "ERROR: unsupported parameter: %s\n", argv[argind]); fprintf(stderr,
"ERROR: unsupported parameter: %s\n", argv[argind]);
} }
} }
#ifdef CONFIG_NET_6LOWPAN #ifdef CONFIG_NET_6LOWPAN
@ -249,7 +258,8 @@ void i8sak_set_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
fd = socket(PF_INET6, SOCK_DGRAM, 0); fd = socket(PF_INET6, SOCK_DGRAM, 0);
if (fd < 0) if (fd < 0)
{ {
fprintf(stderr, "ERROR: failed to open socket, errno=%d\n", errno); fprintf(stderr,
"ERROR: failed to open socket, errno=%d\n", errno);
i8sak_cmd_error(i8sak); i8sak_cmd_error(i8sak);
} }
@ -276,23 +286,28 @@ void i8sak_set_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
} }
else if (strcmp(argv[argind], "rxonidle") == 0) else if (strcmp(argv[argind], "rxonidle") == 0)
{ {
sixlowpan_setrxonidle(fd, i8sak->ifname, i8sak_str2bool(argv[argind + 1])); sixlowpan_setrxonidle(fd,
i8sak->ifname, i8sak_str2bool(argv[argind + 1]));
} }
else if (strcmp(argv[argind], "txpwr") == 0) else if (strcmp(argv[argind], "txpwr") == 0)
{ {
sixlowpan_settxpwr(fd, i8sak->ifname, i8sak_str2long(argv[argind + 1])); sixlowpan_settxpwr(fd,
i8sak->ifname, i8sak_str2long(argv[argind + 1]));
} }
else if (strcmp(argv[argind], "maxretries") == 0) else if (strcmp(argv[argind], "maxretries") == 0)
{ {
sixlowpan_setmaxretries(fd, i8sak->ifname, i8sak_str2luint8(argv[argind + 1])); sixlowpan_setmaxretries(fd,
i8sak->ifname, i8sak_str2luint8(argv[argind + 1]));
} }
else if (strcmp(argv[argind], "promisc") == 0) else if (strcmp(argv[argind], "promisc") == 0)
{ {
sixlowpan_setpromisc(fd, i8sak->ifname, i8sak_str2bool(argv[argind + 1])); sixlowpan_setpromisc(fd,
i8sak->ifname, i8sak_str2bool(argv[argind + 1]));
} }
else else
{ {
fprintf(stderr, "ERROR: unsupported parameter: %s\n", argv[argind]); fprintf(stderr,
"ERROR: unsupported parameter: %s\n", argv[argind]);
} }
} }
#endif #endif

View File

@ -141,10 +141,10 @@ static int i8shark_init(FAR struct i8shark_state_s *i8shark)
* Name : i8shark_daemon * Name : i8shark_daemon
* *
* Description : * Description :
* This daemon reads all incoming IEEE 802.15.4 frames from a MAC802154 character * This daemon reads all incoming IEEE 802.15.4 frames from a MAC802154
* driver, packages the frames into a Wireshark Zigbee Encapsulate Protocol (ZEP) * character driver, packages the frames into a Wireshark Zigbee
* packet and sends it over Ethernet to the specified host machine running * Encapsulate Protocol (ZEP) packet and sends it over Ethernet to the
* Wireshark. * specified host machine running Wireshark.
* *
****************************************************************************/ ****************************************************************************/
@ -163,7 +163,9 @@ static int i8shark_daemon(int argc, FAR char *argv[])
fd = open(g_i8shark.devpath, O_RDWR); fd = open(g_i8shark.devpath, O_RDWR);
if (fd < 0) if (fd < 0)
{ {
fprintf(stderr, "ERROR: cannot open %s, errno=%d\n", g_i8shark.devpath, errno); fprintf(stderr,
"ERROR: cannot open %s, errno=%d\n",
g_i8shark.devpath, errno);
g_i8shark.daemon_started = false; g_i8shark.daemon_started = false;
ret = errno; ret = errno;
return ret; return ret;
@ -187,11 +189,12 @@ static int i8shark_daemon(int argc, FAR char *argv[])
return -1; return -1;
} }
/* We bind to the IP address of the outbound interface so that the OS knows /* We bind to the IP address of the outbound interface so that
* which interface to use to send the packet. * the OS knows which interface to use to send the packet.
*/ */
netlib_get_ipv4addr(CONFIG_IEEE802154_I8SHARK_FORWARDING_IFNAME, &addr.sin_addr); netlib_get_ipv4addr(CONFIG_IEEE802154_I8SHARK_FORWARDING_IFNAME,
&addr.sin_addr);
addr.sin_port = 0; addr.sin_port = 0;
addr.sin_family = AF_INET; addr.sin_family = AF_INET;
addrlen = sizeof(struct sockaddr_in); addrlen = sizeof(struct sockaddr_in);
@ -202,15 +205,17 @@ static int i8shark_daemon(int argc, FAR char *argv[])
return -1; return -1;
} }
/* Setup our remote address. Wireshark expects ZEP packets over UDP on port 17754 */ /* Setup our remote address.
* Wireshark expects ZEP packets over UDP on port 17754
*/
raddr.sin_family = AF_INET; raddr.sin_family = AF_INET;
raddr.sin_port = HTONS(17754); raddr.sin_port = HTONS(17754);
raddr.sin_addr.s_addr = HTONL(CONFIG_IEEE802154_I8SHARK_HOST_IPADDR); raddr.sin_addr.s_addr = HTONL(CONFIG_IEEE802154_I8SHARK_HOST_IPADDR);
/* Loop until the daemon is shutdown reading incoming IEEE 802.15.4 frames, /* Loop until the daemon is shutdown reading incoming IEEE 802.15.4 frames,
* packing them into Wireshark "Zigbee Encapsulation Packets" (ZEP) and sending * packing them into Wireshark "Zigbee Encapsulation Packets" (ZEP)
* them over UDP to Wireshark. * and sending them over UDP to Wireshark.
*/ */
while (!g_i8shark.daemon_shutdown) while (!g_i8shark.daemon_shutdown)
@ -251,8 +256,8 @@ static int i8shark_daemon(int argc, FAR char *argv[])
{ {
zepframe[i++] = 2; zepframe[i++] = 2;
/* Not sure why, but the ZEP header allows for a 4-byte sequence no. /* Not sure why, but the ZEP header allows for a 4-byte sequence
* despite 802.15.4 sequence number only being 1-byte * no. despite 802.15.4 sequence number only being 1-byte
*/ */
zepframe[i] = frame.meta.dsn; zepframe[i] = frame.meta.dsn;
@ -268,15 +273,16 @@ static int i8shark_daemon(int argc, FAR char *argv[])
/* For now, just hard code the device ID to an arbitrary value */ /* For now, just hard code the device ID to an arbitrary value */
zepframe[i++] = 0xFA; zepframe[i++] = 0xfa;
zepframe[i++] = 0xDE; zepframe[i++] = 0xde;
/* Not completely sure what LQI mode is. My best guess as of now based /* Not completely sure what LQI mode is. My best guess as of now
* on a few comments in the Wireshark code is that it determines whether * based on a few comments in the Wireshark code is that it
* the last 2 bytes of the frame portion of the packet is the CRC or the * determines whether the last 2 bytes of the frame portion of the
* LQI. I believe it is CRC = 1, LQI = 0. We will assume the CRC is the * packet is the CRC or the LQI.
* last few bytes as that is what the MAC layer expects. However, this * I believe it is CRC = 1, LQI = 0. We will assume the CRC is the
* may be a bad assumption for certain radios. * last few bytes as that is what the MAC layer expects.
* However, this may be a bad assumption for certain radios.
*/ */
zepframe[i++] = 1; zepframe[i++] = 1;
@ -285,20 +291,22 @@ static int i8shark_daemon(int argc, FAR char *argv[])
zepframe[i++] = frame.meta.lqi; zepframe[i++] = frame.meta.lqi;
/* Need to use NTP to get time, but for now, include the system time */ /* Need to use NTP to get time, but for now,
* include the system time
*/
systime = clock(); systime = clock();
memcpy(&zepframe[i], &systime, 8); memcpy(&zepframe[i], &systime, 8);
i += 8; i += 8;
/* Not sure why, but the ZEP header allows for a 4-byte sequence no. /* Not sure why, but the ZEP header allows for a 4-byte sequence
* despite 802.15.4 sequence number only being 1-byte * no. despite 802.15.4 sequence number only being 1-byte
*/ */
zepframe[i] = frame.meta.dsn; zepframe[i] = frame.meta.dsn;
zepframe[i+1] = 0; zepframe[i + 1] = 0;
zepframe[i+2] = 0; zepframe[i + 2] = 0;
zepframe[i+3] = 0; zepframe[i + 3] = 0;
i += 4; i += 4;
/* Skip 10-bytes for reserved fields */ /* Skip 10-bytes for reserved fields */
@ -320,16 +328,17 @@ static int i8shark_daemon(int argc, FAR char *argv[])
memcpy(&zepframe[i], frame.payload, frame.offset); memcpy(&zepframe[i], frame.payload, frame.offset);
i += frame.offset; i += frame.offset;
/* XBee radios use a 2 byte "application header" to support duplicate packet /* XBee radios use a 2 byte "application header" to support duplicate
* detection. Wireshark doesn't know how to handle this data, so we provide * packet detection. Wireshark doesn't know how to handle this data,
* a configuration option that drops the first 2 bytes of the payload portion * so we provide a configuration option that drops the first 2 bytes
* of the frame for all sniffed frames * of the payload portion of the frame for all sniffed frames
* *
* NOTE: Since we remove data from the frame, the FCS is no longer valid * NOTE:
* and Wireshark will fail to disect the frame. Wireshark ignores a case * Since we remove data from the frame, the FCS is no longer valid
* where the FCS is not included in the actual frame. Therefore, we * and Wireshark will fail to disect the frame. Wireshark ignores a
* subtract 4 rather than 2 to remove the FCS field so that the disector * case where the FCS is not included in the actual frame. Therefore,
* will not fail. * we subtract 4 rather than 2 to remove the FCS field so that the
* disector will not fail.
*/ */
memcpy(&zepframe[i], (frame.payload + frame.offset + 2), memcpy(&zepframe[i], (frame.payload + frame.offset + 2),
@ -341,11 +350,11 @@ static int i8shark_daemon(int argc, FAR char *argv[])
*/ */
#ifdef CONFIG_IEEE802154_I8SHARK_SUPPRESS_FCS #ifdef CONFIG_IEEE802154_I8SHARK_SUPPRESS_FCS
{ {
uint8_t fcslen; uint8_t fcslen;
ieee802154_getfcslen(fd, &fcslen); ieee802154_getfcslen(fd, &fcslen);
frame.length -= fcslen; frame.length -= fcslen;
} }
#endif #endif
memcpy(&zepframe[i], frame.payload, frame.length); memcpy(&zepframe[i], frame.payload, frame.length);
@ -354,10 +363,12 @@ static int i8shark_daemon(int argc, FAR char *argv[])
/* Send the encapsulated frame to Wireshark over UDP */ /* Send the encapsulated frame to Wireshark over UDP */
nbytes = sendto(sockfd, zepframe, i, 0, (struct sockaddr*)&raddr, addrlen); nbytes = sendto(sockfd, zepframe, i, 0,
(struct sockaddr *)&raddr, addrlen);
if (nbytes < i) if (nbytes < i)
{ {
fprintf(stderr, "ERROR: sendto() did not send all bytes. %d\n", errno); fprintf(stderr,
"ERROR: sendto() did not send all bytes. %d\n", errno);
} }
} }
@ -386,7 +397,9 @@ int main(int argc, FAR char *argv[])
if (argc > 1) if (argc > 1)
{ {
/* If the first argument is an interface, update our character device path */ /* If the first argument is an interface,
* update our character device path
*/
if (strncmp(argv[argind], "/dev/", 5) == 0) if (strncmp(argv[argind], "/dev/", 5) == 0)
{ {
@ -394,7 +407,9 @@ int main(int argc, FAR char *argv[])
if (!strcmp(g_i8shark.devpath, argv[argind])) if (!strcmp(g_i8shark.devpath, argv[argind]))
{ {
/* Adapter daemon can't be running when we change device path */ /* Adapter daemon can't be running when we change
* device path
*/
if (g_i8shark.daemon_started) if (g_i8shark.daemon_started)
{ {
@ -414,14 +429,14 @@ int main(int argc, FAR char *argv[])
/* If the daemon is not running, start it. */ /* If the daemon is not running, start it. */
g_i8shark.daemon_pid = task_create("i8shark", g_i8shark.daemon_pid = task_create("i8shark",
CONFIG_IEEE802154_I8SHARK_DAEMON_PRIORITY, CONFIG_IEEE802154_I8SHARK_DAEMON_PRIORITY,
CONFIG_IEEE802154_I8SHARK_DAEMON_STACKSIZE, CONFIG_IEEE802154_I8SHARK_DAEMON_STACKSIZE,
i8shark_daemon, NULL); i8shark_daemon, NULL);
if (g_i8shark.daemon_pid < 0) if (g_i8shark.daemon_pid < 0)
{ {
fprintf(stderr, "failed to start daemon\n"); fprintf(stderr, "failed to start daemon\n");
return ERROR; return ERROR;
} }
return OK; return OK;
} }