WiFi works!!! A successful experience. [ SCRIPTS PROVIDED ]

Edit:It seems like someone could be mislead by the way my original post was written, so I want to make things clear:This thread is about making WiFi work USING AN EXTERNAL DONGLE. The internal Broadcom chip is not yet usable in freedom.

Hi folks,

I just wanted to share my enthusiasm for my recent successful experience in making WiFi work on Replicant, using thisexternal dongle.As I've already written [[here]] , I spent a couple of days working on the command line, and now I have a usable WiFi client on my Replicant Phone!

IT..COULD..WORK!!!! (muahuahahaha!)

Thanks to Tibi (Tehnoetic) for releasing all the necessary patches to Replicant and the fundamental scripts for wpa_supplicant!

I'm now planning to develop a graphical front-end to make it usable by everyone.

I'm providing every detail I can to those who want to learn more, so if you're curious, just ask!

[EDIT]I am now proud to provide some useful free-licensed scripts, to make the WiFi experience a bit easier:

the basic instructions are the same provided hereI'm going to update Tehnoetic's wiki too, as soon as I'm able.

The HUGE difference I discovered is that IT IS NOT NECESSARY TO FORMAT THE /data PARTITION in order to recover from a system crash.Instead, it is sufficient to chmod the /data/misc/wifi folder and all its contents to 777.Maybe some less privilege is sufficient, but I haven't tried yet. I only tried 777, and it works. If someone finds out that less privilege is needed, please let us know, as "least privilege" is always the best philosophy!

Other improvements I was able to achieve are:1) the ability to scan for available networks, and connect to the one of interest by simply choosing a number from the list, and providing the relative WPA password.2) a better management of the connection, with both connect and disconnect scritps.3) an automated way to write the configuration file for wpa_supplicant.

So, without further introduction, here are the instructions:(It is assumed that you have tehnoetic's unofficial version of Replicant running on the target device which must be an i9100)

- Back up all of your data! Back up all of your data! Back up all of your data!All the scripts and relative instructions are provided "AS IS" without ANY warranty.I tested all of the following instructions, and they SHOULD cause no harm, but I don't take any responsibility for any data loss or any damage to your device.

- To prepare the environment run the rstr.sh script on the target device, in terminal emulator, running as root. (the "rstr" script can be used both at system startup to set up the environment, and after a crash, to restore it)

# bash /data/misc/wifi/rstr.sh

- To scan for available WiFi networks, run the "select_network.sh" script

- (EXAMPLE) Enter 1 to connect to JustAnotherWiFi_AP, the script will then ask for a PSK password for the connection:

Enter a password for JustAnotherWiFi_AP

- Input the password and press enter. The script will automatically set up "wpa_supplicant.conf" for the desired connection. You will then be asked if you want to connect:

Network connection has been set up for JustAnotherWiFi_AP!
Do you want to connect to JustAnotherWiFi_AP now? [y/n]

- Input "y" to connect.. Everything should work...

- BEFORE UNPLUGGING THE DONGLE: make sure you stop wpa_supplicant and dhcpcd, to avoid possible crashes!

bash /data/misc/wifi/disconnect.sh

During my tests, I have found that a rough 90% of the crashes must be due to a lack of current to the external dongle.I fact, crashes tend to occur when the device battery is low (below 40%) or when doing CPU-intensive operations (e.g. playing 720p videos while being connected).I'm going to try and use a "Y" cable together with an additional power supply ("power bank"), and see if the situation gets better.Apart from this, regular web browsing (no heavy graphics or scripts) should work like a charm.

If you encounter any problem, ask here or on the mailing list. I'll be glad to help you if I'm able to, as soon as my schedule allows me to.Any improvements and corrections are very, very, very welcome, so please, if you find a bug, or have any suggestion, don't hesitate to answer this post or write on the mailing list.

My idea was, and still is, to write an application to provide a GUI around these scripts.But, as of now, I still haven't been able to overcome the numerous troubles I encountered in trying to get Replicant's SDK work in Eclipse.That's to say: if someone wants to help, we can join efforts and do The Right Thing to make Replicant even better then now!

Replies (26)

I've improved the WiFi scripts a little bit:- rearranged the whole system to have a "global" variables setup, so that it's easier to manage and change the paths for debugging or for any needed modification.- added a trivial system to store "known" connections on a file, so that you don't need to re-enter the password each time you connect.

I also managed to place some shortcuts on the home screen of the device, to ease the launching of the scripts (read on for a little tutorial).

- download the RepWiFi.tar.bz2 package attached to this post.- extract the content and navigate inside the extracted "v1.3" folder- from within the "v1.3" folder run:

bash setup.sh

- this will start adb as root, and push all the scripts on the device, in the /data/misc/wifi folder.- to launch the scripts from the command line, refer to my previous post here above.- to ease your life a little bit and use some shortcuts, read on:

The "terminal emulator" app, installed by default in Replicant 4.2 comes with a widget that allows us to place a shortcut on the home screen, pointing to a command to be executed in terminal.This comes in handy for our wifi scripts, so that we can then search networks, connect and disconnect by just tapping a shortcut.1) open the "app drawer" and scroll to the widget section, to find the "Term shortcut" widget.2) long press on "term shortcut" and release the shortcut where you like, on the home screen.3) a configuration window will appear:

