QPE 4.3.0 plus QEMU

Trolltech GPLed and released its Qtopia Phone Edition 4.3.0 distro a couple of weeks ago, at the same time adding Neo1973 as a supported device. I had a look at the “Phone” part of the package and while I was never a fan of Qt, I like a number of things in qtopia design, although I have also tried running Qtopia on my phone and the interface was not terribly nice for a first time user. Like, on one hand I like the fact that they came up with a custom input method, avoiding getting into obscure deals with the popular T9 input method which is patented (which they could easily do). On the other hand though I couldn’t comfortably enter message text using this input method. The cool bit is that it’s now all open-source there’s no way back :)

Having for a short time been involved in the development of gsmd in OpenMoko what I like most in Qtopia and at the same time envy the most is that their phone services have a logical design, quite complete set of documentation and probably work. This last thing I haven’t verified but even if not, the logical design alone would be enough to make me happy, seeing how chaotic is gsmd development process. Gsmd has no documentation and also suffers from lack of maintainership which recently changed status to a presence of a very strange maintainership that makes contributing code very hard and probably leads to less progress than when there was no maintainer. Fortunately there’s recently enough work to be done in the GSM support in OpenMoko that doesn’t involve touching gsmd itself.

Qtopia’s phone part is nicely divided into services each of which supports plugins for adding support for exotic modems. The division is quite grain but no too grain and there are full tutorials for writing each type of plugins. The code is not so amusing but it’s quite complete with all standard features implemented, even those not present in any of the supported devices. I was particularly looking in qtopia for GSM multiplexing code and it was there and surprisingly it was written in C (all the rest of Qtopia being C++, making it not directly reusable in other projects) but it was quite ugly and suboptimal, so only useful for comparing the results. At the moment Qtopia doesn’t do multiplexing when running on the Neo1973, there is probably some reason for this and I’m suspecting it is in the Neo1973 hardware or kernel (the kernel’s not a part of Qtopia, it comes from OpenMoko).

What I found useful is development tools that come with QPE, two in particular. The first one is called phonesim and is used for testing the phone services. The second one is atinterface or “phone emulator”. Both tools idea is to simulate a modem which you can talk to using a standard AT command set, but they do it in different ways. Phonesim is strictly a developer tool, segfaults a lot and is supposed to run on the desktop, or wherever you’re coding, although it can run anywhere. It simulates a dummy GSM modem, you can run Qtopia or other tool that talks to a modem (QEMU, gsmd, gnokii) and make it connect to phonesim. Sometimes it will work and sometimes it won’t because phonesim understands just a minimum subset of standard AT (and some of GreenPhone’s modem’s proprietary commands), but is easily extensible. There’s an optional GUI through which you can simulate incoming calls, messages, data packets and more, but basically the GUI is the only source of events. Atinterface on the other hand runs on Qtopia and it takes events from QPE’s phone subsystem. It’s purpose is exposing a modem interface to a laptop or other devices so that they can send faxes or make data calls through a GreenPhone. The interface is hardware independent, i.e. the virtual modem presented by atinterface to your laptop will not depend on whether the QPE is running on a Neo1973 or GreenPhone or HTC. It’s also more standards compliant than the GSM subset emulated by phonesim, but to use it you will need a running QPE and its phone services.

Now what I wanted was tools for easy testing gsmd and/or OpenMoko running in QEMU. Connecting it all together is not exactly simple so I will explain here how to do that. So, we want to run gsmd or QEMU, and we want to use phonesim or atinterface as a virtual modem, so that we don’t have to use a physical modem because the physical modem is a lot of hassle (for example if it’s the Neo modem, it constantly runs out of battery), if you have one. While we’re at it I will also show how to use the physical modem of Neo1973 with a gsmd running on PC, it’s less hassle than testing gsmd on the phone.

We have two parts: a modem (physical or virtual) and a program (gsmd or QEMU). For the communication channel we choose a network socket because sockets are flexible and already supported in many places. For the modem we have three possibilities: 1. a phonesim virtual modem, 2. atinterface virtual modem, 3. a Neo1973 physical modem.

1. Phonesim supports sockets out of the box, so we just need to build and run it. I hacked up a phonesim version that can build outside a Qtopia tree and I included it in the qemu-neo1973 repo at svn.openmoko.org, to build it you only need to check out a recent qemu-neo1973, configure it with

