1

In the moment I am working with some ad hoc routing protocols (namely OLSR and B.A.T.M.A.N.) on rooted Android devices running Cyanogenmod. My tests are working pretty well. However, there is one thing which really is annoying: I can only connect to an existing ad hoc network, but not create one manually using only the phones. Right now I am using my laptop to set up an ad hoc network and to run a small DHCP server.

Do you know how to create an ad hoc network manually by using the shell on Android? I have found some methods how this should work, but none did work for me. I tried using ifconfig, iwconfig, netcfg and even wpa_cli (which seemed to be the best choice for this). But after any try the system fell back into "no wifi connected" state - even if the phone stayed in ad hoc mode for a couple of seconds while searching for an IP.

I will be so gladful if I can finally get around this problem because then I might actually use my laptop for Internet access (and therefore searching for online help during the tests) instead of using it to set up an ad hoc network. :-)

mreichelt
  • 12,359
  • 6
  • 56
  • 70
  • Stackoverflow is for programming questions. For Android usability questions, please use android.stackexchange.com – Cheryl Simon Nov 23 '10 at 18:01
  • @mayra As you can read my question is about programming - here it's programming a shell script. – mreichelt Nov 23 '10 at 20:19
  • Sorry, it looked like it was about running commands on the shell, not writing a script. You still might get better luck there. – Cheryl Simon Nov 23 '10 at 21:12
  • Actually I want to run the commands in the shell to try them out first and later put them together in a shell script, which is no big difference. Nevertheless this really is a programming question, since "normal" Android users do not root their phones or try to use ad hoc wifi networks - but developers do. At least sometimes. ;-) – mreichelt Nov 23 '10 at 23:27
  • Even if you want to turn this into a shell script, this still is not programming question. If you have problems with writing down the loops or classes, then it is a programming question, but this question is asking about using ifconfig/iwconfig/wpa_supplicant which is a Unix/Linux tool. Your question is much more on-topic in unix.stackexchange.com or android.stackexchange.com; and might have better chance there. Neither does "normal" developers own an Android device, much less a rooted one, much less hack up an ad-hoc wifi network when infrastructure-based tethering works. – Lie Ryan Dec 04 '10 at 15:54

2 Answers2

2

I'm not really clear on the technical details, but android-wifi-tether requires you to have a custom kernel with NETFILTER support, which I don't know if Cyanogenmod has. You might try using another open source project as an example: Barnacle Tether. It doesn't require a custom kernel.

I've started looking at the source for Barnacle for my own project. It's pretty easy to compile, but I've only just begun playing with it so I don't know the exact answer to your question.

Neil Traft
  • 18,367
  • 15
  • 63
  • 70
  • This project looks interesting, and the code seems to be quite simple. Maybe if I get the time to I can extract the part that is needed to create an ad-hoc network. After a quick glance at the code it seems that they create a new wpa_supplicant process, connect to it and run some commands with it. So basically maybe there is a solution using wpa_cli - yet the question how to do it is still open... – mreichelt Dec 04 '10 at 15:54
  • I am marking this as the right solution although the problem is not fully solved yet. Maybe I'll get back to this problem later and publish the solution here. :-) – mreichelt Dec 15 '10 at 23:22
1

Correct me if I'm wrong, but didn't the old cyanogen tethering app (android 1.6, before tethering was officially offered) create an ad-hoc network for the tether clients? (I ended up using it not to tether, but just to set up a network so I could ssh into the phone from a laptop while I was playing around with USB host drivers and so couldn't use ADB.)

Chris Stratton
  • 39,853
  • 6
  • 84
  • 117
  • Do you mean http://code.google.com/p/android-wifi-tether/ ? I already looked through some sources but didn't find information how to create an ad-hoc network there. And I can't use it because I am using Android 2.2 on newer versions of Cyanogenmod. All I would need is a set of shell commands to set up an ad-hoc network on Android. – mreichelt Nov 28 '10 at 16:30
  • Out of curiosity, what happens if you enable tethering now? – Chris Stratton Nov 28 '10 at 16:33
  • If I turn on tethering Cyanogenmod creates a new hotspot (= infrastructure mode, no ad-hoc mode). – mreichelt Nov 28 '10 at 19:02
  • Ah, okay, more useful for most people that way, but not for you. The google code project you linked does appear to be what was in the old version of cyanogen. At http://code.google.com/p/android-wifi-tether/source/browse/wiki/FAQ.wiki it specifically says it creates an ad-hoc network. So if you go through all the source there, you might learn how to do that. – Chris Stratton Nov 29 '10 at 01:00
  • I know that this app should do this (according to the FAQ) but all it does right now is to create an infrastructure network. I can not find where in the UI an ad hoc network should be created nor where the source for this action is located. I really thought there might be a small shell script available already that creates an ad hoc network without having to use a whole app for this... – mreichelt Dec 01 '10 at 09:39
  • Perhaps you should try examining the history of the revision control system from the googlecode project and see if they changed it at some point from ad-hoc to infrastructure. I'm not recommending you use the whole app (except for an initial test), but rather that you look through it and figure out how it works. – Chris Stratton Dec 01 '10 at 13:53