4.1) leave the "command" textbox blank!4.2) in the "Arguments" textbox write the command to run the script you want like this:

su -c "bash path/to/the/script"

5) call your shortcut whatever you want by placing a name in the "shortcut label" textbox, and click "ok".6) you can now launch the script by simply clicking on the shortcut you just created.7) make sure you close the terminal window after running the scritp! I'm not sure why, but if you leave the terminal window open, the next command you launch via a shortcut will behave strangely (sometimes won't even run until you close the previous window).

Repeat the above points 1-5 for each script you need, using the following command lines: su -c "bash /data/misc/wifi/rstr.sh" for the "restore" script, su -c "bash /data/misc/wifi/select_network.sh" for the network selection script su -c "bash /data/misc/wifi/connect.sh" for the "reconnect" script su -c "bash /data/misc/wifi/disconnect.sh" for the "disconnect" script

I hope the instructions above are clear enough for everyone.In case they aren't, just ask and I'll be glad to help!

Not yet. But I'm planning to get one and try the scripts on it.The scripts themselves should work just fine on ANY device having wpa_supplicant and wpa_cli installed, as they are basically only a set of commands to those two programs.They should even work on any GNU/linux system by just changing the working directory to something more sensible (e.g. /home/user/wifi )And from what I know, the S3 should run the same driver/firmwares for atheros AR9271, so there should be no difference in making the whole thing work.Still I'm not completely sure, so I suggest you ask Tibi from Tehnoetic if his unofficial version of Replicant (which is needed in order to have support for free wifi) runs the same on both devices.

All the necessary patches are now included in the kernel for the Galaxy S2 and Galaxy S3 and it should work with Replicant 6.0. The firmware is also part of Replicant 6.0 images, so no need to manually copy it to the device.

I attached a minimal script that allows to connect to a WiFi access point. You need to edit the name and password of your access point at the beginning of the script. Then you can push it to the device:

adb push path/to/wifi_setup.sh /data/misc/wifi/

Attach the wifi dongle and run the script as root in the /data/misc/wifi directory using the terminal emulator app (bash wifi_setup.sh). You may need to enable the terminal app in the developer settings. These are all the needed steps to get WiFi working.

It should be pretty straightforward to change Fil's scripts accordingly and include the commands from my script that are specific to Replicant 6.0. So if someone wants to help with this, this would be a great place to start!

Security-wise, I'm pretty satisfied with the script. The configuration steps don't require to change any permissions and nothing needs to be made world-readable. It also looks like wpa_supplicant correctly drops its privileges and runs as the wifi user.

I have started playing around with your script..It works, with some modifications, in Replicant 4.2 (basically stripping away the ndc commands, and the -I option from wpa_supplicant)

I have now tried to run it in Replicant 6.0, but I haven't been able to get it to work yet..It seems like interface wlan0 disappears somewhere during the execution of the script.

ip link correctly lists wlan0 before running the scripts (and after unplugging and plugging the dongle back in).But while the script runs, some command complains about "wlan0" being inexistent. In fact, the interface disappears from ip link too, after running the script.I didn't have much time to do a deeper testing. I'm going for it tomorrow.

