rosvall / cc2531_linux

Linux kernel driver for CC2531 WPAN Adapter firmware
http://rosvall.github.io/
1 stars 1 forks source link

Ping does not work #1

Closed ekawahyu closed 8 months ago

ekawahyu commented 8 months ago

I installed this driver, did the modprobe, brought up the interface with proper IPv6 address, but ping does not seem to work. Any idea how I can debug this?

My current setup: One PC with Rhino Linux, kernel 6.6.7 One PC with Ubuntu 22.04 LTS, kernel 6.4.0

I saw the LED blink at least when I send the ping, but that's all I could see.

rosvall commented 8 months ago

First check that you've correctly set up the IEEE802.15.4 and 6lowpan interfaces on both ends.

I do something like:

CHAN=25
PAN=0x1234
ADDR=0x0001    # <- Use a unique address for each device.
DEV=wpan0
PHY=`cat /sys/class/net/$DEV/device/name`
ip link set $DEV down
iwpan phy $PHY set channel 0 $CHAN
iwpan phy $PHY set cca_ed_level -80
iwpan phy $PHY set tx_power -20
iwpan dev $DEV set short_addr $ADDR
iwpan dev $DEV set pan_id $PAN
iwpan dev $DEV set ackreq_default 1
iwpan dev $DEV set max_frame_retries 6
iwpan dev $DEV set backoff_exponents 1 4
iwpan dev $DEV set max_csma_backoffs 16
ip link add link $DEV name lo$DEV type lowpan
ip link set $DEV up
ip link set lo$DEV up

Then you should be able to ping with

ping ff02::1%lowpan0

Wireshark is great for debugging both USB and IEEE802.15.4. And if you have some sort of 3.3V TTL UART adapter that can handle 2Mbaud, you can connect that to the P6.1 pin on the CC2531 to see the debug output.

ekawahyu commented 8 months ago

I believe I did configure it properly. I also followed the exact same values you gave but nothing works. Not sure if the firmware was built correctly though. But as far as I can see from the LEDs, there seemed to be activities while doing the ping test.

I own ATUSB, so I can try for sniff the packet with it. In the meantime, here is the configuration that seems successful to receive the ping packet but with CRC error:

ip link set wpan0 down
iwpan dev wpan0 set pan_id 0xbeef
ip link add link wpan0 name lowpan0 type lowpan
ip link set wpan0 up
ip link set lowpan0 up
ip addr add 2001:db8::1/64 dev lowpan0

Notice that I also added IPv6 address, ::1 on one node and ::20 for the other. And here is what I got on the receiving node:

[ 8516.285587] usb 3-3: new full-speed USB device number 5 using xhci_hcd
[ 8516.458402] usb 3-3: New USB device found, idVendor=1608, idProduct=154f, bcdDevice= 0.02
[ 8516.458407] usb 3-3: New USB device strings: Mfr=2, Product=3, SerialNumber=1
[ 8516.458408] usb 3-3: Product: CC2531 USB WPAN Adapter
[ 8516.458409] usb 3-3: Manufacturer: Andreas Rosvall
[ 8516.458410] usb 3-3: SerialNumber: 00124B000FD5BDBA
[ 8516.461669] cc2531 3-3:1.0: read permanent extended address: 00124b000fd5bdba
[ 8516.464660] cc2531 3-3:1.0: CC2531 firmware version: 0.2-next-08e13ad-20230703-dirty
[ 8732.924393] cc2531 3-3:1.0: Received pkt with invalid crc
[ 8732.924600] pkt: 41 c8 74 ef be ff ff 47 0e 6f 01 00 4b 12 00 7b
[ 8732.924656] pkt: 09 3a 20 01 0d b8 00 00 00 00 00 00 00 00 00 00
[ 8732.924701] pkt: 00 01 02 01 ff 00 00 20 87 00 c3 1a 00 00 00 00
[ 8732.924746] pkt: 20 01 0d b8 20 00 00 00 00 00 00 00 00 00 00 20
[ 8732.924791] pkt: 01 02 00 12 4b 00 01 6f 0e 47 00 00 00 00 00 00
[ 8732.924835] pkt: e4 6a
[ 8737.019170] cc2531 3-3:1.0: Received pkt with invalid crc
[ 8737.019409] pkt: 41 c8 79 ef be ff ff 47 0e 6f 01 00 4b 12 00 7b
[ 8737.019439] pkt: 09 3a 20 c1 0a b8 00 20 00 00 00 00 00 00 00 00
[ 8737.019487] pkt: 00 01 02 01 ff 00 00 20 87 00 c3 1a 70 00 02 00
[ 8737.019514] pkt: 20 01 0d b8 00 00 00 00 00 00 00 c0 00 00 00 d0
[ 8737.019547] pkt: 01 02 00 12 4b 00 01 6f 0e 47 00 00 00 00 00 00
[ 8737.019573] pkt: e3 6a
[ 8758.427699] cc2531 3-3:1.0: Received pkt with invalid crc
[ 8758.427942] pkt: 41 c8 80 ef be ff ff 43 0e 6f 01 00 4b 12 00 7b
[ 8758.427996] pkt: 09 3a 20 01 0d b8 00 00 00 00 00 00 00 00 00 00
[ 8758.428042] pkt: 00 01 02 01 ff 00 00 20 87 00 c3 1a 00 00 00 00
[ 8758.428087] pkt: 20 01 0d b8 00 00 00 00 00 00 00 00 00 00 00 20
[ 8758.428132] pkt: 01 04 00 12 4b 00 01 6f 0e 47 00 00 00 00 00 00
[ 8758.428178] pkt: e4 4d

Device info:

debian@debian:~$ iwpan dev
phy#2
    Interface wpan0
        ifindex 7
        wpan_dev 0x200000001
        extended_addr 0x00124b000fd5bdba
        short_addr 0xffff
        pan_id 0xbeef
        type node
        max_frame_retries 3
        min_be 3
        max_be 5
        max_csma_backoffs 4
        lbt 0
        ackreq_default 0

debian@debian:~$ iwpan phy
wpan_phy phy2
supported channels:
    page 0: 11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31 
current_page: 0
current_channel: 11,  2405 MHz
cca_mode: (3, cca_opt: 0) Carrier sense with energy above threshold (logical operator is 'and')
cca_ed_level: -84
tx_power: 4.5
capabilities:
    iftypes: node,monitor,coordinator 
    channels:
        page 0: 
            [11]  2405 MHz, [12]  2410 MHz, [13]  2415 MHz, 
            [14]  2420 MHz, [15]  2425 MHz, [16]  2430 MHz, 
            [17]  2435 MHz, [18]  2440 MHz, [19]  2445 MHz, 
            [20]  2450 MHz, [21]  2455 MHz, [22]  2460 MHz, 
            [23]  2465 MHz, [24]  2470 MHz, [25]  2475 MHz, 
            [26]  2480 MHz, [27]  2485 MHz, [28]  2490 MHz, 
            [29]  2495 MHz, [30]  2500 MHz, [31]  2505 MHz  
    tx_powers: 
            -22 dBm, -20 dBm, -18 dBm, -16 dBm, -14 dBm, -12 dBm, 
            -10 dBm, -8 dBm, -6 dBm, -4 dBm, -3 dBm, -1.5 dBm, 
            -0.5 dBm, 1 dBm, 2.5 dBm, 4.5 dBm, 
    cca_ed_levels: 
            -100 dBm, -99 dBm, -98 dBm, -97 dBm, -96 dBm, -95 dBm, 
            -94 dBm, -93 dBm, -92 dBm, -91 dBm, -90 dBm, -89 dBm, 
            -88 dBm, -87 dBm, -86 dBm, -85 dBm, -84 dBm, -83 dBm, 
            -82 dBm, -81 dBm, -80 dBm, -79 dBm, -78 dBm, -77 dBm, 
            -76 dBm, -75 dBm, -74 dBm, -73 dBm, -72 dBm, -71 dBm, 
            -70 dBm, -69 dBm, -68 dBm, -67 dBm, -66 dBm, -65 dBm, 
            -64 dBm, -63 dBm, -62 dBm, -61 dBm, -60 dBm, -59 dBm, 
            -58 dBm, -57 dBm, -56 dBm, -55 dBm, -54 dBm, -53 dBm, 
            -52 dBm, -51 dBm, -50 dBm, -49 dBm, -48 dBm, -47 dBm, 
            -46 dBm, -45 dBm, -44 dBm, -43 dBm, -42 dBm, -41 dBm, 
            -40 dBm, 
    cca_modes: 
        (1) Energy above threshold
        (2) Carrier sense only
        (3, cca_opt: 0) Carrier sense with energy above threshold (logical operator is 'and')
        (4) ALOHA
    min_be: 0,1,2,3,4,5,6,7 
    max_be: 0,1,2,3,4,5,6,7 
    csma_backoffs: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32 
    frame_retries: 0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31,32 
    lbt: true
