This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How to read nrf sniffer 4.1.0 serial data in C?

I'm trying to work with Kismet's nrf51822 plugin that would allow kismet to read the nRF BLE sniffer 4.1.0 the same way Wireshark does.  Alas, theirs is C based and I don't seem to get the right data off my nRF51 DK reading its serial port in C the way the Wireshark plugin does.

Can I first validate I should be opening the /dev/ttyACM0 with 115200 N81 no flow control?  I'm basing that on the results

$ stty < /dev/ttyACM0
speed 115200 baud; line = 0;
intr = <undef>; quit = <undef>; erase = <undef>; kill = <undef>; eof = <undef>; start = <undef>; stop = <undef>; susp = <undef>; rprnt = <undef>; werase = <undef>; lnext = <undef>;
discard = <undef>; min = 0; time = 1;
-brkint -icrnl -imaxbel
-opost -onlcr
-isig -icanon -iexten -echo -echoe -echok -echoctl -echoke

  • Hi, 

    The speed should be 1M (1000000). 

    Flow control does not really matter since it is a virtual COM port. However, HW FC is on between the VCOM and the nRF COM. The argument provided to stty will not have any effect.

    Regards,
    Amanda

  • Thanks, Amanda, I'll give that a try. If it helps, this is the code in kismet that attempts to open /dev/ttyACM0 where my nRF attaches.  If there are any settings you know that should be on/off, please let me know?

    /* open for r/w but no tty */
    localnrf->fd = open(device, O_RDWR | O_NOCTTY);

    if (localnrf->fd < 0) {
        snprintf(msg, STATUS_MAX, "%s failed to open serial device - %s",
        localnrf->name, strerror(errno));
        return -1;
    }

     /* save current serial port settings */
    tcgetattr(localnrf->fd,&localnrf->oldtio);

    /* clear struct for new port settings */
    bzero(&localnrf->newtio,sizeof(localnrf->newtio)); 

    /* set the baud rate and flags */
    localnrf->newtio.c_cflag = localnrf->baudrate | CRTSCTS | CS8 | CLOCAL | CREAD;

    /* ignore parity errors */
    localnrf->newtio.c_iflag = IGNPAR;

    /* raw output */
    localnrf->newtio.c_oflag = 0;

    /* newtio.c_lflag = ICANON; */

    /* flush and set up */
    tcflush(localnrf->fd, TCIFLUSH);
    tcsetattr(localnrf->fd, TCSANOW, &localnrf->newtio);

    return 1;

  • Following up a bit, I managed to play with settings to get data across the line.  Though the serial read is still a bit wonky as I get varying buffer sizes (see below), it appears at least for the nRF51, you're using SLIP for packet coding?  The code looks for 0xAB (SLIP_START) and 0xBC (SLIP_END).  Is this correct?

    buf_rx_len = 4 0xBC 0xAB 0x2B 0x0
    buf_rx_len = 2 0x3 0xB6
    buf_rx_len = 1 0x23
    buf_rx_len = 3 0x2 0xA 0x1
    buf_rx_len = 2 0x26 0x54
    buf_rx_len = 3 0x0 0x0 0x39
    buf_rx_len = 2 0xCB 0x5
    buf_rx_len = 1 0xB
    buf_rx_len = 4 0xD6 0xBE 0x89 0x8E
    buf_rx_len = 1 0x0
    buf_rx_len = 4 0x17 0x0 0xCA 0x91
    buf_rx_len = 2 0x2F 0x85
    buf_rx_len = 1 0x4A
    buf_rx_len = 3 0x6C 0x2 0x1
    buf_rx_len = 3 0x1A 0x2 0xA
    buf_rx_len = 2 0xC 0xA
    buf_rx_len = 1 0xFF
    buf_rx_len = 3 0x4C 0x0 0x10
    buf_rx_len = 2 0x5 0xA
    buf_rx_len = 2 0x14 0x33
    buf_rx_len = 2 0x3C 0x76
    buf_rx_len = 3 0xF5 0x2B 0x92
    buf_rx_len = 1 0xBC
    buf_rx_len = 3 0xAB 0x2B 0x0

  • Hi, 

    In the 4.1.0 release in the doc folder there is a sniffer_uart_protocol.txt document that you can use.

    -Amanda
  • Yes, I found that last night.  Right now my main issue is that when I try to read the fd via:

    res = read(localnrf->fd, buf, 255);

    I get the buffers of random lengths listed above.  I've not been able to find a simple C example that properly manages it.  Wireshark uses your python interface.

Related