DietPi-Config | WiFi support for keys containing `"$

Created on 22 Sep 2018  ยท  32Comments  ยท  Source: MichaIng/DietPi

When I'm upgrading from 6.14 to 6.16 the wifi adapter stopped working .I can't scan for a network through the GUI and even after i manually insert the wireless SSID and PASSWORD stil doesnt resolve it and it gives me no ip ( 0.0.0.0.). If i put a static one doesn't seem to work too.
I tried 2 more times (clean install) from the image with wifi preconfigured in the dietpi.txt as also with ethernet. Worked everything in the clean install of the 6.14 but after the initial update to the 6.16 the wifi adapter breaks. Ethernet still working without a problem. Is there a method to remain to the 6.14 as i need to use the raspi wirelessly. I tried putting CONFIG_CHECK_DIETPI_UPDATES=0 but it still update my initial 6.14 version. Should i try put a fake adress on the APT mirrors ?Also can i try to put on DEV_GITBRANCH=testing on the dietpi.txt to see if the problem is resoved on the 6.17 ? Thanx for your constant work and help !

  • DietPi version 6.16
  • Distro version Stretch 9.4
  • Kernel version Linux DietPi 4.14.70-v7+ #1144 SMP Tue Sep 18 17:34:46 BST 2018 armv7l GNU/Linux
  • SBC device RPi 3 Model B (armv7l)

  • Power supply used 5V 2.5A

  • SDcard used Sansidk ultra 16gb class 10 a1

Additional Information (if applicable):

  • Was the software title installed freshly or updated/migrated? no additional software installed
  • Can this issue be replicated on a fresh installation of DietPi? yes
  • dietpi-bugreport ID 19f71c42-ac59-462a-85ff-27e8fab4d517

Steps to reproduce:

downlaod image from dietpi site flash it on the sd and then install normally

Expected behaviour:

Wireless should work

Actual behaviour:

it doesn't

img_20180920_143922

Bug Solution available

Most helpful comment

@Fourdee
Sadly I have no chance to test/debug WiFi here ๐Ÿ˜ž.

However my suggestions:

  • aWIFI_KEY[$i]="$( echo ${aWIFI_KEY[$i]} | sed 's/\\/\\\\\\/g' )"

    • Since sed interprets it's own magic chars again, better use ${aWIFI_KEY[$i]//\\/\\\\} to double backslashes etc.

  • Currently dietpi-wifi.db creation/applying happens in both, dietpi-config and dietpi-set_hardware. I see the need currently that dietpi-config needs to safe the data and dietpi-set_hardware wants to recreate it for sanity, especially on first run setup, when user uses dietpi-wifi.txt ๐Ÿค”. Anyway maybe we find a more elegant solution.

    • Actually since now the dietpi-wifi.db is effectively recreated two times, one time within dietpi-config and a second time within dietpi-set_hardware, this also doubles the need to backslash magic chars. We should really try to touch strings and file as less as possible. Maybe in this case it is best to create a separate script, e.g. dietpi-wifi[_creds/_setup] or something like that? Then open menu, when this is called without argument (from dietpi-config, Network > WiFi > dietpi-wifi), allow to simply apply existing dietpi-wifi.db via $1==1 and perhaps as separate 1st run option, allow to copy from dietpi-wifi.txt via $1=-1? This would reduce the need to read/write those settings just a single time.

  • for (( i=0; i<5; i++ )): Use for i in ${!aWIFI_SSID[@]} instead to not pre-generate all 5 arrays and safe dummy arrays to file? Also this allows theoretically unlimited SSIDs. Pre-generate a new array index when user chooses (new menu entry) to add a new one: new_index=$((${#aWIFI_SSID[@]}))

    • In case of removed SSIDs, better find first empty index: for (( i=0; i<=${#aWIFI_SSID[@]}; i++ )); do [[ ! ${aWIFI_SSID[$i]} ]] && new_index=${aWIFI_SSID[$i]}; pre-generate array etc...

All 32 comments

@sesshomaru86

Hi, thanks for the report ๐Ÿ‘

I'll try to replicate.

Confirmed bug with current image, redoing the image now (seems I missed this one in the update image ticket)

@sesshomaru86

Image updated which resolves WiFi issues, please re-download and write the following image:
https://dietpi.com/downloads/images/DietPi_RPi-ARMv6-Stretch.7z

NB: WiFi automation has changed in v6.16 images, please see below for info:
https://dietpi.com/phpbb/viewtopic.php?f=8&t=9#p9

Hmm..when i go to dietpi-config to change the network adapter settings im getting a message :

[FAILED] DietPi-Config | DEBUG: /var/lib/dietpi/dietpi-wifi.db does not exist, unable to continue. If you did not manually remove this file, please report this issue to DietPi.

It's a fresh install with the new image posted above without tinkering anything at all.

@sesshomaru86

Thanks for the report. I'll get that resolved and update the image.

EDIT:
In the mean time, please run the following to regen the file:

/DietPi/dietpi/func/dietpi-set_hardware wificreds set

Then re-run dietpi-config

@sesshomaru86

Image updated which applies the fix automatically for this issue:
https://github.com/Fourdee/DietPi/issues/2087#issuecomment-423836528

Image:
https://dietpi.com/downloads/images/DietPi_RPi-ARMv6-Stretch.7z

Completed.

[ SUB2 ] DietPi-Services > stop
[ OK ] DietPi-Services | stop : cron
[ SUB2 ] DietPi-Set_Hardware > wificreds (set)
[ OK ] wificreds set | Completed
[ SUB2 ] DietPi-Set_Hardware > wifimodules (enable)
[ OK ] DietPi-Set_Hardware | Checking for pre-req APT packages: crda firmware-atheros firmware-brcm80211 firmware-iwlwifi iw rfkill wireless-tools wpasupplicant firmware-misc-nonfree
[ INFO ] DietPi-Set_Hardware | Pre-req APT packages are installed
[ INFO ] DietPi-Set_Hardware | Please wait, enabling WiFi Modules...
[ OK ] wifimodules enable | Completed
[ INFO ] DietPi-Config | Dropping connections, please wait...
[ INFO ] DietPi-Config | Restarting network, please wait...
Internet Systems Consortium DHCP Client 4.3.5
Copyright 2004-2016 Internet Systems Consortium.
All rights reserved.
For info, please visit https://www.isc.org/software/dhcp/

Listening on LPF/eth0/(mac adress)
Sending on LPF/eth0/(mac adress)
Sending on Socket/fallback
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 4
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 4
DHCPDISCOVER on eth0 to 255.255.255.255 port 67 interval 3
DHCPREQUEST of 192.168.5.14 on eth0 to 255.255.255.255 port 67
DHCPOFFER of 192.168.5.14 from 192.168.5.1
DHCPACK of 192.168.5.14 from 192.168.5.1
bound to 192.168.5.14 -- renewal in 37647 seconds.
wpa_supplicant: /sbin/wpa_supplicant daemon failed to start
run-parts: /etc/network/if-pre-up.d/wpasupplicant exited with return code 1
ifup: failed to bring up wlan0
[ SUB2 ] DietPi-Services > start
[ OK ] DietPi-Services | start : cron
[ SUB3 ] DietPi-Process_tool > Apply
[ OK ] DietPi-Process_tool > OK
INFO DIETPICONFIG -RELOADING NETWORK DATA, PLEASE WAIT..

Still it doesnt give me an ip the wifi . The new image was flashed with 0 modifications . Tried from an ethernet connection to enable the wifi and one more time with puting in the txt file name and password of the ssid.

Selection_001

@sesshomaru86

ifup: failed to bring up wlan0

Ok appears to be an issue with bringing up adapter, is the onboard WiFi the only connected WiFi adapter?

Ideally, we need to check the system configuration at this state when the WiFi fails. Please can you ensure ethernet is connected, get the WiFi to fail as above, then send me a new bug report:

dietpi-bugreport

I can then check the logs etc, see where the issue is.

  • ๐Ÿˆฏ๏ธ Unable to replicate in local testing, fresh install then straight to dietpi-config to setup wifi
    image

Thanx for the reply ! In the raspberry pi 3 there's no adapter or anything else connected. Only the ethernet cable.

I just download a new image from the site to be sure im not messing with the images reflash it test it again as new without any modifications. same problem.

Bug report sent, reference code: 155689e2-5ada-4461-8d04-051cbfc8a627

@sesshomaru86

Thanks ๐Ÿ‘

Appears the WiFi chip is working fine:

[   97.698885] brcmfmac: brcmf_c_preinit_dcmds: Firmware version = wl0: Oct 23 2017 03:55:53 version 7.45.98.38 (r674442 CY) FWID 01-e58d219f
[   97.699539] brcmfmac: brcmf_c_preinit_dcmds: CLM version = API: 12.2 Data: 7.11.15 Compiler: 1.24.2 ClmImport: 1.24.1 Creation: 2014-05-26 10:53:55 Inc Data: 9.10.39 Inc Compiler: 1.29.4 Inc ClmImport: 1.36.3 Creation: 2017-10-23 03:47:14 
brcmfmac              307200  0
brcmutil               16384  1 brcmfmac
cfg80211              573440  1 brcmfmac
rfkill                 28672  2 cfg80211

Ok I believe the issue may be with the WiFi creds. I'll need to see these. I've updated the bugreport script to include them, please run the following commands to resend bug report:

 wget https://raw.githubusercontent.com/Fourdee/DietPi/testing/dietpi/dietpi-bugreport -O /DietPi/dietpi/dietpi-bugreport
dietpi-bugreport

Also, please can you confirm which WiFi encryption mode is setup on your router (eg: WPA-PSK)?

Tried again and this time when i pressed scan doesnt do anything so i put my credentials again manually.

I use a Unifi AP AC LR as acess point and the encryption is WPA2 -AES . Can it be that the wifi password includes these type of characters [ ` ?

