ST's mbed-os-example-wifi is broken due to incorrect IPv4 parsing inside mbed-OS

03 Apr 2018

SToR

1. Download, compile and run ST WiFi example: https://os.mbed.com/teams/ST/code/mbed-os-example-wifi/ 2. Observe result.

Expected

Example will work as required.

Actual

Example fails with error -3016.

Logs

Scan:
9 networks available.
Network: Network secured: WPA2 BSSID: ee:A6:ee:e7:e6:ee RSSI: -94 Ch: 0

###  ... more networks are displayed, but for clarity/security reason they are skipped ...  ###

Connecting to my_cool_ssid...
Success

MAC: C4:7A:5A:0A:2A:8A
IP: 192.168.0.100
Netmask: 255.255.255.0
Gateway: 192.168.0.1
RSSI: -70

Sending HTTP request to www.arm.com...
sent 37 [GET / HTTP/1.1]
Error receiving data: -3016

Done

Root cause

IPv4 address parsing in features/netsocket/SocketAddress.cpp ( ipv4_from_address() method ) is based on C99 sscanf modifier %hhu It is only present if newlib is compiled with _WANT_IO_C99_FORMATS switch. In case if it is missing, parsing is aborted and default IP (0.0.0.0) is used.

Proposed fix

Environment

$ uname -a
Linux Shakuras 4.15.13-1-ARCH #1 SMP PREEMPT Sun Mar 25 11:27:57 UTC 2018 x86_64 GNU/Linux

$ arm-none-eabi-gcc --version
arm-none-eabi-gcc (Arch Repository) 7.3.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
03 Apr 2018

For some strange reason, I cannot edit my own post. O_o

Here is a proposed fix:

https://github.com/ARMmbed/mbed-os/pull/6524