As a side note:/data/misc/wifi isn't accessible in the regular shell.su is still needed to run the script.

I have started playing around with your script..It works, with some modifications, in Replicant 4.2 (basically stripping away the ndc commands, and the -I option from wpa_supplicant)

Great!

I have now tried to run it in Replicant 6.0, but I haven't been able to get it to work yet..It seems like interface wlan0 disappears somewhere during the execution of the script.

ip link correctly lists wlan0 before running the scripts (and after unplugging and plugging the dongle back in).But while the script runs, some command complains about "wlan0" being inexistent. In fact, the interface disappears from ip link too, after running the script.I didn't have much time to do a deeper testing. I'm going for it tomorrow.

In a previous version of the script, I did run "ifconfig "$iface" up" before launching wpa_supplicant. And I had these kind of issues before, but they disappeared after some changes and I removed the ifconfig command as it didn't seem to be necessary anymore. You could add the ifconfig initialization command. Maybe it solves the issue.

As a side note:/data/misc/wifi isn't accessible in the regular shell.su is still needed to run the script.

Yes, if we stick with the current setup and don't do the hard work of properly implementing a hardware abstraction layer for the usb dongle in the same way as for the internal wifi, it will likely always be necessary to run the scripts as root.

Hi everyone!It's a pleasure to announce that, thanks to the great work done by Wolfgang, "RepWifi" is now available in Replicant 6.0 too! (Thank you, Wolfgang!)I have upgraded the full set of connection management scripts and merged them with Wolfgang's one, in order to make them work in the up-coming next release.

I have tested them in the default terminal bundled with R6.0, but I haven't been able to test them in the "Terminal Emulator" app, so I can't tell if the whole shortcut trick works in R6.0 too.. but I don't see why it shouldn't.

In a previous version of the script, I did run "ifconfig "$iface" up" before launching wpa_supplicant. And I had these kind of issues before, but they disappeared after some changes and I removed the ifconfig command as it didn't seem to be necessary anymore. You could add the ifconfig initialization command. Maybe it solves the issue.

I know you are all busy, but I would really appreciate a simpler 'manual'. If provided I will try to install and provide feedback asap.

Hi there.I'm sorry if it is still a bit hard for users to have it working.Unfortunately there is currently no way other then bare shell commands to connect to a WiFi network.If you're unfamiliar with the shell things can get confusing.

I guess you already tired to follow the instructions provided in the first few posts on this thread.I thought they were clear enough, but it seems they aren't.

In general, it should be sufficient to download the package from this postThen, extract the correct folder for your version of replicant (either 4.2 or 6.0) on your host computer.Then, connect your phone to the host computer via USB and enable usb debugging on the phone (Settings > Developer Options > USB debugging)On the host computer, open a shell and "cd" into the directory where you have extracted the scripts (either "v1.3" or "v1.4").From within this directory run:

adb root

Check your phone, if it asks for you to allow your computer to access ADB via USB. If it does, then grant the permission.Then on the same shell, from within the "v1.3" directory (for Replicant 4.2) or the "v1.4" directory (for Replicant 6.0) run:

bash setup.sh

The "setup.sh" script should do everything for you, placing the needed scripts on your phone.Now you can unplug the phone from the computer, plug in a usb OTG cable with the WiFi adapter connected to it.From now on, you can follow this instructions to use WiFi connectivity.

If you need any other help, please ask here, reporting exactly for which specific steps you need help.I'll be glad to help you!Without specific requests I can do nothing more than point you back again to the original instructions.

I have been following this discussion for several weeks now and eventually was overcome by the urge to purchase a Samsung Galaxy SIII i9300. I installed Replicant 6.0 and it works. I downloaded the scripts for WiFi and they worked . . . nearly.

Unfortunately, the scripts as written do not quite work on Galaxy S3 with Replicant 6.0. I have made some changes to them to make them work. As written, the scripts believed that the working directory was /data/misc/wifi. However, they were actually in /data/misc/wifi/scripts. I have fixed this and now setup.sh pushes the scripts /data/misc/wifi.

I also added support for unsecured networks.

Note: this is my firs tcontribution to the project and as such may contain BUGS. If you use these scripts they MIGHT BREAK YOUR PHONE. I cannot provide any warranty that these scripts will help you in any way.

On the other hand, they worked just fine for me and now allow me to connect to both WPA Personal and unsecured WiFi networks.

All my contributions are licensed under the GPLv3 or any later version.

With these scripts, I believe the instructions previously posted should actually work.

PS: For completeness I have included the old, unchanged, unmodified scripts for Replicant 4.2. I have not touched them, modified them or even looked at them. I just left them there and they do not have any new features I have added to the Replicant 6.0 scripts.

Unfortunately, the scripts as written do not quite work on Galaxy S3 with Replicant 6.0. I have made some changes to them to make them work. As written, the scripts believed that the working directory was /data/misc/wifi. However, they were actually in /data/misc/wifi/scripts. I have fixed this and now setup.sh pushes the scripts /data/misc/wifi.

Thanks for correcting the issue!I guess the incriminated line was the following (in the setup.sh script)

adb push ./scripts "$root_dir"

I noticed you changed it to

adb push ./scripts/* "$root_dir"

I think the previous one was working on my system (Trisquel 7), but I can't remember for sure.. anyway, I think your correction should work better..Can you please confirm that the issue was in that line?I'm no bash expert at all, so I'd like to learn if I was writing it the wrong way..

I also added support for unsecured networks.

That's really great too!I spent my free time during the 2 days of FOSDEM trying to add that feature, but I haven't been able to work on that very much...

If I get it right, all you're doing is providing no password parameter to wpa_supplicant, if the network is unsecured...Does it work for you? Because that was the first thing I tried, but it didn't work for me, unless with FOSDEM's open wifi network..I was researching about explicitly telling wpa_supplicant that the network has no password with:

set_network 0 key_mgmt NONE

And I nearly had it working.. The connection to the AP was established, but then I couldn't get no gateway..I haven't been able to try anymore, so now I'm curious to know if that could have been the right way to go....or not! :)

Can you please help me in this regard?

Thank you very much again for your contribution!

Fil

P.S. it would be fair if you added your copyright notice to the licensing header of the file(s) you edited, to get proper credit for your helpful contribution ;)

It sounds like we both don't know much about shell scripting. I guess we get to learn together!:-)

You asked if

-adb push ./scripts "$root_dir"
+adb push ./scripts/* "$root_dir"

fixed the first problem. Yes, it did. I still don't know if that is the 'correct' way to do it. I know that it works and that is what matters to me.

Also, I used,

set_network 0 key_mgmt NONE

to connect to insecure networks. So far it seems that it works for me. I'm not sure why you couldn't get a gateway on insecure networks. I'll look into it more on my phone. I do know that captive portals are a pain. For me, Browser would not let me visit captive portal pages until I typed in the IP address for the captive portal server. I had to find that IP address on another device running another operating system. Obviously not the best situation. Maybe I'll find a solution to that to.

I also changed some other aspects of the scripts so that passwords are now optional. For instance connect.sh now assumes that a network does not need a password if you don't give it one. The same way with add_network.sh.

Finally, I also posted the entire code to github. I know github is not the best hosting solution, but I have it and it works. If you use github and want commit access, just like send me your username or however its done and I'll add you.

You asked if -adb push ./scripts "$root_dir" +adb push ./scripts/* "$root_dir" fixed the first problem. Yes, it did. I still don't know if that is the 'correct' way to do it. I know that it works and that is what matters to me.

I guess certain ADB versions behave differently regarding pushing folders. I already had a similar issue elsewhere but I didn't yet look into the specifics.

I created a repo for user scripts. The idea is collect all sorts of useful scripts for Replicant users. I included all of your work and added a few changes to the Replicant 6.0 version. Let me know if I overlooked something or if I made a mistake.

See the developer guide for contribution guidelines. It would be great seeing your further improvements included in the user scripts repo.

I created a repo for user scripts. The idea is collect all sorts of useful scripts for Replicant users. I included all of your work and added a few changes to the Replicant 6.0 version. Let me know if I overlooked something or if I made a mistake.

That's a freaking great idea, Wolfgang! ;)Thanks for bothering.I took a quick glance at your changes to the scripts, and I guess everything is sensible. For sure it is more sensible than before. Above all is the right chmod'ing for the wifi directory.Looking back, I'm sorry I ever introduced that 777.. I recognize I was just hammering things in the desperate effort to make things work, without exactly knowing what I was doing.. Unfortunately, in Replicant 4.2, that was the only "workaround" I found, to make things work again after a system crash.

OTOH, I've been noticing with pleasure that such hammering isn't needed in Replicant 6.0.Everything seems to be more stable and nicer overall.

See the developer guide for contribution guidelines. It would be great seeing your further improvements included in the user scripts repo.

So.. as I'm really close to release the graphical application to control WiFi, are you the right person to ask for an account to the repo?

I took a quick glance at your changes to the scripts, and I guess everything is sensible. For sure it is more sensible than before. Above all is the right chmod'ing for the wifi directory.Looking back, I'm sorry I ever introduced that 777.. I recognize I was just hammering things in the desperate effort to make things work, without exactly knowing what I was doing.. Unfortunately, in Replicant 4.2, that was the only "workaround" I found, to make things work again after a system crash.

Don't be sorry for this! You did the initial work and this was the initial solution to get things working. And so far, there is no other solution for Replicant 4.2.

OTOH, I've been noticing with pleasure that such hammering isn't needed in Replicant 6.0.Everything seems to be more stable and nicer overall.

That's great to hear!

So.. as I'm really close to release the graphical application to control WiFi, are you the right person to ask for an account to the repo?

Yes, I can create an account for you. Please send me a mail with the name, username and mail address that should be used for your account.

I was able to make use of these scripts for Replicant 6.0, though it appears that some apps are unable to utilize the connection to access the internet.

F-Droid is the most notable example.Attempting to update the repos results in "Cannot update, are you connected to the internet?" Antox also fails, citing "No Internet Connection"

On the other hand, OpenKeyChain and K-9 Mail are able to access the internet through the connection just fine.

I can only speculate that apps like F-Droid and Antox in some way check the system status for whether the wifi and/or mobile data toggles are enabled and abort outgoing connection attempts right away if both are turned off.

I hadn't seen this mentioned so far, and I doubt I'm the only one that tried refreshing F-Droid and mistakenly concluded the scripts don't work.

I was able to make use of these scripts for Replicant 6.0, though it appears that some apps are unable to utilize the connection to access the internet.

F-Droid is the most notable example.Attempting to update the repos results in "Cannot update, are you connected to the internet?" Antox also fails, citing "No Internet Connection"

On the other hand, OpenKeyChain and K-9 Mail are able to access the internet through the connection just fine.

I can only speculate that apps like F-Droid and Antox in some way check the system status for whether the wifi and/or mobile data toggles are enabled and abort outgoing connection attempts right away if both are turned off.

You are speculating right. A workaround for now is to enable mobile data and then establish a wifi connection with the scripts. The scripts set the wifi interface as default, so the mobile data interface won't be used, but the Android system doesn't assume that there is no network connection. It is important to enable mobile data first and then setting up wifi with the dongle. If you do it the other way around, the mobile data interface is likely used.

I will post about this in the graphical app thread. I'm not yet aware of a working solution for this issue. The task is to "enable" wifi in the Android system so that apps are notified that a wifi connection is available.

I can only speculate that apps like F-Droid and Antox in some way check the system status for whether the wifi and/or mobile data toggles are enabled and abort outgoing connection attempts right away if both are turned off.

I hadn't seen this mentioned so far, and I doubt I'm the only one that tried refreshing F-Droid and mistakenly concluded the scripts don't work.

Perhaps F-Droid has other bugs related to this too. One user suggests downgrading F-Droid to the version before they started doing this internet check.

From the F-Droid issue:

"We did indeed add some code to try and detect the type of connection, so that people can select the setting "Only update automatically on unmetered networks like Wi-Fi". It seems that we have been a bit too strict though." https://gitlab.com/pserwylo (Peter Serwylo)

Thanks for the link! I commented on the issue but I can't offer a solution (except the mentioned workaround) for now as I didn't look into the actual issue. I'll update the reverse tether wiki accordingly. Hopefully Fil finds a solution for this and we can also use his solution for reverse tethering.