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

Added by Fil Bergamo 2 months ago

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 this external 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!

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!

P.S. please read [[this]] and help if you can!

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 here
I'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.

- Download and copy the needed drivers/firmwares for ath9k (refer to: https://wiki.tehnoetic.com/doku.php?id=tehnoetic_wifi_replicant)
- Download the scripts attached to this post.
- Copy all the scripts to /data/misc/wifi:

adb push startwpa.sh /data/misc/wifi
adb push rstr.sh /data/misc/wifi
adb push check_modules.sh /data/misc/wifi
adb push connect.sh /data/misc/wifi
adb push disconnect.sh /data/misc/wifi
adb push select_network.sh /data/misc/wifi
adb push write_config.sh /data/misc/wifi

- 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
# bash /data/misc/wifi/select_network.sh

- The script scans for networks, and lists the available ones:
Scanning for networks... OK
Retrieving network list... 

Please input the number of the network you want to connect to:
     # |  SSID
    1) | JustAnotherWiFi_AP
    2) | SuperFastNetwork
    3) | ARandomISPname1234

- (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!

I hope many of you will find my work useful and enjoyable!

write_config.sh - writes a config file for wpa_supplicant using provided parameters (SSID and password) (1.1 kB)

select_network.sh - Scans for available connections and lets you choose one to connect to. (2.8 kB)

check_modules.sh - checks if the needed drivers are loaded (2.5 kB)

connect.sh - connects to the network using current wpa_supplicant.conf file (1.1 kB)

disconnect.sh - stops dhcpcd and wpa_supplicant (180 Bytes)

rstr.sh - sets up or restores the working environment (1.2 kB)

startwpa.sh - starts wpa_supplicant without configuration, in order to make it work wit wpa_cli (82 Bytes)

Replies (5)

RE: WiFi works!!! A successful experience. [ SCRIPTS PROVIDED ] - Added by Fil Bergamo about 1 month ago


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).

To set up the whole environment:

- 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:

To create the shortcuts:

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!

Enjoy Libre WiFi connectivity!


RepWiFi.tar.bz2 (4.8 kB)

screenshot.png (143 kB)

screenshot.png (53.1 kB)

RE: WiFi works!!! A successful experience. [ SCRIPTS PROVIDED ] - Added by Kurtis Hanna 22 days ago

This is great! Thank you so much for all the work you've put into this!

Do you happen to have an i9300 to test this on, by chance?

RE: WiFi works!!! A successful experience. [ SCRIPTS PROVIDED ] - Added by Fil Bergamo 22 days ago

Do you happen to have an i9300 to test this on, by chance?

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.

RE: WiFi works!!! A successful experience. [ SCRIPTS PROVIDED ] - Added by Mzee Mzee 16 days ago

Wow, this is awesome news! When can we expect this to be included in the official distribution of Replicant? How can the community help to make this a reality as fast as possible?

RE: WiFi works!!! A successful experience. [ SCRIPTS PROVIDED ] - Added by Fil Bergamo 16 days ago

When can we expect this to be included in the official distribution of Replicant? How can the community help to make this a reality as fast as possible?

I think Tibi(tct) is in touch with PaulK to organize the inclusion of wifi support in the next release of Replicant..
I really don't know much more about it.
I suggest you contact Tibi (http://redmine.replicant.us/users/4785) or Paul (http://redmine.replicant.us/projects/replicant/wiki#Contact) to have better information.

Anyway, WiFi on Replicant IS ALREADY a reality. You can have it working, installing Tehnoetic's unofficial zip (refer to https://wiki.tehnoetic.com/doku.php?id=tehnoetic_wifi_replicant), and following my tutorial in this very thread!

Happy Hacking!