ekawahyu commented 8 months ago

Btw, just wanted to rule out the kernel version, what is the exact kernel version you tested it with? I can try to build the kernel from source and give it a try.

rosvall commented 8 months ago

I doubt it's the Linux kernel version. I used to develop it on the regular Arch Linux kernel (sometime around 6.5 i think), and now i'm running on a couple of days old master branch from torvalds/linux. But i haven't tested this kernel module on anything other than x86_64!

I forgot to say that you can enable additional debugging kernel log messages with

echo "module cc2531 +p" > /sys/kernel/debug/dynamic_debug/control

I suspect it's one of two things: 1) Device configuration. You're receiving something - that's good! And receiving some percentage with CRC errors is also normal. Maybe we can bring that percentage down from 100 with a bit of tweaking. 2) SDCC. The 8051 backend is terrible, and you're obviously building the firmware with a different version (mine didn't insist on prototypes). I'd like to test your wpan_fw.dfu binary.

rosvall commented 8 months ago

If you want, you can try the firmware i've built with SDCC 4.3.0 #14184. wpan_fw.dfu.gz

Flash to device with

gunzip wpan_fw.dfu.gz
dfu-util -D wpan_fw.dfu -R

If that works, and your firmware doesn't it's definitely SDCC.

ekawahyu commented 8 months ago

Oh man, this turns out to be a hardware issue. Even after configuring TX power to 4.5dBm, the wireless coverage does not even go beyond 3 feet! I got this USB dongle from Amazon, I would NOT recommend anyone to get this.

Just for fun, I attach my firmware built in case you want to check it out: wpan_fw.dfu.zip

I am getting another USB dongle from EByte, will let you know how it goes. Feel free to close this ticket. I am pretty sure the firmware I built would work on your end.

rosvall commented 8 months ago

Yes, from a quick test it looks like your firmware works pretty much the same as mine.

Those $5 Amazon modules are probably not the best quality, but, uh, the same could probably be said of my CSMA implementation, etc. It's not like it's seen a lot of testing.

I still think you should try tuning the phy/dev parameters with iwpan and see if that doesn't help a bit. Try a less crowded channel, raise the number of retries, etc.

ekawahyu commented 8 months ago

Out of my curiosity, what is the range you get (line of sight) on TX power set to -22dBm? In my case, I had to keep both PCB antenna within 1 cm to get the ping to work. Either these dongle were a reject, or did not pass QA at all. I had CC2531EMK before and I know it worked a lot longer than 1cm coverage.

I tried all channels with no luck on these hardware, and the CCA mode. I do see differences when changing TX power from the lowest to the highest, so I know that those configuration were taken.

rosvall commented 8 months ago

At -22dBm i get at least a couple of meters with line of sight, so 1cm does indeed sound like there's a problem.

rosvall commented 8 months ago

You could try to throw the ATUSB in the mix, to see if it's just one CC2531 board that's borked, or both are deaf and/or dumb.

rosvall commented 8 months ago

I'm closing this issue for now. Please open a new one, if you still have range issues with the new hardware.

ekawahyu commented 8 months ago

@rosvall FYI, the USB dongles from EByte work a lot better in term of coverage. Glad to finally make this to work. Thanks.

rosvall commented 8 months ago

I'm glad you got it working :)