WelcomeWelcome | FAQFAQ | DownloadsDownloads | WikiWiki

Author Topic: Help with piCore15 and wifi.sh  (Read 1314 times)

Offline timbee

  • Newbie
  • *
  • Posts: 4
Help with piCore15 and wifi.sh
« on: August 19, 2024, 12:01:27 PM »
I had it all working under piCore 14 but I can't get wifi.sh to work on piCore 15, this is on a Pi 3B+

onboot.lst has the following
Quote
openssh.tcz
firmware-rpi-wifi.tcz
firmware-brcmwifi.tcz
wifi.tcz

When I run sudo wifi.sh it list the available SSIDs but once one selected it does not prompt for the password but gives this error messsage instead, obviousy it then fails to connect.
Quote
tcgetattr: Inappropriate ioctl for device

Any thoughts on what I am doing wrong?
Thanks

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1270
Re: Help with piCore15 and wifi.sh
« Reply #1 on: August 19, 2024, 12:45:47 PM »
Can you try to setup wpa_supplicant manually?

« Last Edit: August 19, 2024, 12:47:56 PM by Paul_123 »

Offline timbee

  • Newbie
  • *
  • Posts: 4
Re: Help with piCore15 and wifi.sh
« Reply #2 on: August 19, 2024, 01:48:30 PM »
Thanks for your fast reply.
I now have a workaround in that the following works
Quote
wpa_passphrase My_SSID My_Password > /etc/wpa_supplicant.conf
wpa_supplicant -i wlan0 -c /etc/wpa_supplicant.conf -B -D nl80211,wext
udhcpc -i wlan0

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1270
Re: Help with piCore15 and wifi.sh
« Reply #3 on: August 19, 2024, 02:37:15 PM »
Great, thanks for letting me know, I'll take a look at the script, it hasn't been updated in years.

Offline ovacikar

  • Jr. Member
  • **
  • Posts: 65
Re: Help with piCore15 and wifi.sh
« Reply #4 on: August 19, 2024, 07:35:56 PM »
I use wifi.sh script without problems on Pi model 1B and a Realtek USB Wifi. I am still on the first beta release of 15 though.

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1270
Re: Help with piCore15 and wifi.sh
« Reply #5 on: August 19, 2024, 07:51:21 PM »
Now that I'm at home looking at whats going on, its more likely related to the tty.

What is your connection to the pi.   keyboard, ssh? 

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11705
Re: Help with piCore15 and wifi.sh
« Reply #6 on: August 19, 2024, 08:20:59 PM »
Hi Paul_123
I don't know if this is of interest to you. Last February someone
reported an issue involving ESSID containing an ampersand:
https://forum.tinycorelinux.net/index.php/topic,26819.0.html

I worked out some changes to handle certain troublesome
characters in reply #18. I don't know if any of them were
incorporated. Maybe they are of some interest?

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1270
Re: Help with piCore15 and wifi.sh
« Reply #7 on: August 19, 2024, 09:23:06 PM »
I don’t use wifi.sh, nor do I have time to test every combination of odd characters.  Not sure who is the official maintainer, or if it’s in the TC git somewhere, but I would just implement the changes you suggested, and see what shakes out next

Offline gadget42

  • Hero Member
  • *****
  • Posts: 826
Re: Help with piCore15 and wifi.sh
« Reply #8 on: August 20, 2024, 05:05:50 AM »
searched DDG for "tcgetattr: Inappropriate ioctl for device"

and read these:
https://unix.stackexchange.com/questions/417362/concalc-tcsetattr-error-inappropriate-ioctl-for-device
https://unix.stackexchange.com/questions/82658/bash-script-error-stty-standard-input-inappropriate-ioctl-for-device

given TCL14x worked, but TCL15x fails, could this be a change in busybox?
(tcl14=busybox_1.36.0 and tcl15=busybox_1.36.1)
The fluctuation theorem has long been known for a sudden switch of the Hamiltonian of a classical system Z54 . For a quantum system with a Hamiltonian changing from... https://forum.tinycorelinux.net/index.php/topic,25972.msg166580.html#msg166580

Offline timbee

  • Newbie
  • *
  • Posts: 4
