You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2022/03/07 17:45:09 UTC
[incubator-nuttx-apps] 13/14: apps: wireless: ieee802154: nxstyle fixes
This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/incubator-nuttx-apps.git
commit 73258b3b39c1b297391c7f00ac20c85d8353a4e8
Author: Alin Jerpelea <al...@sony.com>
AuthorDate: Mon Mar 7 15:11:14 2022 +0000
apps: wireless: ieee802154: nxstyle fixes
fix for errors reported by the nxstyle tool
Signed-off-by: Alin Jerpelea <al...@sony.com>
---
include/wireless/ieee802154.h | 26 ++++---
wireless/ieee802154/i8sak/i8sak_acceptassoc.c | 6 +-
wireless/ieee802154/i8sak/i8sak_events.c | 19 +++--
wireless/ieee802154/i8sak/i8sak_get.c | 32 +++++---
wireless/ieee802154/i8sak/i8sak_regdump.c | 6 +-
wireless/ieee802154/i8sak/i8sak_reset.c | 5 +-
wireless/ieee802154/i8sak/i8sak_set.c | 71 ++++++++++-------
wireless/ieee802154/i8shark/i8shark_main.c | 107 +++++++++++++++-----------
8 files changed, 167 insertions(+), 105 deletions(-)
diff --git a/include/wireless/ieee802154.h b/include/wireless/ieee802154.h
index 0a6ad26..383aa3f 100644
--- a/include/wireless/ieee802154.h
+++ b/include/wireless/ieee802154.h
@@ -37,8 +37,8 @@
****************************************************************************/
/* 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_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
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,
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,
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_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,
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,
FAR uint8_t *retries);
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,
- 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 *****************************************************************/
int ieee802154_addrtostr(FAR char *buf, int len,
FAR struct ieee802154_addr_s *addr);
-#endif /*__APPS_INCLUDE_WIRELESS_IEEE802154_H */
+#endif /* __APPS_INCLUDE_WIRELESS_IEEE802154_H */
diff --git a/wireless/ieee802154/i8sak/i8sak_acceptassoc.c b/wireless/ieee802154/i8sak/i8sak_acceptassoc.c
index 56f0384..e927f2d 100644
--- a/wireless/ieee802154/i8sak/i8sak_acceptassoc.c
+++ b/wireless/ieee802154/i8sak/i8sak_acceptassoc.c
@@ -114,7 +114,8 @@ void i8sak_acceptassoc_cmd(FAR struct i8sak_s *i8sak, int argc,
fd = open(i8sak->ifname, O_RDWR);
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);
}
@@ -170,7 +171,8 @@ static void acceptassoc_eventcb(FAR struct ieee802154_primitive_s *primitive,
*/
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 */
diff --git a/wireless/ieee802154/i8sak/i8sak_events.c b/wireless/ieee802154/i8sak/i8sak_events.c
index 6729c77..7b9ad57 100644
--- a/wireless/ieee802154/i8sak/i8sak_events.c
+++ b/wireless/ieee802154/i8sak/i8sak_events.c
@@ -83,7 +83,7 @@ static pthread_addr_t i8sak_eventthread(pthread_addr_t arg)
#endif
while (i8sak->eventlistener_run)
- {
+ {
if (i8sak->mode == I8SAK_MODE_CHAR)
{
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 */
- 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(
(FAR sq_entry_t *)receiver);
}
+
sem_post(&i8sak->eventsem);
}
@@ -219,7 +221,8 @@ int i8sak_eventlistener_start(FAR struct i8sak_s *i8sak)
i8sak->eventlistener_run = true;
- ret = pthread_create(&i8sak->eventlistener_threadid, NULL, i8sak_eventthread,
+ ret = pthread_create(&i8sak->eventlistener_threadid,
+ NULL, i8sak_eventthread,
(void *)i8sak);
if (ret != 0)
{
@@ -266,8 +269,9 @@ int i8sak_eventlistener_stop(FAR struct i8sak_s *i8sak)
* Name: i8sak_eventlistener_addreceiver
*
* Description:
- * Add an event receiver. An event receiver consists of a callback and flags
- * for which events should be sent to the callback.
+ * Add an event receiver.
+ * An event receiver consists of a callback and flags for which events
+ * should be sent to the callback.
*
* Parameters:
* 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 */
receiver = (FAR struct i8sak_eventreceiver_s *)sq_remfirst(
- &i8sak->eventreceivers_free);
+ &i8sak->eventreceivers_free);
if (receiver == NULL)
{
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 */
- sq_addlast((FAR sq_entry_t *)receiver, &i8sak->eventreceivers_free);
+ sq_addlast((FAR sq_entry_t *)receiver,
+ &i8sak->eventreceivers_free);
sem_post(&i8sak->eventsem);
diff --git a/wireless/ieee802154/i8sak/i8sak_get.c b/wireless/ieee802154/i8sak/i8sak_get.c
index b376839..bc1e53e 100644
--- a/wireless/ieee802154/i8sak/i8sak_get.c
+++ b/wireless/ieee802154/i8sak/i8sak_get.c
@@ -18,7 +18,7 @@
*
****************************************************************************/
- /****************************************************************************
+/****************************************************************************
* Included Files
****************************************************************************/
@@ -91,6 +91,7 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
" maxretries = macMaxFrameRetries\n"
" promisc = Promiscuous Mode\n"
, argv[0]);
+
/* Must manually reset optind if we are going to exit early */
optind = -1;
@@ -98,12 +99,14 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
case ':':
fprintf(stderr, "ERROR: missing argument\n");
+
/* Must manually reset optind if we are going to exit early */
optind = -1;
i8sak_cmd_error(i8sak); /* This exits for us */
case '?':
fprintf(stderr, "ERROR: unknown argument\n");
+
/* Must manually reset optind if we are going to exit early */
optind = -1;
@@ -170,7 +173,8 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
#ifdef CONFIG_NET_6LOWPAN
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)
{
@@ -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)
{
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)
{
@@ -264,7 +269,8 @@ void i8sak_get_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
}
else
{
- fprintf(stderr, "ERROR: unsupported parameter: %s\n", argv[argind]);
+ fprintf(stderr,
+ "ERROR: unsupported parameter: %s\n", argv[argind]);
}
}
#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);
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);
}
@@ -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)
{
- sixlowpan_getcoordeaddr(fd, i8sak->ifname, u.attr.mac.coordeaddr);
+ sixlowpan_getcoordeaddr(fd, i8sak->ifname,
+ u.attr.mac.coordeaddr);
printf("i8sak: Coordinator Extended Address: "
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)
{
- sixlowpan_getmaxretries(fd, i8sak->ifname, &u.attr.mac.max_retries);
- printf("i8sak: Max Retries: %d\n", (int)u.attr.mac.max_retries);
+ sixlowpan_getmaxretries(fd, i8sak->ifname,
+ &u.attr.mac.max_retries);
+ printf("i8sak: Max Retries: %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);
+ sixlowpan_getpromisc(fd, i8sak->ifname,
+ &u.attr.mac.promisc_mode);
if (u.attr.mac.promisc_mode)
{
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
{
- fprintf(stderr, "ERROR: unsupported parameter: %s\n", argv[argind]);
+ fprintf(stderr, "ERROR: unsupported parameter: %s\n",
+ argv[argind]);
}
}
#endif
diff --git a/wireless/ieee802154/i8sak/i8sak_regdump.c b/wireless/ieee802154/i8sak/i8sak_regdump.c
index f26dc9d..74ab2cd 100644
--- a/wireless/ieee802154/i8sak/i8sak_regdump.c
+++ b/wireless/ieee802154/i8sak/i8sak_regdump.c
@@ -18,7 +18,7 @@
*
****************************************************************************/
- /****************************************************************************
+/****************************************************************************
* Included Files
****************************************************************************/
@@ -62,6 +62,7 @@ void i8sak_regdump_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
"Usage: %s [-h]\n"
" -h = this help menu\n"
, argv[0]);
+
/* Must manually reset optind if we are going to exit early */
optind = -1;
@@ -69,12 +70,14 @@ void i8sak_regdump_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
case ':':
fprintf(stderr, "ERROR: missing argument\n");
+
/* Must manually reset optind if we are going to exit early */
optind = -1;
i8sak_cmd_error(i8sak); /* This exits for us */
case '?':
fprintf(stderr, "ERROR: unknown argument\n");
+
/* Must manually reset optind if we are going to exit early */
optind = -1;
@@ -93,6 +96,7 @@ void i8sak_regdump_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
i8sak->ifname, errno);
i8sak_cmd_error(i8sak);
}
+
ieee802154_get_req(fd, &req);
}
#ifdef CONFIG_NET_6LOWPAN
diff --git a/wireless/ieee802154/i8sak/i8sak_reset.c b/wireless/ieee802154/i8sak/i8sak_reset.c
index 4132634..7a26a92 100644
--- a/wireless/ieee802154/i8sak/i8sak_reset.c
+++ b/wireless/ieee802154/i8sak/i8sak_reset.c
@@ -18,7 +18,7 @@
*
****************************************************************************/
- /****************************************************************************
+/****************************************************************************
* Included Files
****************************************************************************/
@@ -61,6 +61,7 @@ void i8sak_reset_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
"Usage: %s [-h]\n"
" -h = this help menu\n"
, argv[0]);
+
/* Must manually reset optind if we are going to exit early */
optind = -1;
@@ -68,12 +69,14 @@ void i8sak_reset_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
case ':':
fprintf(stderr, "ERROR: missing argument\n");
+
/* Must manually reset optind if we are going to exit early */
optind = -1;
i8sak_cmd_error(i8sak); /* This exits for us */
case '?':
fprintf(stderr, "ERROR: unknown argument\n");
+
/* Must manually reset optind if we are going to exit early */
optind = -1;
diff --git a/wireless/ieee802154/i8sak/i8sak_set.c b/wireless/ieee802154/i8sak/i8sak_set.c
index 55ce7fd..fc58a73 100644
--- a/wireless/ieee802154/i8sak/i8sak_set.c
+++ b/wireless/ieee802154/i8sak/i8sak_set.c
@@ -18,7 +18,7 @@
*
****************************************************************************/
- /****************************************************************************
+/****************************************************************************
* Included Files
****************************************************************************/
@@ -72,24 +72,28 @@ void i8sak_set_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
{
case 'h':
fprintf(stderr, "Sets various parameters and attributes\n"
- "Usage: %s [-h] parameter\n"
- " -h = this help menu\n"
- "\n"
- "Parameters:\n"
- " chan 0-255 = RF channel (only some channels valid per radio)\n"
- " panid xx:xx = PAN Identifier\n"
- " saddr xx:xx = this node's short address\n"
- " eaddr xx:xx:xx:xx:xx:xx:xx:xx = this node's extended address\n"
- " addrmode s|e = source addressing mode\n"
- " ep_saddr xx:xx = i8sak endpoint short address\n"
- " ep_eaddr xx:xx:xx:xx:xx:xx:xx:xx = i8sak endpoint extended address\n"
- " ep_addrmode s|e = destination addressing mode\n"
- " 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]);
+ "Usage: %s [-h] parameter\n"
+ " -h = this help menu\n"
+ "\n"
+ "Parameters:\n"
+ " chan 0-255 = RF channel "
+ "(only some channels valid per radio)\n"
+ " panid xx:xx = PAN Identifier\n"
+ " saddr xx:xx = this node's short address\n"
+ " eaddr xx:xx:xx:xx:xx:xx:xx:xx = this node's "
+ "extended address\n"
+ " addrmode s|e = source addressing mode\n"
+ " ep_saddr xx:xx = i8sak endpoint short address\n"
+ " ep_eaddr xx:xx:xx:xx:xx:xx:xx:xx = i8sak "
+ "endpoint extended address\n"
+ " ep_addrmode s|e = destination addressing mode\n"
+ " 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 */
optind = -1;
@@ -97,12 +101,14 @@ void i8sak_set_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
case ':':
fprintf(stderr, "ERROR: missing argument\n");
+
/* Must manually reset optind if we are going to exit early */
optind = -1;
i8sak_cmd_error(i8sak); /* This exits for us */
case '?':
fprintf(stderr, "ERROR: unknown argument\n");
+
/* Must manually reset optind if we are going to exit early */
optind = -1;
@@ -183,7 +189,8 @@ void i8sak_set_cmd(FAR struct i8sak_s *i8sak, int argc, FAR char *argv[])
#ifdef CONFIG_NET_6LOWPAN
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
@@ -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)
{
- ieee802154_setmaxretries(fd, i8sak_str2luint8(argv[argind + 1]));
+ ieee802154_setmaxretries(fd,
+ i8sak_str2luint8(argv[argind + 1]));
}
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
{
- fprintf(stderr, "ERROR: unsupported parameter: %s\n", argv[argind]);
+ fprintf(stderr,
+ "ERROR: unsupported parameter: %s\n", argv[argind]);
}
}
#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);
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);
}
@@ -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)
{
- 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)
{
- 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)
{
- 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)
{
- sixlowpan_setpromisc(fd, i8sak->ifname, i8sak_str2bool(argv[argind + 1]));
+ sixlowpan_setpromisc(fd,
+ i8sak->ifname, i8sak_str2bool(argv[argind + 1]));
}
else
{
- fprintf(stderr, "ERROR: unsupported parameter: %s\n", argv[argind]);
+ fprintf(stderr,
+ "ERROR: unsupported parameter: %s\n", argv[argind]);
}
}
#endif
diff --git a/wireless/ieee802154/i8shark/i8shark_main.c b/wireless/ieee802154/i8shark/i8shark_main.c
index 3ec74d6..e03c87f 100644
--- a/wireless/ieee802154/i8shark/i8shark_main.c
+++ b/wireless/ieee802154/i8shark/i8shark_main.c
@@ -141,10 +141,10 @@ static int i8shark_init(FAR struct i8shark_state_s *i8shark)
* Name : i8shark_daemon
*
* Description :
- * This daemon reads all incoming IEEE 802.15.4 frames from a MAC802154 character
- * driver, packages the frames into a Wireshark Zigbee Encapsulate Protocol (ZEP)
- * packet and sends it over Ethernet to the specified host machine running
- * Wireshark.
+ * This daemon reads all incoming IEEE 802.15.4 frames from a MAC802154
+ * character driver, packages the frames into a Wireshark Zigbee
+ * Encapsulate Protocol (ZEP) packet and sends it over Ethernet to the
+ * 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);
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;
ret = errno;
return ret;
@@ -187,11 +189,12 @@ static int i8shark_daemon(int argc, FAR char *argv[])
return -1;
}
- /* We bind to the IP address of the outbound interface so that the OS knows
- * which interface to use to send the packet.
+ /* We bind to the IP address of the outbound interface so that
+ * 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_family = AF_INET;
addrlen = sizeof(struct sockaddr_in);
@@ -202,15 +205,17 @@ static int i8shark_daemon(int argc, FAR char *argv[])
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_port = HTONS(17754);
raddr.sin_addr.s_addr = HTONL(CONFIG_IEEE802154_I8SHARK_HOST_IPADDR);
/* Loop until the daemon is shutdown reading incoming IEEE 802.15.4 frames,
- * packing them into Wireshark "Zigbee Encapsulation Packets" (ZEP) and sending
- * them over UDP to Wireshark.
+ * packing them into Wireshark "Zigbee Encapsulation Packets" (ZEP)
+ * and sending them over UDP to Wireshark.
*/
while (!g_i8shark.daemon_shutdown)
@@ -251,8 +256,8 @@ static int i8shark_daemon(int argc, FAR char *argv[])
{
zepframe[i++] = 2;
- /* Not sure why, but the ZEP header allows for a 4-byte sequence no.
- * despite 802.15.4 sequence number only being 1-byte
+ /* Not sure why, but the ZEP header allows for a 4-byte sequence
+ * no. despite 802.15.4 sequence number only being 1-byte
*/
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 */
- zepframe[i++] = 0xFA;
- zepframe[i++] = 0xDE;
+ zepframe[i++] = 0xfa;
+ zepframe[i++] = 0xde;
- /* Not completely sure what LQI mode is. My best guess as of now based
- * on a few comments in the Wireshark code is that it determines whether
- * the last 2 bytes of the frame portion of the packet is the CRC or the
- * LQI. I believe it is CRC = 1, LQI = 0. We will assume the CRC is the
- * last few bytes as that is what the MAC layer expects. However, this
- * may be a bad assumption for certain radios.
+ /* Not completely sure what LQI mode is. My best guess as of now
+ * based on a few comments in the Wireshark code is that it
+ * determines whether the last 2 bytes of the frame portion of the
+ * packet is the CRC or the LQI.
+ * I believe it is CRC = 1, LQI = 0. We will assume the CRC is the
+ * last few bytes as that is what the MAC layer expects.
+ * However, this may be a bad assumption for certain radios.
*/
zepframe[i++] = 1;
@@ -285,20 +291,22 @@ static int i8shark_daemon(int argc, FAR char *argv[])
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();
memcpy(&zepframe[i], &systime, 8);
i += 8;
- /* Not sure why, but the ZEP header allows for a 4-byte sequence no.
- * despite 802.15.4 sequence number only being 1-byte
+ /* Not sure why, but the ZEP header allows for a 4-byte sequence
+ * no. despite 802.15.4 sequence number only being 1-byte
*/
zepframe[i] = frame.meta.dsn;
- zepframe[i+1] = 0;
- zepframe[i+2] = 0;
- zepframe[i+3] = 0;
+ zepframe[i + 1] = 0;
+ zepframe[i + 2] = 0;
+ zepframe[i + 3] = 0;
i += 4;
/* 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);
i += frame.offset;
- /* XBee radios use a 2 byte "application header" to support duplicate packet
- * detection. Wireshark doesn't know how to handle this data, so we provide
- * a configuration option that drops the first 2 bytes of the payload portion
- * of the frame for all sniffed frames
+ /* XBee radios use a 2 byte "application header" to support duplicate
+ * packet detection. Wireshark doesn't know how to handle this data,
+ * so we provide a configuration option that drops the first 2 bytes
+ * 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
- * and Wireshark will fail to disect the frame. Wireshark ignores a case
- * where the FCS is not included in the actual frame. Therefore, we
- * subtract 4 rather than 2 to remove the FCS field so that the disector
- * will not fail.
+ * NOTE:
+ * Since we remove data from the frame, the FCS is no longer valid
+ * and Wireshark will fail to disect the frame. Wireshark ignores a
+ * case where the FCS is not included in the actual frame. Therefore,
+ * 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),
@@ -341,11 +350,11 @@ static int i8shark_daemon(int argc, FAR char *argv[])
*/
#ifdef CONFIG_IEEE802154_I8SHARK_SUPPRESS_FCS
- {
+ {
uint8_t fcslen;
ieee802154_getfcslen(fd, &fcslen);
frame.length -= fcslen;
- }
+ }
#endif
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 */
- nbytes = sendto(sockfd, zepframe, i, 0, (struct sockaddr*)&raddr, addrlen);
+ nbytes = sendto(sockfd, zepframe, i, 0,
+ (struct sockaddr *)&raddr, addrlen);
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 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)
{
@@ -394,7 +407,9 @@ int main(int argc, FAR char *argv[])
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)
{
@@ -414,14 +429,14 @@ int main(int argc, FAR char *argv[])
/* If the daemon is not running, start it. */
g_i8shark.daemon_pid = task_create("i8shark",
- CONFIG_IEEE802154_I8SHARK_DAEMON_PRIORITY,
- CONFIG_IEEE802154_I8SHARK_DAEMON_STACKSIZE,
- i8shark_daemon, NULL);
+ CONFIG_IEEE802154_I8SHARK_DAEMON_PRIORITY,
+ CONFIG_IEEE802154_I8SHARK_DAEMON_STACKSIZE,
+ i8shark_daemon, NULL);
if (g_i8shark.daemon_pid < 0)
{
fprintf(stderr, "failed to start daemon\n");
return ERROR;
}
- return OK;
+ return OK;
}