$ ./configure --disable-system --disable-user --target-list=arm-softmmu --enable-phonesim && make

The command

$ (cd phonesim; LD_LIBRARY_PATH=lib ./phonesim -gui ../openmoko/neo1973.xml) &

runs phonesim. The -gui switch is optional. The GUI will only appear after a first client connects. Phonesim now listens on localhost port 12345 and is ready to accept clients. The neo1973.xml file defines a modem behavior resembling the Neo1973 modem (TI Calypso).

2. Atinterface is part of Qtopia, and requires Qtopia. I will not explain here how to build Qtopia. After you’ve built and installed it (I assume the default paths) you will need to first run QPE and then atinterface. For QPE to run you need a modem, we can use phonesim. You can use the phonesim build that comes with Qtopia, to do that run the following command:

$ bin/phonesim -gui src/tools/phonesim/troll.xml &
$ export QTOPIA_PHONE_DEVICE="sim:localhost"

Next, we’ll need to emulate a framebuffer on which QPE will display and then we can run QPE and atinterface:

$ bin/qvfb &
$ echo [SerialDevices] > etc/default/Trolltech/Phone.conf
$ echo ExternalAccessDevice=/dev/ttyS1:115200 >> etc/default/Trolltech/Phone.conf
$ image/bin/qpe &
$ image/bin/atinterface --test -qws

Ready, now we have atinterface listening on localhost:12350.

Phonesim on an OHand laptop

3. To make the Neo1973 modem accessible to a PC over USB we have several options. The u-boot gsm passthrough support turned out unreliable so we will boot Neo into linux, kill gsmd and run netcat:

# killall gsmd
# nc -l -p 5000 < /dev/ttySAC0 > /dev/ttySAC0

Voila, if the usb ethernet is configured (see OpenMoko wiki) , the modem is now listening at 192.168.0.202:5000.

Now we want to connect to our modem from the other side, gsmd or QEMU programs on the desktop. With QEMU the task is easy because it can connect to a socket directly: just append -serial tcp:localhost:12345 (in the phonesim case, in other cases tcp:localhost:12350 or tcp:192.168.0.202:5000) and you should see the system running inside QEMU connect to a GSM network and be operational. Remember that if you haven’t configured QEMU with –enable-phonesim, it uses a builtin modem emulator based on gnokii (yes, yet another virtual phone), which needs to be disabled.

With gsmd the problem is that it wants a character device to connect to, rather than a socket. We will emulate a character device using a tiny program I uploaded to qemu-neo1973 svn yesterday. It will make a pseudo-terminal pair (pty stands for Pseudo-Terminal. Has anyone wondered, if tty is for Tele-Typewriter, why pty is not Pseudo-Typewriter?) and connect the master to the socket. If you’ve checked out qemu-neo1973 and you’re inside the source directory, do:

$ make pty
gcc-3.3.6 -Wall -O2 -g -fno-strict-aliasing -I. -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -g  pty.c   -o pty
$ ./pty localhost 12345
/dev/pts/12

The pty program connected to the modem (change the hostname/port pair accordingly) and it told us that it created a character device /dev/pts/12 to which gsmd can now connect (qemu can also connect to character devices). The device will exist as long as pty is running.

$ /usr/local/sbin/gsmd -p /dev/pts/12 -s 115200 -v ti -m generic

That should be it. Now you can launch a program like openmoko-dialer that uses gsmd and hack away. Phonesim has a nice GUI (alas Qt…) from which you can observe the AT communication with your program.

About these ads

3 Responses to “QPE 4.3.0 plus QEMU”

  1. sudharsh Says:

    cool, thanks for the cool post..the problem in my case is that, I code at my home and have to take the ipks to the neo in my university. If code is borked i am pretty much screwed.
    I wasn’t aware of phonesim really and had to make gsmd listen to ttyS0 in my desktop instead which was crappy, as it was a one way comminication. But when i heard of phonesim i was searching the wrong place for the docs..(..no prizes for guessing), but stumbled upon this post..
    keep up the good work..owe you a pint sometime ;)

  2. pygsmd: update « Random Rants of a n00b Says:

    […] [1]: http://unadventure.wordpress.com/2007/10/28/qpe-430-plus-qemu/ […]

  3. Rencontre Sexe Mobile Says:

    well.. it’s like I said! f

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.

%d bloggers like this: