only sniff uses promisc mode, beacon scan does not.

This commit is contained in:
Sebastien Lorquet 2015-08-10 14:37:01 +02:00
parent a867dfb3bb
commit 2b4fa91f37

View File

@ -61,6 +61,7 @@
#include <nuttx/fs/ioctl.h> #include <nuttx/fs/ioctl.h>
#include <nuttx/ieee802154/ieee802154.h> #include <nuttx/ieee802154/ieee802154.h>
#include <nuttx/ieee802154/ieee802154_dev.h> #include <nuttx/ieee802154/ieee802154_dev.h>
#include <apps/ieee802154/ieee802154.h>
/**************************************************************************** /****************************************************************************
* Definitions * Definitions
@ -258,12 +259,33 @@ static int status(int fd)
static int display(FAR struct ieee802154_packet_s *pack) static int display(FAR struct ieee802154_packet_s *pack)
{ {
int i; int i;
printf("len=%3u rssi=%3u lqi=%3u [", pack->len, pack->rssi, pack->lqi); int hlen=0;
for (i = 0; i < pack->len; i++) char buf[IEEE802154_ADDRSTRLEN+1];
struct ieee802154_addr_s dest,src;
printf("rssi=%3u lqi=%3u ", pack->rssi, pack->lqi);
hlen = ieee802154_addrparse(pack, &dest, &src);
if(hlen<0)
{ {
printf("%02X", pack->data[i]); printf("invalid header \n");
hlen = 0;
} }
printf("]\n"); else
{
ieee802154_addrtostr(buf,sizeof(buf),&src);
printf("[%s -> ", buf);
ieee802154_addrtostr(buf,sizeof(buf),&dest);
printf("%s] ", buf);
}
printf("len=%d ", pack->len - hlen);
for (i = 0; i < pack->len - hlen; i++)
{
printf("%02X", pack->data[i+hlen]);
}
printf("\n");
return 0; return 0;
} }
@ -284,13 +306,6 @@ static void* sniff(void *arg)
struct sniffargs *sa = (struct sniffargs*)arg; struct sniffargs *sa = (struct sniffargs*)arg;
int fd = sa->fd; int fd = sa->fd;
ret = ioctl(fd, MAC854IOCSPROMISC, TRUE);
if (ret<0)
{
printf("Device is not an IEEE 802.15.4 interface!\n");
return (void*)ret;
}
printf("Listening...\n"); printf("Listening...\n");
while (1) while (1)
{ {
@ -317,12 +332,6 @@ static void* sniff(void *arg)
display(&gRxPacket); display(&gRxPacket);
} }
ret = ioctl(fd, MAC854IOCSPROMISC, FALSE);
if (ret<0)
{
printf("Device is not an IEEE 802.15.4 interface!\n");
return (void*)ret;
}
return (void*)ret; return (void*)ret;
} }
@ -473,8 +482,24 @@ int i8_main(int argc, char *argv[])
else if (!strcmp(argv[2], "snif")) else if (!strcmp(argv[2], "snif"))
{ {
struct sniffargs args; struct sniffargs args;
ret = ioctl(fd, MAC854IOCSPROMISC, TRUE);
if (ret<0)
{
printf("Device is not an IEEE 802.15.4 interface!\n");
return (void*)ret;
}
args.fd = fd; args.fd = fd;
ret = (int)sniff(&args); ret = (int)sniff(&args);
ret = ioctl(fd, MAC854IOCSPROMISC, FALSE);
if (ret<0)
{
printf("Device is not an IEEE 802.15.4 interface!\n");
return (void*)ret;
}
} }
else if (!strcmp(argv[2], "tx")) else if (!strcmp(argv[2], "tx"))
{ {