Re: Help with piCore15 and wifi.sh
« Reply #9 on: August 20, 2024, 05:34:21 AM »
The error comes from this line
Quote
system("wpa_passphrase " s " < " ptmp " > /etc/wpa_supplicant.conf")
It appears that wpa_passphrase no longer accepts input redirected from a file.
the solution that seems to work is to have the password as a command line argument
Quote
system("wpa_passphrase " s " " p " > /etc/wpa_supplicant.conf")
the line creating the temporary file can be deleted
Quote
--- /usr/local/bin/wifi.sh
+++ wifi.sh
@@ -106,13 +106,12 @@
 }
 
 function associate(t,d,s,p,c) {
-   print p > ptmp
    keyphrase=" key restricted "
    if ( p == "" ) { keyphrase = "" }
    selchannel=" channel "
    if ( c == "" ) { selchannel = "" }
    if (t == "WPA") {
-      system("wpa_passphrase " s " < " ptmp " > /etc/wpa_supplicant.conf")
+      system("wpa_passphrase " s " " p " > /etc/wpa_supplicant.conf")
       system("wpa_supplicant -i " d " -c /etc/wpa_supplicant.conf -B  -D $WPADRV >/dev/null 2>&1")
    } else {
       system("iwconfig " d " essid " s keyphrase p selchannel c)

Warning this appears to work in my case but it has not had any testing other than my home WPA network.


Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1270
Re: Help with piCore15 and wifi.sh
« Reply #10 on: August 20, 2024, 11:46:40 AM »
while the wpa_supplicant package was recently updated, the wpa_passphrase code has not changed much.  The redirection would be handled by the shell anyway.

tcgetattr is only called if the number of arguments is less than 2.  busybox ash and busybox awk are the places to start looking.

Offline timbee

  • Newbie
  • *
  • Posts: 4
Re: Help with piCore15 and wifi.sh
« Reply #11 on: August 20, 2024, 01:46:41 PM »
Here is my test to show that it is wpa_passphrase and redirection that is causing the problem.
Quote
tc@box:~$ echo MyPassword > ptmp
tc@box:~$ wpa_passphrase MySSID < ptmp
# reading passphrase from stdin
tcgetattr: Inappropriate ioctl for device
tc@box:~$ wpa_passphrase MySSID MyPassword
network={
   ssid="MySSID"
   #psk="MyPassword"
   psk=a66e97b9a1008a97285c78c2b95082bed3541d3dd01165b0128f7f3c18563797
}
tc@box:~$

Offline Rich

  • Administrator
  • Hero Member
  • *****
  • Posts: 11705
Re: Help with piCore15 and wifi.sh
« Reply #12 on: August 21, 2024, 01:17:00 PM »
Hi Paul_123
I don’t use wifi.sh, nor do I have time to test every combination of odd characters.  Not sure who is the official maintainer, or if it’s in the TC git somewhere, but I would just implement the changes you suggested, and see what shakes out next
I couldn't find it in the TC git or any of the repo src directories.
Currently, there are 3 versions of wifi.tcz in TC15:
x86     v1.5
x86_64  v1.4
ARM     v1.6

Since it's just a script, I'd like to keep it in sync for all architectures.

I took the 1.6 version and added the changes for odd characters.

If there is no objection, I would like to implement the change proposed by timbee:
Code: [Select]
system("wpa_passphrase " s " " p " > /etc/wpa_supplicant.conf")It seems a lot simpler and more straightforward than this:
Code: [Select]
print p > ptmp
 ----- Snip -----
system("wpa_passphrase " s " < " ptmp " > /etc/wpa_supplicant.conf")
 ----- Snip -----

I've put together a source tarball containing:
Code: [Select]
wifi.sh         # /usr/local/bin
wifi            # Script for /usr/local/tce.installed
wifi.desktop    # /usr/local/share/applications
wifi.tcz.info   # The .info file for updating version number, comments, and change log.
wifi.png        # /usr/local/share/pixmaps
wifi.build      # Script that builds and packages the extensions.

wifi.build creates wifi-Arm.tar.gz and wifi-Intel.tar.gz.
Each contains:
Code: [Select]
wifi.tcz.md5.txt
wifi.tcz
wifi.tcz.dep
wifi.tcz.list
wifi.tcz.info
wifi.tcz.zsync
The only differences are:
ARM  16k squash block size  .tcz.dep=wireless_tools.tcz, wpa_supplicant.tcz
Intel   4k squash block size  .tcz.dep=wpa_supplicant-dbus.tcz

wifi.build also creates a new source tarball (wifi-source-Ver1.7.tar.gz) and
wifi-Ver1.7.tar.gz.bfe for submitting the extensions and new source package.

wifi.build gets the current version number from wifi.tcz.info.

Offline Paul_123

  • Administrator
  • Hero Member
  • *****
  • Posts: 1270
Re: Help with piCore15 and wifi.sh
« Reply #13 on: August 21, 2024, 01:46:49 PM »
Writing a temp file has less of a chance of squashing a special character by the shell.

I'm pretty sure I see the issue with wpa_passphrase.  The change they made (In 2022 after wpa_supoplicant 2.10) expects a real tty for standard input.

Offline patrikg

  • Wiki Author
  • Hero Member
  • *****
  • Posts: 724
Re: Help with piCore15 and wifi.sh
« Reply #14 on: August 21, 2024, 03:46:01 PM »
This is how alpine does the thingy: taken from the file  setup-interfaces

Code: [Select]
config_wpa_supp() {
local iface="$1" essid="$2" auth_type="$3" psk="$4"
local conffile="$ROOT"/etc/wpa_supplicant/wpa_supplicant.conf
mkdir -p "${conffile%/*}"
if [ "$auth_type" = "WPA-PSK" ]; then
(umask 0077 && wpa_passphrase "$essid" "$psk" | sed -e '/^\t#psk=.*/d' >> "$conffile")
else
cat << EOF >> $conffile
network={
ssid="$essid"
key_mgmt=$auth_type
}
EOF
fi
mkdir -p "$ROOT/etc/conf.d"
if grep -q ^wpa_supplicant_args= "$ROOT"/etc/conf.d/wpa_supplicant 2>/dev/null; then
sed -i -e "s/^wpa_supplicant_args=.*/wpa_supplicant_args=\"-i $iface\"/" /etc/conf.d/wpa_supplicant
else
printf 'wpa_supplicant_args="-i%s"\n' "$iface" >> "$ROOT"/etc/conf.d/wpa_supplicant
fi
rc-update --quiet add wpa_supplicant boot
rc-service wpa_supplicant start
}
« Last Edit: August 21, 2024, 03:51:00 PM by patrikg »