Tried with the above command

dietpi-bugreport
[ OK ] DietPi-Bugreport | Root access verified.
[ OK ] DietPi-Bugreport | RootFS R/W access verified.

[ INFO ] DietPi-Bugreport | Packing upload archive, please wait...
[ .... ] DietPi-Bugreport | (1/5) Testing connection to ssh.dietpi.com, please w[ OK ] DietPi-Bugreport | Connection test: ssh.dietpi.com
stat: cannot stat '155689e2-5ada-4461-8d04-051cbfc8a627.7z': No such file or directory
/DietPi/dietpi/dietpi-bugreport: line 155: ((: <= 10000000 : syntax error: operand expected (error token is "<= 10000000 ")
[FAILED] DietPi-Bugreport | The bug report upload archive appears to be unexpected large. Please inspect and in case clean up the locations to be uploaded, as their size should never be that large:
CMD_OUT.txt
G_ERROR_HANDLER_GITREPORT
/var/log/*
/DietPi/*
/boot/dietpi.txt
/boot/config.txt
/boot/dietpi/*
/tmp/.G*
/var/tmp/dietpi/logs/*
/var/lib/dietpi/*
/etc/bash.bashrc
/etc/bashrc.d/*
/root/.bashrc
/home//.bashrc
/etc/profile
/etc/profile.d/

/root/.profile
/home//.profile
/etc/rc.local
/etc/X11/xorg.conf
/etc/asound.conf
/etc/network/interfaces
/etc/wpa_supplicant/wpa_supplicant.conf
/var/lib/dietpi/dietpi-wifi.db
/etc/fstab
/etc/sysctl.conf
/etc/sysctl.d/

/etc/init.d/*
/etc/systemd/system/*
/lib/systemd/system/*
/etc/apt/sources.list
/etc/apt/sources.list.d/*

Tried just now with a hotspot from my phone and it works so it must be a problem with my router or my password. I'm sorry i didn't tested before.

The selection of the network / Scan automatically is bugged and doesnt work anymore.
Tried again with a hotspot having the same password -!Jjtp4Vui/y[ and it doesn't connect so definitely is the characters of the password . Its a random generated pass with keepassxc.

@sesshomaru86

includes these type of characters [ ` ?

Yep, I believe is the issue, try escaping the single quote character when adding in the key:
https://pastebin.com/YC6yZtY2

It worked ! Thanx a lot !

@sesshomaru86

Excellent ๐Ÿ‘ i'll add some more info when entering WiFi keys, to mention backslash required for those chars.

Theoretically we could also add those backslashes via ${value//[/\[} but maybe this confuses more than it helps?

@MichaIng

Theoretically we could also add those backslashes via ${value/[/[} but maybe this confuses more than it helps?

๐Ÿ‘ Should be fine as long as we mention that backslashes will automatically be added for the required chars?


Hmm, returned value seems fine:

root@DietPi:~# G_USER_INPUTS=1 G_WHIP_INPUTBOX
root@DietPi:~# echo -e "$G_WHIP_RETURNED_VALUE"
123`\[]342-?

Issue with saving wifi.db:

root@DietPi:~# cat /var/lib/dietpi/dietpi-wifi.db
#---------------------------------------------------------------
# - Entry 0
#       WiFi SSID (Case Sensitive)
aWIFI_SSID[0]="FuzonWifi"
#       Key options: If no key (open), leave this blank
aWIFI_KEY[0]=""

echo -e vs cat:
both sets correct wifi.db, but importing it again fails, we still need to adjust it during save.

[ SUB1 ] DietPi-Set_Hardware > wificreds (set)
/var/lib/dietpi/dietpi-wifi.db: line 6: unexpected EOF while looking for matching ``'
/var/lib/dietpi/dietpi-wifi.db: line 96: syntax error: unexpected end of file

Nope, not keen on this, means adding potentially more issues once modified.

For now, we'll simply add the required.

image

Completed.

Just for the reference . I tried another new install but i couldn't connect it to the wifi again . Moreover every time i was pasting the password automatically was closing the field with the password. At the end it couldn't connect even to a hotspot with no password at all. I proceed with the installation through ethernet , i rebooted and that time got everything flawlessly.

P.S. and now it bugged when i tried to change the country code to AT . It cannot go back to GB and wifi again doesn't work.

P.S.2 I think i found the problem . I continue troubleshoot try to connect to the wifi but this time didn't connect , i disabled the adapter re-enable nothing again. I noticed that sometimes when i write or paste the password and click back its not the whole pass inside the blue box (in the beginning i thought that it just cant visualize all the characters ) but its not like that it just cut the password and there are characters missing! Maybe something to do with the .db . Anyway it's something that provokes a weird behavior for sure.

(reproducing steps : Put a password in the pass tab of the ssid and then exit back to the menu with all the networking options , re enter again in the wifi adapter select network and the password is only half)

@sesshomaru86

reproducing steps : Put a password in the pass tab of the ssid and then exit back to the menu with all the networking options , re enter again in the wifi adapter select network and the password is only half

Many thanks, i'll reopen for testing ๐Ÿ‘

Testing with key:

`\$\"'

  • Appears fine in menu, and returning to menu
  • Apply, then recheck key, key missing.

Ok, its due to init array from file.

aWIFI_KEY[0]="`$"'"

aWIFI_KEY[0]=`$"'test
                    # - Add required escapes for bash related items
                    #   \"`$
                    sed -i 's/\\/\\\\/g' /var/lib/dietpi/dietpi-wifi.db
                    sed -i 's/\"/\\"/g' /var/lib/dietpi/dietpi-wifi.db
                    sed -i 's/`/\\`/g' /var/lib/dietpi/dietpi-wifi.db
                    sed -i 's/\$/\\$/g' /var/lib/dietpi/dietpi-wifi.db

                    cat /var/lib/dietpi/dietpi-wifi.db | grep 'aWIFI_KEY\[0\]'
 DietPi-Set_Hardware
โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
 Mode: wificreds (set)

aWIFI_KEY[0]=\`\$\"'test
/var/lib/dietpi/dietpi-wifi.db: line 6: unexpected EOF while looking for matching `''
/var/lib/dietpi/dietpi-wifi.db: line 96: syntax error: unexpected end of file
[  OK  ] wificreds set | Completed

Before:
image

After network apply:
image

๐Ÿˆฏ๏ธ aWIFI_KEY[$i]=$( echo ${aWIFI_KEY[$i]} | sed 's/\\/\\\\\\/g' )

With 3 backslashes for 1 being the magic item, when sourcing a file into a variable.

aWIFI_KEY[0]=test\\\`test\\\"test\\\$test

Users will still need to add the escapes manually, but after saving file and re-sourcing, its resolved.


wpa_supplicant.conf needs testing.

 psk="test\`test\"test\$test"

Ok testing:

  • WiFi key in router = testtest`"$1
  • Entered key = testtest\`\"\$1
  • ๐Ÿˆฏ๏ธ Key saved correctly after applying and reloading.
  • ๐Ÿˆด Does not connect
  • ๐Ÿˆฏ๏ธ wpa_supplicant.conf, appears fine, as it should be
network={
        ssid="XXXXXXXXXXXX"
        scan_ssid=1
        key_mgmt=WPA-PSK
        psk="testtest\`\"\$1"
}
  • ๐Ÿˆด Also tried with wifi hotspot on smartphone, does not connect.

@Fourdee
Sadly I have no chance to test/debug WiFi here ๐Ÿ˜ž.

However my suggestions:

  • aWIFI_KEY[$i]="$( echo ${aWIFI_KEY[$i]} | sed 's/\\/\\\\\\/g' )"

    • Since sed interprets it's own magic chars again, better use ${aWIFI_KEY[$i]//\\/\\\\} to double backslashes etc.

  • Currently dietpi-wifi.db creation/applying happens in both, dietpi-config and dietpi-set_hardware. I see the need currently that dietpi-config needs to safe the data and dietpi-set_hardware wants to recreate it for sanity, especially on first run setup, when user uses dietpi-wifi.txt ๐Ÿค”. Anyway maybe we find a more elegant solution.

    • Actually since now the dietpi-wifi.db is effectively recreated two times, one time within dietpi-config and a second time within dietpi-set_hardware, this also doubles the need to backslash magic chars. We should really try to touch strings and file as less as possible. Maybe in this case it is best to create a separate script, e.g. dietpi-wifi[_creds/_setup] or something like that? Then open menu, when this is called without argument (from dietpi-config, Network > WiFi > dietpi-wifi), allow to simply apply existing dietpi-wifi.db via $1==1 and perhaps as separate 1st run option, allow to copy from dietpi-wifi.txt via $1=-1? This would reduce the need to read/write those settings just a single time.

  • for (( i=0; i<5; i++ )): Use for i in ${!aWIFI_SSID[@]} instead to not pre-generate all 5 arrays and safe dummy arrays to file? Also this allows theoretically unlimited SSIDs. Pre-generate a new array index when user chooses (new menu entry) to add a new one: new_index=$((${#aWIFI_SSID[@]}))

    • In case of removed SSIDs, better find first empty index: for (( i=0; i<=${#aWIFI_SSID[@]}; i++ )); do [[ ! ${aWIFI_SSID[$i]} ]] && new_index=${aWIFI_SSID[$i]}; pre-generate array etc...

Did further enhancements about this: https://github.com/Fourdee/DietPi/pull/2193

  • No manual escaping required any more. Testing on Jessie would be great, just to verify that Jessie wpa_supplicant parses the config file identically.

Test:

  • ๐Ÿˆฏ๏ธ "$moocow

@MichaIng

Legend, works a charm ๐Ÿ‘

I am so confused about how to put the correct wifi key.. why should we need to type so weird character ? if my wifikey is "wakanda" how should i type ?

@panjisn
If your password is "wakanda", so does not include any special characters, there shouldn't be any issues.

If your password contains one of $ ` " \ , then on current v6.17 your need to escape those via backslashes, e.g. "w$k\nd"" should be "w\$k\\nd\"" then, to have the password correctly stored and assigned to wpa_supplicant.

With v6.18 we changed the way the pw string is stored (from double quotes " to single quotes '), which allows more special characters, and do the remaining escaping script internally. So no manual escaping is required any more.

We can actually mark this as completed. Testing passed, no need to escape chars in v6.18.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

and09 picture and09  ยท  3Comments

Fourdee picture Fourdee  ยท  3Comments

aesirteam picture aesirteam  ยท  3Comments

Fourdee picture Fourdee  ยท  3Comments

mok-liee picture mok-liee  ยท  3Comments